mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-06 10:25:22 +02:00
fix: disable Forgejo Actions email notifications on recovery (#8374)
- Make the migration to add an index a noop - do not remove it as it would break v12.next & v13.next - Keep the logic that relies on finding the last run, only always fail to find which is the same as assuming each run is one of a kind Refs forgejo/forgejo#8373 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8374 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
bcde3aea4f
commit
c0eeb75322
6 changed files with 10 additions and 144 deletions
|
@ -284,16 +284,10 @@ func GetLatestRun(ctx context.Context, repoID int64) (*ActionRun, error) {
|
|||
return &run, nil
|
||||
}
|
||||
|
||||
// GetRunBefore returns the last run that completed a given timestamp (not inclusive).
|
||||
func GetRunBefore(ctx context.Context, repoID int64, timestamp timeutil.TimeStamp) (*ActionRun, error) {
|
||||
var run ActionRun
|
||||
has, err := db.GetEngine(ctx).Where("repo_id=? AND stopped IS NOT NULL AND stopped<?", repoID, timestamp).OrderBy("stopped DESC").Limit(1).Get(&run)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, fmt.Errorf("run before: %w", util.ErrNotExist)
|
||||
}
|
||||
return &run, nil
|
||||
func GetRunBefore(ctx context.Context, _ *ActionRun) (*ActionRun, error) {
|
||||
// TODO return the most recent run related to the run given in argument
|
||||
// see https://codeberg.org/forgejo/user-research/issues/63 for context
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func GetLatestRunForBranchAndWorkflow(ctx context.Context, repoID int64, branch, workflowFile, event string) (*ActionRun, error) {
|
||||
|
|
|
@ -5,92 +5,7 @@ package actions
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forgejo.org/models/db"
|
||||
"forgejo.org/models/unittest"
|
||||
"forgejo.org/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetRunBefore(t *testing.T) {
|
||||
require.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// this repo is part of the test database requiring loading "repository.yml" in main_test.go
|
||||
var repoID int64 = 1
|
||||
|
||||
workflowID := "test_workflow"
|
||||
|
||||
// third completed run
|
||||
time1, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00")
|
||||
require.NoError(t, err)
|
||||
timeutil.MockSet(time1)
|
||||
run1 := ActionRun{
|
||||
ID: 1,
|
||||
Index: 1,
|
||||
RepoID: repoID,
|
||||
Stopped: timeutil.TimeStampNow(),
|
||||
WorkflowID: workflowID,
|
||||
}
|
||||
|
||||
// fourth completed run
|
||||
time2, err := time.Parse(time.RFC3339, "2024-08-31T15:47:55+08:00")
|
||||
require.NoError(t, err)
|
||||
timeutil.MockSet(time2)
|
||||
run2 := ActionRun{
|
||||
ID: 2,
|
||||
Index: 2,
|
||||
RepoID: repoID,
|
||||
Stopped: timeutil.TimeStampNow(),
|
||||
WorkflowID: workflowID,
|
||||
}
|
||||
|
||||
// second completed run
|
||||
time3, err := time.Parse(time.RFC3339, "2024-07-31T15:47:54+08:00")
|
||||
require.NoError(t, err)
|
||||
timeutil.MockSet(time3)
|
||||
run3 := ActionRun{
|
||||
ID: 3,
|
||||
Index: 3,
|
||||
RepoID: repoID,
|
||||
Stopped: timeutil.TimeStampNow(),
|
||||
WorkflowID: workflowID,
|
||||
}
|
||||
|
||||
// first completed run
|
||||
time4, err := time.Parse(time.RFC3339, "2024-06-30T15:47:54+08:00")
|
||||
require.NoError(t, err)
|
||||
timeutil.MockSet(time4)
|
||||
run4 := ActionRun{
|
||||
ID: 4,
|
||||
Index: 4,
|
||||
RepoID: repoID,
|
||||
Stopped: timeutil.TimeStampNow(),
|
||||
WorkflowID: workflowID,
|
||||
}
|
||||
require.NoError(t, db.Insert(db.DefaultContext, &run1))
|
||||
runBefore, err := GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
||||
// there is no run before run1
|
||||
require.Error(t, err)
|
||||
require.Nil(t, runBefore)
|
||||
|
||||
// now there is only run3 before run1
|
||||
require.NoError(t, db.Insert(db.DefaultContext, &run3))
|
||||
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, run3.ID, runBefore.ID)
|
||||
|
||||
// there still is only run3 before run1
|
||||
require.NoError(t, db.Insert(db.DefaultContext, &run2))
|
||||
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, run3.ID, runBefore.ID)
|
||||
|
||||
// run4 is further away from run1
|
||||
require.NoError(t, db.Insert(db.DefaultContext, &run4))
|
||||
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, run3.ID, runBefore.ID)
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ var migrations = []*Migration{
|
|||
// v33 -> v34
|
||||
NewMigration("Add `notify-email` column to `action_run` table", AddNotifyEmailToActionRun),
|
||||
// v34 -> v35
|
||||
NewMigration("Add index to `stopped` column in `action_run` table", AddIndexToActionRunStopped),
|
||||
NewMigration("Noop because of https://codeberg.org/forgejo/forgejo/issues/8373", NoopAddIndexToActionRunStopped),
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current Forgejo database version.
|
||||
|
|
|
@ -4,16 +4,10 @@
|
|||
package forgejo_migrations //nolint:revive
|
||||
|
||||
import (
|
||||
"forgejo.org/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddIndexToActionRunStopped(x *xorm.Engine) error {
|
||||
type ActionRun struct {
|
||||
ID int64
|
||||
Stopped timeutil.TimeStamp `xorm:"index"`
|
||||
}
|
||||
|
||||
return x.Sync(&ActionRun{})
|
||||
// see https://codeberg.org/forgejo/forgejo/issues/8373
|
||||
func NoopAddIndexToActionRunStopped(x *xorm.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue