mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-20 11:43:57 +08:00
Compare commits
7 Commits
30c9dc74d8
...
3bb150a7c9
Author | SHA1 | Date | |
---|---|---|---|
|
3bb150a7c9 | ||
|
40faa6dc78 | ||
|
370284cf60 | ||
|
8963c10574 | ||
|
95ee4c6a94 | ||
|
70f02e00ae | ||
|
ba0805520a |
@ -11,7 +11,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"
|
||||
@ -70,6 +72,12 @@ 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"
|
||||
@ -203,3 +204,63 @@ 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) {
|
||||
// Check status first to avoid unnecessary processing
|
||||
if run.Status != actions_model.StatusSuccess && run.Status != actions_model.StatusFailure {
|
||||
return
|
||||
}
|
||||
|
||||
// Load required attributes after status check
|
||||
if err := run.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
subject := fmt.Sprintf("[%s] Workflow run %s: %s",
|
||||
run.Repo.FullName(),
|
||||
run.WorkflowID,
|
||||
run.Status,
|
||||
)
|
||||
|
||||
// Safely handle short commit SHA
|
||||
commitSHA := run.CommitSHA
|
||||
if len(commitSHA) > 7 {
|
||||
commitSHA = commitSHA[:7]
|
||||
}
|
||||
|
||||
body := fmt.Sprintf(`Workflow "%s" run #%d has completed with status: %s
|
||||
|
||||
Repository: %s
|
||||
Branch: %s
|
||||
Commit: %s
|
||||
Triggered by: %s
|
||||
|
||||
View the run details here: %s`,
|
||||
run.WorkflowID,
|
||||
run.Index,
|
||||
run.Status,
|
||||
run.Repo.FullName(),
|
||||
run.PrettyRef(),
|
||||
commitSHA,
|
||||
run.TriggerUser.Name,
|
||||
run.HTMLURL(),
|
||||
)
|
||||
|
||||
// Send to repo owner if notifications enabled and email present
|
||||
if run.Repo.Owner.Email != "" &&
|
||||
run.Repo.Owner.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
if err := SendMailFrom(ctx, run.Repo.Owner.Email, subject, body); err != nil {
|
||||
log.Error("Failed to send email to repo owner %s: %v", run.Repo.Owner.Email, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Send to trigger user if different from owner and notifications enabled
|
||||
if run.TriggerUser.ID != run.Repo.Owner.ID &&
|
||||
run.TriggerUser.Email != "" &&
|
||||
run.TriggerUser.EmailNotificationsPreference != user_model.EmailNotificationsDisabled {
|
||||
if err := SendMailFrom(ctx, run.TriggerUser.Email, subject, body); err != nil {
|
||||
log.Error("Failed to send email to trigger user %s: %v", run.TriggerUser.Email, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
@ -76,5 +77,7 @@ type Notifier interface {
|
||||
|
||||
ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository)
|
||||
|
||||
ActionRunFinished(ctx context.Context, run *actions_model.ActionRun)
|
||||
|
||||
CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package notify
|
||||
import (
|
||||
"context"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
@ -374,3 +375,10 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit
|
||||
notifier.CreateCommitStatus(ctx, repo, commit, sender, status)
|
||||
}
|
||||
}
|
||||
|
||||
// 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"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
@ -212,3 +213,7 @@ func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.R
|
||||
|
||||
func (*NullNotifier) CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, commit *repository.PushCommit, sender *user_model.User, status *git_model.CommitStatus) {
|
||||
}
|
||||
|
||||
|
||||
// ActionRunFinished represents action run finished
|
||||
func (*NullNotifier) ActionRunFinished(ctx context.Context, run *actions_model.ActionRun) {}
|
||||
|
@ -29,7 +29,7 @@ func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bo
|
||||
}
|
||||
|
||||
if len(branches) == 0 {
|
||||
graphCmd.AddArguments("--all")
|
||||
graphCmd.AddArguments("--tags", "--branches")
|
||||
}
|
||||
|
||||
graphCmd.AddArguments("-C", "-M", "--date=iso-strict").
|
||||
|
Loading…
x
Reference in New Issue
Block a user