Skip to content

Commit bd06180

Browse files
Merge branch 'main' into pnpm
2 parents ab34337 + c4fbccc commit bd06180

File tree

7 files changed

+505
-67
lines changed

7 files changed

+505
-67
lines changed

.github/workflows/release-nightly.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ jobs:
7676
- name: Get cleaned branch name
7777
id: clean_name
7878
run: |
79-
# if main then say nightly otherwise cleanup name
80-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
81-
echo "branch=nightly" >> "$GITHUB_OUTPUT"
82-
exit 0
83-
fi
8479
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
8580
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
8681
- name: Login to Docker Hub
@@ -123,11 +118,6 @@ jobs:
123118
- name: Get cleaned branch name
124119
id: clean_name
125120
run: |
126-
# if main then say nightly otherwise cleanup name
127-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
128-
echo "branch=nightly" >> "$GITHUB_OUTPUT"
129-
exit 0
130-
fi
131121
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
132122
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
133123
- name: Login to Docker Hub

routers/api/v1/repo/issue_comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ func deleteIssueComment(ctx *context.APIContext) {
721721
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
722722
ctx.Status(http.StatusForbidden)
723723
return
724-
} else if comment.Type != issues_model.CommentTypeComment {
725-
ctx.Status(http.StatusNoContent)
724+
} else if !comment.Type.HasContentSupport() {
725+
ctx.Status(http.StatusBadRequest)
726726
return
727727
}
728728

routers/web/repo/actions/view.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ func Rerun(ctx *context_module.Context) {
429429
ctx.ServerError("UpdateRun", err)
430430
return
431431
}
432+
433+
if err := run.LoadAttributes(ctx); err != nil {
434+
ctx.ServerError("run.LoadAttributes", err)
435+
return
436+
}
437+
notify_service.WorkflowRunStatusUpdate(ctx, run.Repo, run.TriggerUser, run)
432438
}
433439

434440
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
@@ -485,7 +491,6 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
485491
}
486492

487493
actions_service.CreateCommitStatus(ctx, job)
488-
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
489494
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
490495

491496
return nil
@@ -560,9 +565,8 @@ func Cancel(ctx *context_module.Context) {
560565
if len(updatedjobs) > 0 {
561566
job := updatedjobs[0]
562567
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
563-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
564568
}
565-
ctx.JSON(http.StatusOK, struct{}{})
569+
ctx.JSONOK()
566570
}
567571

568572
func Approve(ctx *context_module.Context) {
@@ -606,15 +610,14 @@ func Approve(ctx *context_module.Context) {
606610
if len(updatedjobs) > 0 {
607611
job := updatedjobs[0]
608612
actions_service.NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
609-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
610613
}
611614

612615
for _, job := range updatedjobs {
613616
_ = job.LoadAttributes(ctx)
614617
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
615618
}
616619

617-
ctx.JSON(http.StatusOK, struct{}{})
620+
ctx.JSONOK()
618621
}
619622

620623
func Delete(ctx *context_module.Context) {

services/actions/clear_tasks.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ func notifyWorkflowJobStatusUpdate(ctx context.Context, jobs []*actions_model.Ac
4242
_ = job.LoadAttributes(ctx)
4343
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
4444
}
45-
if len(jobs) > 0 {
46-
job := jobs[0]
47-
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
48-
}
45+
job := jobs[0]
46+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
4947
}
5048
}
5149

@@ -101,7 +99,7 @@ func stopTasks(ctx context.Context, opts actions_model.FindTaskOptions) error {
10199
return nil
102100
}
103101

104-
// CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time
102+
// CancelAbandonedJobs cancels jobs that have not been picked by any runner for a long time
105103
func CancelAbandonedJobs(ctx context.Context) error {
106104
jobs, err := db.Find[actions_model.ActionRunJob](ctx, actions_model.FindRunJobOptions{
107105
Statuses: []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusBlocked},
@@ -113,24 +111,40 @@ func CancelAbandonedJobs(ctx context.Context) error {
113111
}
114112

115113
now := timeutil.TimeStampNow()
114+
115+
// Collect one job per run to send workflow run status update
116+
updatedRuns := map[int64]*actions_model.ActionRunJob{}
117+
116118
for _, job := range jobs {
117119
job.Status = actions_model.StatusCancelled
118120
job.Stopped = now
119121
updated := false
120122
if err := db.WithTx(ctx, func(ctx context.Context) error {
121123
n, err := actions_model.UpdateRunJob(ctx, job, nil, "status", "stopped")
122-
updated = err == nil && n > 0
123-
return err
124+
if err != nil {
125+
return err
126+
}
127+
if err := job.LoadAttributes(ctx); err != nil {
128+
return err
129+
}
130+
updated = n > 0
131+
if updated && job.Run.Status.IsDone() {
132+
updatedRuns[job.RunID] = job
133+
}
134+
return nil
124135
}); err != nil {
125136
log.Warn("cancel abandoned job %v: %v", job.ID, err)
126137
// go on
127138
}
128139
CreateCommitStatus(ctx, job)
129140
if updated {
130-
NotifyWorkflowRunStatusUpdateWithReload(ctx, job)
131141
notify_service.WorkflowJobStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job, nil)
132142
}
133143
}
134144

145+
for _, job := range updatedRuns {
146+
notify_service.WorkflowRunStatusUpdate(ctx, job.Run.Repo, job.Run.TriggerUser, job.Run)
147+
}
148+
135149
return nil
136150
}

