Skip to content

Commit e02c7c5

Browse files
committed
fix(tasks): fill username
1 parent 24c66bb commit e02c7c5

File tree

5 files changed

+66
-38
lines changed

5 files changed

+66
-38
lines changed

api/integration.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
246246

247247
log.Info(fmt.Sprintf("Running integration %d", integration.ID))
248248

249-
var envValues = make([]db.IntegrationExtractValue, 0)
250-
var taskValues = make([]db.IntegrationExtractValue, 0)
249+
var envValues = make([]db.IntegrationExtractValue, 0)
250+
var taskValues = make([]db.IntegrationExtractValue, 0)
251251

252252
extractValuesForExtractor, err := helpers.Store(r).GetIntegrationExtractValues(project.ID, db.RetrieveQueryParams{}, integration.ID)
253253
if err != nil {
@@ -257,7 +257,7 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
257257

258258
for _, val := range extractValuesForExtractor {
259259
switch val.VariableType {
260-
case "", db.IntegrationVariableEnvironment: // "" handles null/empty for backward compatibility
260+
case "", db.IntegrationVariableEnvironment: // "" handles null/empty for backward compatibility
261261
envValues = append(envValues, val)
262262
case db.IntegrationVariableTaskParam:
263263
taskValues = append(taskValues, val)
@@ -281,7 +281,7 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
281281
Environment: environmentJSONString,
282282
IntegrationID: &integration.ID,
283283
}
284-
284+
285285
// Only assign extractedTaskResults to Params if it's not empty
286286
if len(extractedTaskResults) > 0 {
287287
taskDefinition.Params = extractedTaskResults
@@ -293,7 +293,7 @@ func RunIntegration(integration db.Integration, project db.Project, r *http.Requ
293293
return
294294
}
295295

296-
_, err = helpers.TaskPool(r).AddTask(taskDefinition, nil, integration.ProjectID, tpl.App.NeedTaskAlias())
296+
_, err = helpers.TaskPool(r).AddTask(taskDefinition, nil, "", integration.ProjectID, tpl.App.NeedTaskAlias())
297297
if err != nil {
298298
log.Error(err)
299299
return
@@ -321,27 +321,27 @@ func Extract(extractValues []db.IntegrationExtractValue, r *http.Request, payloa
321321
}
322322

323323
func ExtractAsAnyForTaskParams(extractValues []db.IntegrationExtractValue, r *http.Request, payload []byte) db.MapStringAnyField {
324-
// Create a result map that accepts any type
325-
result := make(db.MapStringAnyField)
326-
327-
for _, extractValue := range extractValues {
328-
switch extractValue.ValueSource {
329-
case db.IntegrationExtractHeaderValue:
330-
// Extract the header value
331-
result[extractValue.Variable] = r.Header.Get(extractValue.Key)
332-
333-
case db.IntegrationExtractBodyValue:
334-
switch extractValue.BodyDataType {
335-
case db.IntegrationBodyDataJSON:
336-
// Query the JSON payload for the key using gojsonq
337-
rawValue := gojsonq.New().JSONString(string(payload)).Find(extractValue.Key)
338-
result[extractValue.Variable] = rawValue
339-
340-
case db.IntegrationBodyDataString:
341-
// Simply use the entire payload as a string
342-
result[extractValue.Variable] = string(payload)
343-
}
344-
}
345-
}
346-
return result
347-
}
324+
// Create a result map that accepts any type
325+
result := make(db.MapStringAnyField)
326+
327+
for _, extractValue := range extractValues {
328+
switch extractValue.ValueSource {
329+
case db.IntegrationExtractHeaderValue:
330+
// Extract the header value
331+
result[extractValue.Variable] = r.Header.Get(extractValue.Key)
332+
333+
case db.IntegrationExtractBodyValue:
334+
switch extractValue.BodyDataType {
335+
case db.IntegrationBodyDataJSON:
336+
// Query the JSON payload for the key using gojsonq
337+
rawValue := gojsonq.New().JSONString(string(payload)).Find(extractValue.Key)
338+
result[extractValue.Variable] = rawValue
339+
340+
case db.IntegrationBodyDataString:
341+
// Simply use the entire payload as a string
342+
result[extractValue.Variable] = string(payload)
343+
}
344+
}
345+
}
346+
return result
347+
}

api/projects/tasks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ func AddTask(w http.ResponseWriter, r *http.Request) {
3232
return
3333
}
3434

35-
newTask, err := helpers.TaskPool(r).AddTask(taskObj, &user.ID, project.ID, tpl.App.NeedTaskAlias())
35+
newTask, err := helpers.TaskPool(r).AddTask(
36+
taskObj,
37+
&user.ID,
38+
user.Username,
39+
project.ID,
40+
tpl.App.NeedTaskAlias(),
41+
)
3642

3743
if errors.Is(err, tasks.ErrInvalidSubscription) {
3844
helpers.WriteErrorStatus(w, "No active subscription available.", http.StatusForbidden)

services/schedules/SchedulePool.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ func (r ScheduleRunner) Run() {
8383
return
8484
}
8585

86-
_, err = r.pool.taskPool.AddTask(db.Task{
86+
task := db.Task{
8787
TemplateID: schedule.TemplateID,
8888
ProjectID: schedule.ProjectID,
89-
}, nil, schedule.ProjectID, tpl.App.NeedTaskAlias())
89+
}
90+
91+
_, err = r.pool.taskPool.AddTask(
92+
task,
93+
nil,
94+
"",
95+
schedule.ProjectID,
96+
tpl.App.NeedTaskAlias(),
97+
)
9098

9199
if err != nil {
92100
log.Error(err)

services/tasks/TaskPool.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,13 @@ func getNextBuildVersion(startVersion string, currentVersion string) string {
341341
return prefix + strconv.Itoa(newVer) + suffix
342342
}
343343

344-
func (p *TaskPool) AddTask(taskObj db.Task, userID *int, projectID int, needAlias bool) (newTask db.Task, err error) {
344+
func (p *TaskPool) AddTask(
345+
taskObj db.Task,
346+
userID *int,
347+
username string,
348+
projectID int,
349+
needAlias bool,
350+
) (newTask db.Task, err error) {
345351
taskObj.Created = time.Now().UTC()
346352
taskObj.Status = task_logger.TaskWaitingStatus
347353
taskObj.UserID = userID
@@ -379,8 +385,9 @@ func (p *TaskPool) AddTask(taskObj db.Task, userID *int, projectID int, needAlia
379385
}
380386

381387
taskRunner := TaskRunner{
382-
Task: newTask,
383-
pool: p,
388+
Task: newTask,
389+
pool: p,
390+
Username: username,
384391
}
385392

386393
if needAlias {
@@ -425,7 +432,7 @@ func (p *TaskPool) AddTask(taskObj db.Task, userID *int, projectID int, needAlia
425432
taskRunner.job = job
426433

427434
p.register <- &taskRunner
428-
435+
429436
taskRunner.createTaskEvent()
430437

431438
return

services/tasks/TaskRunner.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,18 @@ func (t *TaskRunner) run() {
197197
}
198198

199199
for _, tpl := range tpls {
200-
_, err = t.pool.AddTask(db.Task{
200+
task := db.Task{
201201
TemplateID: tpl.ID,
202202
ProjectID: tpl.ProjectID,
203203
BuildTaskID: &t.Task.ID,
204-
}, nil, tpl.ProjectID, tpl.App.NeedTaskAlias())
204+
}
205+
_, err = t.pool.AddTask(
206+
task,
207+
nil,
208+
"",
209+
tpl.ProjectID,
210+
tpl.App.NeedTaskAlias(),
211+
)
205212
if err != nil {
206213
t.Log("Running app failed: " + err.Error())
207214
continue

0 commit comments

Comments
 (0)