mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:56:14 +01:00
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 <me@silverwind.io> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
parent
f393ccf745
commit
c0d22d55c9
3 changed files with 36 additions and 14 deletions
|
@ -19,6 +19,7 @@ type CommitStatusSummary struct {
|
||||||
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
|
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
|
||||||
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
|
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
|
||||||
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
|
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
|
||||||
|
TargetURL string `xorm:"TEXT"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -47,6 +48,7 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA
|
||||||
RepoID: summary.RepoID,
|
RepoID: summary.RepoID,
|
||||||
SHA: summary.SHA,
|
SHA: summary.SHA,
|
||||||
State: summary.State,
|
State: summary.State,
|
||||||
|
TargetURL: summary.TargetURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return commitStatuses, nil
|
return commitStatuses, nil
|
||||||
|
@ -61,15 +63,16 @@ 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,
|
// 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
|
// so we need to use insert in on duplicate
|
||||||
if setting.Database.Type.IsMySQL() {
|
if setting.Database.Type.IsMySQL() {
|
||||||
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?",
|
_, 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.State)
|
repoID, sha, state.State, state.TargetURL, state.State)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha).
|
if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha).
|
||||||
Cols("state").
|
Cols("state, target_url").
|
||||||
Update(&CommitStatusSummary{
|
Update(&CommitStatusSummary{
|
||||||
State: state.State,
|
State: state.State,
|
||||||
|
TargetURL: state.TargetURL,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cnt == 0 {
|
} else if cnt == 0 {
|
||||||
|
@ -77,6 +80,7 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er
|
||||||
RepoID: repoID,
|
RepoID: repoID,
|
||||||
SHA: sha,
|
SHA: sha,
|
||||||
State: state.State,
|
State: state.State,
|
||||||
|
TargetURL: state.TargetURL,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -582,6 +582,8 @@ var migrations = []Migration{
|
||||||
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
|
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
|
||||||
// v295 -> v296
|
// v295 -> v296
|
||||||
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
|
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
|
||||||
|
// v296 -> v297
|
||||||
|
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentDBVersion returns the current db version
|
// GetCurrentDBVersion returns the current db version
|
||||||
|
|
16
models/migrations/v1_23/v296.go
Normal file
16
models/migrations/v1_23/v296.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_23 //nolint
|
||||||
|
|
||||||
|
import "xorm.io/xorm"
|
||||||
|
|
||||||
|
func AddCommitStatusSummary2(x *xorm.Engine) error {
|
||||||
|
type CommitStatusSummary struct {
|
||||||
|
ID int64 `xorm:"pk autoincr"`
|
||||||
|
TargetURL string `xorm:"TEXT"`
|
||||||
|
}
|
||||||
|
// there is no migrations because if there is no data on this table, it will fall back to get data
|
||||||
|
// from commit status
|
||||||
|
return x.Sync(new(CommitStatusSummary))
|
||||||
|
}
|
Loading…
Reference in a new issue