mirror of https://github.com/go-gitea/gitea.git
Add a new event for actions finished and send email to related users
This commit is contained in:
parent
663acd0b46
commit
c07ed745c7
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {}
|
||||
|
|
Loading…
Reference in New Issue