services/mailer/mail_workflow_run.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Reposito
3333
return fmt.Sprintf("<%s/actions/runs/%d@%s>", repo.FullName(), run.Index, setting.Domain)
3434
}
3535

36-
func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, sender *user_model.User, recipients []*user_model.User) {
36+
func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, sender *user_model.User, recipients []*user_model.User) error {
37+
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
38+
if err != nil {
39+
return err
40+
}
41+
for _, job := range jobs {
42+
if !job.Status.IsDone() {
43+
log.Debug("composeAndSendActionsWorkflowRunStatusEmail: A job is not done. Will not compose and send actions email.")
44+
return nil
45+
}
46+
}
47+
3748
subject := "Run"
3849
switch run.Status {
3950
case actions_model.StatusFailure:
@@ -48,11 +59,6 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
4859
messageID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run)
4960
metadataHeaders := generateMetadataHeaders(repo)
5061

51-
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
52-
if err != nil {
53-
log.Error("GetRunJobsByRunID: %v", err)
54-
return
55-
}
5662
sort.SliceStable(jobs, func(i, j int) bool {
5763
si, sj := jobs[i].Status, jobs[j].Status
5864
/*
@@ -111,11 +117,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
111117
"Jobs": convertedJobs,
112118
"locale": locale,
113119
}); err != nil {
114-
log.Error("ExecuteTemplate [%s]: %v", tplWorkflowRun, err)
115-
return
120+
return err
116121
}
117122
msgs := make([]*sender_service.Message, 0, len(tos))
118123
for _, rec := range tos {
124+
log.Trace("Sending actions email to %s (UID: %d)", rec.Name, rec.ID)
119125
msg := sender_service.NewMessageFrom(
120126
rec.Email,
121127
displayName,
@@ -135,14 +141,16 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
135141
}
136142
SendAsync(msgs...)
137143
}
144+
145+
return nil
138146
}
139147

140-
func MailActionsTrigger(ctx context.Context, sender *user_model.User, repo *repo_model.Repository, run *actions_model.ActionRun) {
148+
func MailActionsTrigger(ctx context.Context, sender *user_model.User, repo *repo_model.Repository, run *actions_model.ActionRun) error {
141149
if setting.MailService == nil {
142-
return
150+
return nil
143151
}
144-
if run.Status.IsSkipped() {
145-
return
152+
if !run.Status.IsDone() || run.Status.IsSkipped() {
153+
return nil
146154
}
147155

148156
recipients := make([]*user_model.User, 0)
@@ -151,15 +159,16 @@ func MailActionsTrigger(ctx context.Context, sender *user_model.User, repo *repo
151159
notifyPref, err := user_model.GetUserSetting(ctx, sender.ID,
152160
user_model.SettingsKeyEmailNotificationGiteaActions, user_model.SettingEmailNotificationGiteaActionsFailureOnly)
153161
if err != nil {
154-
log.Error("GetUserSetting: %v", err)
155-
return
162+
return err
156163
}
157164
if notifyPref == user_model.SettingEmailNotificationGiteaActionsAll || !run.Status.IsSuccess() && notifyPref != user_model.SettingEmailNotificationGiteaActionsDisabled {
158165
recipients = append(recipients, sender)
159166
}
160167
}
161168

162169
if len(recipients) > 0 {
163-
composeAndSendActionsWorkflowRunStatusEmail(ctx, repo, run, sender, recipients)
170+
log.Debug("MailActionsTrigger: Initiate email composition")
171+
return composeAndSendActionsWorkflowRunStatusEmail(ctx, repo, run, sender, recipients)
164172
}
173+
return nil
165174
}

services/mailer/notify.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *
208208
}
209209

210210
func (m *mailNotifier) WorkflowRunStatusUpdate(ctx context.Context, repo *repo_model.Repository, sender *user_model.User, run *actions_model.ActionRun) {
211-
if !run.Status.IsDone() {
212-
return
211+
if err := MailActionsTrigger(ctx, sender, repo, run); err != nil {
212+
log.Error("MailActionsTrigger: %v", err)
213213
}
214-
MailActionsTrigger(ctx, sender, repo, run)
215214
}

0 commit comments

Comments
 (0)