Merge pull request '[TESTS] fail when log.Error is called' (#2657) from oliverpool/forgejo:fail_test_on_log_error into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2657
This commit is contained in:
commit
5a18b74632
46 changed files with 732 additions and 105 deletions
|
@ -6,6 +6,7 @@ package actions
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
@ -25,6 +26,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
|
||||
|
@ -190,6 +192,12 @@ func notify(ctx context.Context, input *notifyInput) error {
|
|||
baseRef := git.BranchPrefix + input.PullRequest.BaseBranch
|
||||
baseCommit, err := gitRepo.GetCommit(baseRef)
|
||||
if err != nil {
|
||||
if prp, ok := input.Payload.(*api.PullRequestPayload); ok && errors.Is(err, util.ErrNotExist) {
|
||||
// the baseBranch was deleted and the PR closed: the action can be skipped
|
||||
if prp.Action == api.HookIssueClosed {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("gitRepo.GetCommit: %w", err)
|
||||
}
|
||||
baseWorkflows, _, err := actions_module.DetectWorkflows(gitRepo, baseCommit, input.Event, input.Payload)
|
||||
|
|
|
@ -165,11 +165,15 @@ func createPackageAndVersion(ctx context.Context, pvci *PackageCreationInfo, all
|
|||
if pv, err = packages_model.GetOrInsertVersion(ctx, pv); err != nil {
|
||||
if err == packages_model.ErrDuplicatePackageVersion {
|
||||
versionCreated = false
|
||||
}
|
||||
if err != packages_model.ErrDuplicatePackageVersion || !allowDuplicate {
|
||||
} else {
|
||||
log.Error("Error inserting package: %v", err)
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if !allowDuplicate {
|
||||
// no need to log an error
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
if versionCreated {
|
||||
|
|
|
@ -65,7 +65,7 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
|
|||
if status != nil {
|
||||
return status.State
|
||||
}
|
||||
return structs.CommitStatusSuccess
|
||||
return ""
|
||||
}
|
||||
|
||||
return returnedStatus
|
||||
|
|
|
@ -123,7 +123,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep
|
|||
for i, repo := range repos {
|
||||
if results[i] == nil {
|
||||
results[i] = git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
|
||||
if results[i].State != "" {
|
||||
if results[i] != nil {
|
||||
if err := updateCommitStatusCache(ctx, repo.ID, repo.DefaultBranch, results[i].State); err != nil {
|
||||
log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err)
|
||||
}
|
||||
|
|
|
@ -28,10 +28,19 @@ func TestWebhook_GetSlackHook(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func activateWebhook(t *testing.T, hookID int64) {
|
||||
t.Helper()
|
||||
updated, err := db.GetEngine(db.DefaultContext).ID(hookID).Cols("is_active").Update(webhook_model.Webhook{IsActive: true})
|
||||
assert.Equal(t, int64(1), updated)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestPrepareWebhooks(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
activateWebhook(t, 1)
|
||||
|
||||
hookTasks := []*webhook_model.HookTask{
|
||||
{HookID: 1, EventType: webhook_module.HookEventPush},
|
||||
}
|
||||
|
@ -48,6 +57,8 @@ func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
|
|||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||
activateWebhook(t, 4)
|
||||
|
||||
hookTasks := []*webhook_model.HookTask{
|
||||
{HookID: 4, EventType: webhook_module.HookEventPush},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue