0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 23:53:11 +02:00

Merge branch 'main' into dev/hezi/fix-skipped-icon

This commit is contained in:
wxiaoguang 2025-05-27 20:05:28 +08:00 committed by GitHub
commit 40bcd57d44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 198 additions and 102 deletions

View File

@ -7,6 +7,7 @@
target_url: https://example.com/builds/ target_url: https://example.com/builds/
description: My awesome CI-service description: My awesome CI-service
context: ci/awesomeness context: ci/awesomeness
context_hash: c65f4d64a3b14a3eced0c9b36799e66e1bd5ced7
creator_id: 2 creator_id: 2
- -
@ -18,6 +19,7 @@
target_url: https://example.com/converage/ target_url: https://example.com/converage/
description: My awesome Coverage service description: My awesome Coverage service
context: cov/awesomeness context: cov/awesomeness
context_hash: 3929ac7bccd3fa1bf9b38ddedb77973b1b9a8cfe
creator_id: 2 creator_id: 2
- -
@ -29,6 +31,7 @@
target_url: https://example.com/converage/ target_url: https://example.com/converage/
description: My awesome Coverage service description: My awesome Coverage service
context: cov/awesomeness context: cov/awesomeness
context_hash: 3929ac7bccd3fa1bf9b38ddedb77973b1b9a8cfe
creator_id: 2 creator_id: 2
- -
@ -40,6 +43,7 @@
target_url: https://example.com/builds/ target_url: https://example.com/builds/
description: My awesome CI-service description: My awesome CI-service
context: ci/awesomeness context: ci/awesomeness
context_hash: c65f4d64a3b14a3eced0c9b36799e66e1bd5ced7
creator_id: 2 creator_id: 2
- -
@ -51,4 +55,5 @@
target_url: https://example.com/builds/ target_url: https://example.com/builds/
description: My awesome deploy service description: My awesome deploy service
context: deploy/awesomeness context: deploy/awesomeness
context_hash: ae9547713a6665fc4261d0756904932085a41cf2
creator_id: 2 creator_id: 2

View File

@ -298,27 +298,37 @@ type CommitStatusIndex struct {
MaxIndex int64 `xorm:"index"` MaxIndex int64 `xorm:"index"`
} }
func makeRepoCommitQuery(ctx context.Context, repoID int64, sha string) *xorm.Session {
return db.GetEngine(ctx).Table(&CommitStatus{}).
Where("repo_id = ?", repoID).And("sha = ?", sha)
}
// GetLatestCommitStatus returns all statuses with a unique context for a given commit. // GetLatestCommitStatus returns all statuses with a unique context for a given commit.
func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, int64, error) { func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, error) {
getBase := func() *xorm.Session {
return db.GetEngine(ctx).Table(&CommitStatus{}).
Where("repo_id = ?", repoID).And("sha = ?", sha)
}
indices := make([]int64, 0, 10) indices := make([]int64, 0, 10)
sess := getBase().Select("max( `index` ) as `index`"). sess := makeRepoCommitQuery(ctx, repoID, sha).
GroupBy("context_hash").OrderBy("max( `index` ) desc") Select("max( `index` ) as `index`").
GroupBy("context_hash").
OrderBy("max( `index` ) desc")
if !listOptions.IsListAll() { if !listOptions.IsListAll() {
sess = db.SetSessionPagination(sess, &listOptions) sess = db.SetSessionPagination(sess, &listOptions)
} }
count, err := sess.FindAndCount(&indices) if err := sess.Find(&indices); err != nil {
if err != nil { return nil, err
return nil, count, err
} }
statuses := make([]*CommitStatus, 0, len(indices)) statuses := make([]*CommitStatus, 0, len(indices))
if len(indices) == 0 { if len(indices) == 0 {
return statuses, count, nil return statuses, nil
} }
return statuses, count, getBase().And(builder.In("`index`", indices)).Find(&statuses) err := makeRepoCommitQuery(ctx, repoID, sha).And(builder.In("`index`", indices)).Find(&statuses)
return statuses, err
}
func CountLatestCommitStatus(ctx context.Context, repoID int64, sha string) (int64, error) {
return makeRepoCommitQuery(ctx, repoID, sha).
Select("count(context_hash)").
GroupBy("context_hash").
Count()
} }
// GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs // GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs

