Skip to content

Commit bc16df1

Browse files
committed
fix various problems
1 parent ee304d5 commit bc16df1

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

models/git/commit_status.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ type CommitStatusIndex struct {
298298
MaxIndex int64 `xorm:"index"`
299299
}
300300

301-
var getBase = func(ctx context.Context, repoID int64, sha string) *xorm.Session {
301+
func makeRepoCommitQuery(ctx context.Context, repoID int64, sha string) *xorm.Session {
302302
return db.GetEngine(ctx).Table(&CommitStatus{}).
303303
Where("repo_id = ?", repoID).And("sha = ?", sha)
304304
}
305305

306306
// GetLatestCommitStatus returns all statuses with a unique context for a given commit.
307307
func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, error) {
308308
indices := make([]int64, 0, 10)
309-
sess := getBase(ctx, repoID, sha).
309+
sess := makeRepoCommitQuery(ctx, repoID, sha).
310310
Select("max( `index` ) as `index`").
311311
GroupBy("context_hash").
312312
OrderBy("max( `index` ) desc")
@@ -320,11 +320,12 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp
320320
if len(indices) == 0 {
321321
return statuses, nil
322322
}
323-
return statuses, getBase(ctx, repoID, sha).And(builder.In("`index`", indices)).Find(&statuses)
323+
err := makeRepoCommitQuery(ctx, repoID, sha).And(builder.In("`index`", indices)).Find(&statuses)
324+
return statuses, err
324325
}
325326

326327
func CountLatestCommitStatus(ctx context.Context, repoID int64, sha string) (int64, error) {
327-
return getBase(ctx, repoID, sha).
328+
return makeRepoCommitQuery(ctx, repoID, sha).
328329
Select("count(context_hash)").
329330
GroupBy("context_hash").
330331
Count()

models/git/commit_status_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestGetCommitStatuses(t *testing.T) {
2626

2727
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
2828

29-
sha1 := "1234123412341234123412341234123412341234"
29+
sha1 := "1234123412341234123412341234123412341234" // the mocked commit ID in test fixtures
3030

3131
statuses, maxResults, err := db.FindAndCount[git_model.CommitStatus](db.DefaultContext, &git_model.CommitStatusOptions{
3232
ListOptions: db.ListOptions{Page: 1, PageSize: 50},
@@ -262,7 +262,7 @@ func TestGetCountLatestCommitStatus(t *testing.T) {
262262

263263
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
264264

265-
sha1 := "1234123412341234123412341234123412341234"
265+
sha1 := "1234123412341234123412341234123412341234" // the mocked commit ID in test fixtures
266266

267267
commitStatuses, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo1.ID, sha1, db.ListOptions{
268268
Page: 1,

routers/api/v1/repo/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
266266

267267
count, err := git_model.CountLatestCommitStatus(ctx, repo.ID, refCommit.Commit.ID.String())
268268
if err != nil {
269-
ctx.APIErrorInternal(fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err))
269+
ctx.APIErrorInternal(fmt.Errorf("CountLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err))
270270
return
271271
}
272272
ctx.SetTotalCountHeader(count)

0 commit comments

Comments
 (0)