feat: add ActionRunNowDone notification channel

This commit is contained in:
christopher-besch 2025-04-08 08:40:22 +02:00
parent eb3feaad45
commit 58551587f3
3 changed files with 19 additions and 0 deletions

View file

@ -6,6 +6,7 @@ package notify
import ( import (
"context" "context"
actions_model "forgejo.org/models/actions"
issues_model "forgejo.org/models/issues" issues_model "forgejo.org/models/issues"
packages_model "forgejo.org/models/packages" packages_model "forgejo.org/models/packages"
repo_model "forgejo.org/models/repo" repo_model "forgejo.org/models/repo"
@ -76,4 +77,6 @@ type Notifier interface {
PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository)
ActionRunNowDone(ctx context.Context, run *actions_model.ActionRun, priorStatus actions_model.Status, lastRun *actions_model.ActionRun)
} }

View file

@ -6,6 +6,7 @@ package notify
import ( import (
"context" "context"
actions_model "forgejo.org/models/actions"
issues_model "forgejo.org/models/issues" issues_model "forgejo.org/models/issues"
packages_model "forgejo.org/models/packages" packages_model "forgejo.org/models/packages"
repo_model "forgejo.org/models/repo" repo_model "forgejo.org/models/repo"
@ -374,3 +375,13 @@ func ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
notifier.ChangeDefaultBranch(ctx, repo) notifier.ChangeDefaultBranch(ctx, repo)
} }
} }
// ActionRunNowDone notifies that the old status priorStatus with (priorStatus.isDone() == false) of an ActionRun changed to run.Status with (run.Status.isDone() == true)
// lastRun might be nil (e.g. when the run is the first for this workflow). It is the last run of the same workflow for the same repo.
// It can be used to figure out if a successful run follows a failed one.
// Both run and lastRun need their attributes loaded.
func ActionRunNowDone(ctx context.Context, run *actions_model.ActionRun, priorStatus actions_model.Status, lastRun *actions_model.ActionRun) {
for _, notifier := range notifiers {
notifier.ActionRunNowDone(ctx, run, priorStatus, lastRun)
}
}

View file

@ -6,6 +6,7 @@ package notify
import ( import (
"context" "context"
actions_model "forgejo.org/models/actions"
issues_model "forgejo.org/models/issues" issues_model "forgejo.org/models/issues"
packages_model "forgejo.org/models/packages" packages_model "forgejo.org/models/packages"
repo_model "forgejo.org/models/repo" repo_model "forgejo.org/models/repo"
@ -211,3 +212,7 @@ func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, p
// ChangeDefaultBranch places a place holder function // ChangeDefaultBranch places a place holder function
func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) { func (*NullNotifier) ChangeDefaultBranch(ctx context.Context, repo *repo_model.Repository) {
} }
// ActionRunNowDone places a place holder function
func (*NullNotifier) ActionRunNowDone(ctx context.Context, run *actions_model.ActionRun, priorStatus actions_model.Status, lastRun *actions_model.ActionRun) {
}