Skip to content

Commit e20428d

Browse files
lunnysilverwinddelvhGiteaBot
authored
Fix commitstatus summary (#30431)
The target_url is necessary for the UI, but missed in commit_status_summary table. This PR fix it. --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: delvh <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent f326754 commit e20428d

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

models/git/commit_status_summary.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import (
1515

1616
// CommitStatusSummary holds the latest commit Status of a single Commit
1717
type CommitStatusSummary struct {
18-
ID int64 `xorm:"pk autoincr"`
19-
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
20-
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
21-
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
18+
ID int64 `xorm:"pk autoincr"`
19+
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
20+
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
21+
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
22+
TargetURL string `xorm:"TEXT"`
2223
}
2324

2425
func init() {
@@ -44,9 +45,10 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA
4445
commitStatuses := make([]*CommitStatus, 0, len(repoSHAs))
4546
for _, summary := range summaries {
4647
commitStatuses = append(commitStatuses, &CommitStatus{
47-
RepoID: summary.RepoID,
48-
SHA: summary.SHA,
49-
State: summary.State,
48+
RepoID: summary.RepoID,
49+
SHA: summary.SHA,
50+
State: summary.State,
51+
TargetURL: summary.TargetURL,
5052
})
5153
}
5254
return commitStatuses, nil
@@ -61,22 +63,24 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er
6163
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
6264
// so we need to use insert in on duplicate
6365
if setting.Database.Type.IsMySQL() {
64-
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?",
65-
repoID, sha, state.State, state.State)
66+
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state,target_url) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE state=?",
67+
repoID, sha, state.State, state.TargetURL, state.State)
6668
return err
6769
}
6870

6971
if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha).
70-
Cols("state").
72+
Cols("state, target_url").
7173
Update(&CommitStatusSummary{
72-
State: state.State,
74+
State: state.State,
75+
TargetURL: state.TargetURL,
7376
}); err != nil {
7477
return err
7578
} else if cnt == 0 {
7679
_, err = db.GetEngine(ctx).Insert(&CommitStatusSummary{
77-
RepoID: repoID,
78-
SHA: sha,
79-
State: state.State,
80+
RepoID: repoID,
81+
SHA: sha,
82+
State: state.State,
83+
TargetURL: state.TargetURL,
8084
})
8185
return err
8286
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ var migrations = []Migration{
580580
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
581581
// v295 -> v296
582582
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
583+
// v296 -> v297
584+
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
583585
}
584586

585587
// GetCurrentDBVersion returns the current db version

models/migrations/v1_23/v296.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddCommitStatusSummary2(x *xorm.Engine) error {
9+
type CommitStatusSummary struct {
10+
ID int64 `xorm:"pk autoincr"`
11+
TargetURL string `xorm:"TEXT"`
12+
}
13+
// there is no migrations because if there is no data on this table, it will fall back to get data
14+
// from commit status
15+
return x.Sync(new(CommitStatusSummary))
16+
}

0 commit comments

Comments
 (0)