diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index 4ab1beec923..f50fa04c5e8 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -32,6 +32,9 @@ type RepoSHA struct { } func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA) ([]*CommitStatus, error) { + if len(repoSHAs) == 0 { + return nil, nil + } cond := builder.NewCond() for _, rs := range repoSHAs { cond = cond.Or(builder.Eq{"repo_id": rs.RepoID, "sha": rs.SHA}) @@ -67,8 +70,8 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er // mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database, // so we need to use insert in on duplicate if setting.Database.Type.IsMySQL() { - _, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state,target_url) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE state=?", - repoID, sha, state.State, state.TargetURL, state.State) + _, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state,target_url) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE state=?, target_url=?", + repoID, sha, state.State, state.TargetURL, state.State, state.TargetURL) return err } diff --git a/models/git/commit_status_test.go b/models/git/commit_status_test.go index 954e444e8da..20ec0d9dc37 100644 --- a/models/git/commit_status_test.go +++ b/models/git/commit_status_test.go @@ -89,6 +89,13 @@ func TestGetCommitStatuses(t *testing.T) { "deploy/awesomeness": 5, }, latestIndexes) }) + + t.Run("GetLatestCommitStatusForRepoAndSHAsEmpty", func(t *testing.T) { + assert.NoError(t, git_model.UpdateCommitStatusSummary(t.Context(), repo1.ID, sha1)) + statuses, err := git_model.GetLatestCommitStatusForRepoAndSHAs(t.Context(), nil) + assert.NoError(t, err) + assert.Empty(t, statuses) + }) } func Test_CalcCommitStatus(t *testing.T) {