View File

@ -55,7 +55,7 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA
} }
func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) error { func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) error {
commitStatuses, _, err := GetLatestCommitStatus(ctx, repoID, sha, db.ListOptionsAll) commitStatuses, err := GetLatestCommitStatus(ctx, repoID, sha, db.ListOptionsAll)
if err != nil { if err != nil {
return err return err
} }

View File

@ -26,7 +26,7 @@ func TestGetCommitStatuses(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
sha1 := "1234123412341234123412341234123412341234" sha1 := "1234123412341234123412341234123412341234" // the mocked commit ID in test fixtures
statuses, maxResults, err := db.FindAndCount[git_model.CommitStatus](db.DefaultContext, &git_model.CommitStatusOptions{ statuses, maxResults, err := db.FindAndCount[git_model.CommitStatus](db.DefaultContext, &git_model.CommitStatusOptions{
ListOptions: db.ListOptions{Page: 1, PageSize: 50}, ListOptions: db.ListOptions{Page: 1, PageSize: 50},
@ -256,3 +256,26 @@ func TestCommitStatusesHideActionsURL(t *testing.T) {
assert.Empty(t, statuses[0].TargetURL) assert.Empty(t, statuses[0].TargetURL)
assert.Equal(t, "https://mycicd.org/1", statuses[1].TargetURL) assert.Equal(t, "https://mycicd.org/1", statuses[1].TargetURL)
} }
func TestGetCountLatestCommitStatus(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
sha1 := "1234123412341234123412341234123412341234" // the mocked commit ID in test fixtures
commitStatuses, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo1.ID, sha1, db.ListOptions{
Page: 1,
PageSize: 2,
})
assert.NoError(t, err)
assert.Len(t, commitStatuses, 2)
assert.Equal(t, structs.CommitStatusFailure, commitStatuses[0].State)
assert.Equal(t, "ci/awesomeness", commitStatuses[0].Context)
assert.Equal(t, structs.CommitStatusError, commitStatuses[1].State)
assert.Equal(t, "deploy/awesomeness", commitStatuses[1].Context)
count, err := git_model.CountLatestCommitStatus(db.DefaultContext, repo1.ID, sha1)
assert.NoError(t, err)
assert.EqualValues(t, 3, count)
}

View File

@ -88,6 +88,8 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
sess.Asc("issue.created_unix").Asc("issue.id") sess.Asc("issue.created_unix").Asc("issue.id")
case "recentupdate": case "recentupdate":
sess.Desc("issue.updated_unix").Desc("issue.created_unix").Desc("issue.id") sess.Desc("issue.updated_unix").Desc("issue.created_unix").Desc("issue.id")
case "recentclose":
sess.Desc("issue.closed_unix").Desc("issue.created_unix").Desc("issue.id")
case "leastupdate": case "leastupdate":
sess.Asc("issue.updated_unix").Asc("issue.created_unix").Asc("issue.id") sess.Asc("issue.updated_unix").Asc("issue.created_unix").Asc("issue.id")
case "mostcomment": case "mostcomment":

View File

@ -152,7 +152,8 @@ func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptio
applySorts(findSession, opts.SortType, 0) applySorts(findSession, opts.SortType, 0)
findSession = db.SetSessionPagination(findSession, opts) findSession = db.SetSessionPagination(findSession, opts)
prs := make([]*PullRequest, 0, opts.PageSize) prs := make([]*PullRequest, 0, opts.PageSize)
return prs, maxResults, findSession.Find(&prs) found := findSession.Find(&prs)
return prs, maxResults, found
} }
// PullRequestList defines a list of pull requests // PullRequestList defines a list of pull requests

View File

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestPullRequest_LoadAttributes(t *testing.T) { func TestPullRequest_LoadAttributes(t *testing.T) {
@ -76,6 +77,47 @@ func TestPullRequestsNewest(t *testing.T) {
} }
} }
func TestPullRequests_Closed_RecentSortType(t *testing.T) {
// Issue ID | Closed At. | Updated At
// 2 | 1707270001 | 1707270001
// 3 | 1707271000 | 1707279999
// 11 | 1707279999 | 1707275555
tests := []struct {
sortType string
expectedIssueIDOrder []int64
}{
{"recentupdate", []int64{3, 11, 2}},
{"recentclose", []int64{11, 3, 2}},
}
assert.NoError(t, unittest.PrepareTestDatabase())
_, err := db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707270001, updated_unix = 1707270001, is_closed = true WHERE id = 2")
require.NoError(t, err)
_, err = db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707271000, updated_unix = 1707279999, is_closed = true WHERE id = 3")
require.NoError(t, err)
_, err = db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707279999, updated_unix = 1707275555, is_closed = true WHERE id = 11")
require.NoError(t, err)
for _, test := range tests {
t.Run(test.sortType, func(t *testing.T) {
prs, _, err := issues_model.PullRequests(db.DefaultContext, 1, &issues_model.PullRequestsOptions{
ListOptions: db.ListOptions{
Page: 1,
},
State: "closed",
SortType: test.sortType,
})
require.NoError(t, err)
if assert.Len(t, prs, len(test.expectedIssueIDOrder)) {
for i := range test.expectedIssueIDOrder {
assert.Equal(t, test.expectedIssueIDOrder[i], prs[i].IssueID)
}
}
})
}
}
func TestLoadRequestedReviewers(t *testing.T) { func TestLoadRequestedReviewers(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())

View File

@ -132,18 +132,22 @@ func (r *BlameReader) Close() error {
} }
// CreateBlameReader creates reader for given repository, commit and file // CreateBlameReader creates reader for given repository, commit and file
func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error) { func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, err error) {
reader, stdout, err := os.Pipe() var ignoreRevsFileName string
if err != nil { var ignoreRevsFileCleanup func()
return nil, err defer func() {
} if err != nil && ignoreRevsFileCleanup != nil {
ignoreRevsFileCleanup()
}
}()
cmd := NewCommandNoGlobals("blame", "--porcelain") cmd := NewCommandNoGlobals("blame", "--porcelain")
var ignoreRevsFileName string
var ignoreRevsFileCleanup func() // TODO: maybe it should check the returned err in a defer func to make sure the cleanup could always be executed correctly
if DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore { if DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore {
ignoreRevsFileName, ignoreRevsFileCleanup = tryCreateBlameIgnoreRevsFile(commit) ignoreRevsFileName, ignoreRevsFileCleanup, err = tryCreateBlameIgnoreRevsFile(commit)
if err != nil && !IsErrNotExist(err) {
return nil, err
}
if ignoreRevsFileName != "" { if ignoreRevsFileName != "" {
// Possible improvement: use --ignore-revs-file /dev/stdin on unix // Possible improvement: use --ignore-revs-file /dev/stdin on unix
// There is no equivalent on Windows. May be implemented if Gitea uses an external git backend. // There is no equivalent on Windows. May be implemented if Gitea uses an external git backend.
@ -154,6 +158,10 @@ func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath
cmd.AddDynamicArguments(commit.ID.String()).AddDashesAndList(file) cmd.AddDynamicArguments(commit.ID.String()).AddDashesAndList(file)
done := make(chan error, 1) done := make(chan error, 1)
reader, stdout, err := os.Pipe()
if err != nil {
return nil, err
}
go func() { go func() {
stderr := bytes.Buffer{} stderr := bytes.Buffer{}
// TODO: it doesn't work for directories (the directories shouldn't be "blamed"), and the "err" should be returned by "Read" but not by "Close" // TODO: it doesn't work for directories (the directories shouldn't be "blamed"), and the "err" should be returned by "Read" but not by "Close"
@ -182,33 +190,29 @@ func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath
}, nil }, nil
} }
func tryCreateBlameIgnoreRevsFile(commit *Commit) (string, func()) { func tryCreateBlameIgnoreRevsFile(commit *Commit) (string, func(), error) {
entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs") entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs")
if err != nil { if err != nil {
log.Error("Unable to get .git-blame-ignore-revs file: GetTreeEntryByPath: %v", err) return "", nil, err
return "", nil
} }
r, err := entry.Blob().DataAsync() r, err := entry.Blob().DataAsync()
if err != nil { if err != nil {
log.Error("Unable to get .git-blame-ignore-revs file data: DataAsync: %v", err) return "", nil, err
return "", nil
} }
defer r.Close() defer r.Close()
f, cleanup, err := setting.AppDataTempDir("git-repo-content").CreateTempFileRandom("git-blame-ignore-revs") f, cleanup, err := setting.AppDataTempDir("git-repo-content").CreateTempFileRandom("git-blame-ignore-revs")
if err != nil { if err != nil {
log.Error("Unable to get .git-blame-ignore-revs file data: CreateTempFileRandom: %v", err) return "", nil, err
return "", nil
} }
filename := f.Name() filename := f.Name()
_, err = io.Copy(f, r) _, err = io.Copy(f, r)
_ = f.Close() _ = f.Close()
if err != nil { if err != nil {
cleanup() cleanup()
log.Error("Unable to get .git-blame-ignore-revs file data: Copy: %v", err) return "", nil, err
return "", nil
} }
return filename, cleanup return filename, cleanup, nil
} }

View File

@ -1190,7 +1190,7 @@ issues.context.edit=Modifica
issues.context.delete=Elimina issues.context.delete=Elimina
issues.reopen_issue=Riapri issues.reopen_issue=Riapri
issues.create_comment=Commento issues.create_comment=Commento
issues.closed_at=`chiuso questo probleam <a id="%[1]s" href="#%[1]s">%[2]s</a>` issues.closed_at=`ha chiuso questo problema <a id="%[1]s" href="#%[1]s">%[2]s</a>`
issues.reopened_at=`riaperto questo problema <a id="%[1]s" href="#%[1]s">%[2]s</a>` issues.reopened_at=`riaperto questo problema <a id="%[1]s" href="#%[1]s">%[2]s</a>`
issues.commit_ref_at=`ha fatto riferimento a questa issue dal commit <a id="%[1]s" href="#%[1]s">%[2]s</a>` issues.commit_ref_at=`ha fatto riferimento a questa issue dal commit <a id="%[1]s" href="#%[1]s">%[2]s</a>`
issues.ref_issue_from=`<a href="%[3]s">ha fatto riferimento a questo problema %[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>` issues.ref_issue_from=`<a href="%[3]s">ha fatto riferimento a questo problema %[4]s</a> <a id="%[1]s" href="#%[1]s">%[2]s</a>`

View File

@ -384,13 +384,13 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption" // "$ref": "#/definitions/CreateVariableOption"
// responses: // responses:
// "201": // "201":
// description: response when creating an org-level variable // description: successfully created the org-level variable
// "204":
// description: response when creating an org-level variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -419,7 +419,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update an org-level variable // UpdateVariable update an org-level variable

View File

@ -339,12 +339,12 @@ func (Action) CreateVariable(ctx *context.APIContext) {
// responses: // responses:
// "201": // "201":
// description: response when creating a repo-level variable // description: response when creating a repo-level variable
// "204":
// description: response when creating a repo-level variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
// "500":
// "$ref": "#/responses/error"
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update a repo-level variable // UpdateVariable update a repo-level variable

View File

@ -73,7 +73,7 @@ func ListPullRequests(ctx *context.APIContext) {
// in: query // in: query
// description: Type of sort // description: Type of sort
// type: string // type: string
// enum: [oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority] // enum: [oldest, recentupdate, recentclose, leastupdate, mostcomment, leastcomment, priority]
// - name: milestone // - name: milestone
// in: query // in: query
// description: ID of the milestone // description: ID of the milestone

View File

@ -258,19 +258,24 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
statuses, count, err := git_model.GetLatestCommitStatus(ctx, repo.ID, refCommit.Commit.ID.String(), utils.GetListOptions(ctx)) statuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, refCommit.Commit.ID.String(), utils.GetListOptions(ctx))
if err != nil { if err != nil {
ctx.APIErrorInternal(fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err)) ctx.APIErrorInternal(fmt.Errorf("GetLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err))
return return
} }
count, err := git_model.CountLatestCommitStatus(ctx, repo.ID, refCommit.Commit.ID.String())
if err != nil {
ctx.APIErrorInternal(fmt.Errorf("CountLatestCommitStatus[%s, %s]: %w", repo.FullName(), refCommit.CommitID, err))
return
}
ctx.SetTotalCountHeader(count)
if len(statuses) == 0 { if len(statuses) == 0 {
ctx.JSON(http.StatusOK, &api.CombinedStatus{}) ctx.JSON(http.StatusOK, &api.CombinedStatus{})
return return
} }
combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.Permission)) combiStatus := convert.ToCombinedStatus(ctx, statuses, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, combiStatus) ctx.JSON(http.StatusOK, combiStatus)
} }

View File

@ -127,13 +127,11 @@ func CreateVariable(ctx *context.APIContext) {
// "$ref": "#/definitions/CreateVariableOption" // "$ref": "#/definitions/CreateVariableOption"
// responses: // responses:
// "201": // "201":
// description: response when creating a variable // description: successfully created the user-level variable
// "204":
// description: response when creating a variable
// "400": // "400":
// "$ref": "#/responses/error" // "$ref": "#/responses/error"
// "404": // "409":
// "$ref": "#/responses/notFound" // description: variable name already exists.
opt := web.GetForm(ctx).(*api.CreateVariableOption) opt := web.GetForm(ctx).(*api.CreateVariableOption)
@ -162,7 +160,7 @@ func CreateVariable(ctx *context.APIContext) {
return return
} }
ctx.Status(http.StatusNoContent) ctx.Status(http.StatusCreated)
} }
// UpdateVariable update a user-level variable which is created by current doer // UpdateVariable update a user-level variable which is created by current doer

View File

@ -377,7 +377,7 @@ func Diff(ctx *context.Context) {
ctx.Data["FileIconPoolHTML"] = renderedIconPool.RenderToHTML() ctx.Data["FileIconPoolHTML"] = renderedIconPool.RenderToHTML()
} }
statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptionsAll) statuses, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, commitID, db.ListOptionsAll)
if err != nil { if err != nil {
log.Error("GetLatestCommitStatus: %v", err) log.Error("GetLatestCommitStatus: %v", err)
} }

View File

@ -291,7 +291,7 @@ func prepareMergedViewPullInfo(ctx *context.Context, issue *issues_model.Issue)
if len(compareInfo.Commits) != 0 { if len(compareInfo.Commits) != 0 {
sha := compareInfo.Commits[0].ID.String() sha := compareInfo.Commits[0].ID.String()
commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptionsAll) commitStatuses, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, sha, db.ListOptionsAll)
if err != nil { if err != nil {
ctx.ServerError("GetLatestCommitStatus", err) ctx.ServerError("GetLatestCommitStatus", err)
return nil return nil
@ -358,7 +358,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err) ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
return nil return nil
} }
commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll) commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll)
if err != nil { if err != nil {
ctx.ServerError("GetLatestCommitStatus", err) ctx.ServerError("GetLatestCommitStatus", err)
return nil return nil
@ -454,7 +454,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
return nil return nil
} }
commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll) commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll)
if err != nil { if err != nil {
ctx.ServerError("GetLatestCommitStatus", err) ctx.ServerError("GetLatestCommitStatus", err)
return nil return nil

View File

@ -130,7 +130,7 @@ func getReleaseInfos(ctx *context.Context, opts *repo_model.FindReleasesOptions)
} }
if canReadActions { if canReadActions {
statuses, _, err := git_model.GetLatestCommitStatus(ctx, r.Repo.ID, r.Sha1, db.ListOptionsAll) statuses, err := git_model.GetLatestCommitStatus(ctx, r.Repo.ID, r.Sha1, db.ListOptionsAll)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -131,7 +131,7 @@ func loadLatestCommitData(ctx *context.Context, latestCommit *git.Commit) bool {
ctx.Data["LatestCommitVerification"] = verification ctx.Data["LatestCommitVerification"] = verification
ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(ctx, latestCommit) ctx.Data["LatestCommitUser"] = user_model.ValidateCommitWithEmail(ctx, latestCommit)
statuses, _, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, latestCommit.ID.String(), db.ListOptionsAll) statuses, err := git_model.GetLatestCommitStatus(ctx, ctx.Repo.Repository.ID, latestCommit.ID.String(), db.ListOptionsAll)
if err != nil { if err != nil {
log.Error("GetLatestCommitStatus: %v", err) log.Error("GetLatestCommitStatus: %v", err)
} }

View File

@ -92,7 +92,7 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er
} }
ctxname := fmt.Sprintf("%s / %s (%s)", runName, job.Name, event) ctxname := fmt.Sprintf("%s / %s (%s)", runName, job.Name, event)
state := toCommitStatus(job.Status) state := toCommitStatus(job.Status)
if statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll); err == nil { if statuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll); err == nil {
for _, v := range statuses { for _, v := range statuses {
if v.Context == ctxname { if v.Context == ctxname {
if v.State == state { if v.State == state {

View File

@ -84,7 +84,7 @@ func ParseCommitsWithStatus(ctx context.Context, oldCommits []*asymkey_model.Sig
commit := &git_model.SignCommitWithStatuses{ commit := &git_model.SignCommitWithStatuses{
SignCommit: c, SignCommit: c,
} }
statuses, _, err := git_model.GetLatestCommitStatus(ctx, repo.ID, commit.ID.String(), db.ListOptions{}) statuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, commit.ID.String(), db.ListOptionsAll)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -151,7 +151,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
return "", errors.Wrap(err, "LoadBaseRepo") return "", errors.Wrap(err, "LoadBaseRepo")
} }
commitStatuses, _, err := git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptionsAll) commitStatuses, err := git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptionsAll)
if err != nil { if err != nil {
return "", errors.Wrap(err, "GetLatestCommitStatus") return "", errors.Wrap(err, "GetLatestCommitStatus")
} }

View File

@ -1004,7 +1004,7 @@ func getAllCommitStatus(ctx context.Context, gitRepo *git.Repository, pr *issues
return nil, nil, shaErr return nil, nil, shaErr
} }
statuses, _, err = git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptionsAll) statuses, err = git_model.GetLatestCommitStatus(ctx, pr.BaseRepo.ID, sha, db.ListOptionsAll)
lastStatus = git_model.CalcCommitStatus(statuses) lastStatus = git_model.CalcCommitStatus(statuses)
return statuses, lastStatus, err return statuses, lastStatus, err
} }

View File

@ -121,7 +121,7 @@ func (graph *Graph) LoadAndProcessCommits(ctx context.Context, repository *repo_
return repo_model.IsOwnerMemberCollaborator(ctx, repository, user.ID) return repo_model.IsOwnerMemberCollaborator(ctx, repository, user.ID)
}, &keyMap) }, &keyMap)
statuses, _, err := git_model.GetLatestCommitStatus(ctx, repository.ID, c.Commit.ID.String(), db.ListOptions{}) statuses, err := git_model.GetLatestCommitStatus(ctx, repository.ID, c.Commit.ID.String(), db.ListOptionsAll)
if err != nil { if err != nil {
log.Error("GetLatestCommitStatus: %v", err) log.Error("GetLatestCommitStatus: %v", err)
} else { } else {

View File

@ -36,15 +36,23 @@
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince $run.Updated}}</div> <div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince $run.Updated}}</div>
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{$run.Duration}}</div> <div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{$run.Duration}}</div>
</div> </div>
{{if and ($.AllowDeleteWorkflowRuns) ($run.Status.IsDone)}} <div class="ui dropdown jump tw-p-2">
<button class="btn interact-bg link-action tw-p-2" {{svg "octicon-kebab-horizontal"}}
data-url="{{$run.Link}}/delete" <div class="menu flex-items-menu">
data-modal-confirm="{{ctx.Locale.Tr "actions.runs.delete.description"}}" <!-- TODO: This redundant link should be replaced by something else in future,
data-tooltip-content="{{ctx.Locale.Tr "actions.runs.delete"}}" because have not figured out how to add "View Workflow" or anything similar to GitHub.
> Related: https://github.com/go-gitea/gitea/pull/34530 -->
{{svg "octicon-trash"}} <a class="item" href="{{$run.Link}}">{{svg "octicon-play"}}{{ctx.Locale.Tr "view"}}</a>
</button> {{if and $.AllowDeleteWorkflowRuns $run.Status.IsDone}}
{{end}} <a class="item link-action"
data-url="{{$run.Link}}/delete"
data-modal-confirm="{{ctx.Locale.Tr "actions.runs.delete.description"}}"
>
{{svg "octicon-trash"}}{{ctx.Locale.Tr "actions.runs.delete"}}
</a>
{{end}}
</div>
</div>
</div> </div>
</div> </div>
{{end}} {{end}}

View File

@ -2259,16 +2259,16 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "response when creating an org-level variable" "description": "successfully created the org-level variable"
},
"204": {
"description": "response when creating an org-level variable"
}, },
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
},
"500": {
"$ref": "#/responses/error"
} }
} }
}, },
@ -5263,14 +5263,14 @@
"201": { "201": {
"description": "response when creating a repo-level variable" "description": "response when creating a repo-level variable"
}, },
"204": {
"description": "response when creating a repo-level variable"
},
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
},
"500": {
"$ref": "#/responses/error"
} }
} }
}, },
@ -12871,6 +12871,7 @@
"enum": [ "enum": [
"oldest", "oldest",
"recentupdate", "recentupdate",
"recentclose",
"leastupdate", "leastupdate",
"mostcomment", "mostcomment",
"leastcomment", "leastcomment",
@ -17863,16 +17864,13 @@
], ],
"responses": { "responses": {
"201": { "201": {
"description": "response when creating a variable" "description": "successfully created the user-level variable"
},
"204": {
"description": "response when creating a variable"
}, },
"400": { "400": {
"$ref": "#/responses/error" "$ref": "#/responses/error"
}, },
"404": { "409": {
"$ref": "#/responses/notFound" "description": "variable name already exists."
} }
} }
}, },

View File

@ -633,7 +633,7 @@ jobs:
assert.NotEmpty(t, addFileResp) assert.NotEmpty(t, addFileResp)
sha = addFileResp.Commit.SHA sha = addFileResp.Commit.SHA
assert.Eventually(t, func() bool { assert.Eventually(t, func() bool {
latestCommitStatuses, _, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo.ID, sha, db.ListOptionsAll) latestCommitStatuses, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo.ID, sha, db.ListOptionsAll)
assert.NoError(t, err) assert.NoError(t, err)
if len(latestCommitStatuses) == 0 { if len(latestCommitStatuses) == 0 {
return false return false
@ -676,7 +676,7 @@ jobs:
} }
func checkCommitStatusAndInsertFakeStatus(t *testing.T, repo *repo_model.Repository, sha string) { func checkCommitStatusAndInsertFakeStatus(t *testing.T, repo *repo_model.Repository, sha string) {
latestCommitStatuses, _, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo.ID, sha, db.ListOptionsAll) latestCommitStatuses, err := git_model.GetLatestCommitStatus(db.DefaultContext, repo.ID, sha, db.ListOptionsAll)
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, latestCommitStatuses, 1) assert.Len(t, latestCommitStatuses, 1)
assert.Equal(t, api.CommitStatusPending, latestCommitStatuses[0].State) assert.Equal(t, api.CommitStatusPending, latestCommitStatuses[0].State)

View File

@ -35,11 +35,11 @@ func TestAPIRepoVariables(t *testing.T) {
}, },
{ {
Name: "_", Name: "_",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "TEST_VAR", Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "test_var", Name: "test_var",
@ -81,7 +81,7 @@ func TestAPIRepoVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
cases := []struct { cases := []struct {
Name string Name string
@ -138,7 +138,7 @@ func TestAPIRepoVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
req = NewRequest(t, "DELETE", url).AddTokenAuth(token) req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)

View File

@ -29,11 +29,11 @@ func TestAPIUserVariables(t *testing.T) {
}, },
{ {
Name: "_", Name: "_",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "TEST_VAR", Name: "TEST_VAR",
ExpectedStatus: http.StatusNoContent, ExpectedStatus: http.StatusCreated,
}, },
{ {
Name: "test_var", Name: "test_var",
@ -75,7 +75,7 @@ func TestAPIUserVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
cases := []struct { cases := []struct {
Name string Name string
@ -132,7 +132,7 @@ func TestAPIUserVariables(t *testing.T) {
req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{ req := NewRequestWithJSON(t, "POST", url, api.CreateVariableOption{
Value: "initial_val", Value: "initial_val",
}).AddTokenAuth(token) }).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusCreated)
req = NewRequest(t, "DELETE", url).AddTokenAuth(token) req = NewRequest(t, "DELETE", url).AddTokenAuth(token)
MakeRequest(t, req, http.StatusNoContent) MakeRequest(t, req, http.StatusNoContent)