Add a new event for actions finished and send email to related users

This commit is contained in:
Lunny Xiao 2024-04-04 22:59:04 +08:00
parent 663acd0b46
commit c07ed745c7
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
5 changed files with 30 additions and 0 deletions

View File

@ -12,7 +12,9 @@ import (
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
notify_service "code.gitea.io/gitea/services/notify"
"github.com/nektos/act/pkg/jobparser"
"xorm.io/builder"
@ -71,6 +73,14 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
}); err != nil {
return err
}
run, _, err := db.GetByID[actions_model.ActionRun](ctx, runID)
if err != nil {
log.Error("GetByID failed: %v", err)
} else if run.Status == actions_model.StatusSuccess || run.Status == actions_model.StatusFailure {
notify_service.ActionRunFinished(ctx, run)
}
CreateCommitStatus(ctx, jobs...)
return nil
}

View File

@ -7,6 +7,7 @@ import (
"context"
"fmt"
actions_model "code.gitea.io/gitea/models/actions"
activities_model "code.gitea.io/gitea/models/activities"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
@ -202,3 +203,7 @@ func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *
log.Error("SendRepoTransferNotifyMail: %v", err)
}
}
func (m *mailNotifier) ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {
// TODO: send email to related users
}

View File

@ -6,6 +6,7 @@ package notify
import (
"context"
actions_model "code.gitea.io/gitea/models/actions"
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@ -74,4 +75,6 @@ type Notifier interface {
PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository)
ActionRunFinished(ctx context.Context, run *actions_model.ActionRun)
}

View File

@ -6,6 +6,7 @@ package notify
import (
"context"
actions_model "code.gitea.io/gitea/models/actions"
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@ -367,3 +368,10 @@ func ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
notifier.ChangeDefaultBranch(ctx, repo)
}
}
// ActionRunFinished represents action run finished
func ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {
for _, notifier := range notifiers {
notifier.ActionRunFinished(ctx, run)
}
}

View File

@ -6,6 +6,7 @@ package notify
import (
"context"
actions_model "code.gitea.io/gitea/models/actions"
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@ -208,3 +209,6 @@ func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, p
// ChangeDefaultBranch places a place holder function
func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
}
// ActionRunFinished represents action run finished
func (*NullNotifier) ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {}