Skip to content

Commit 93e9733

Browse files
authored
Merge branch 'main' into lunny/split_get_last_commit_statuses
2 parents bc16df1 + ab96912 commit 93e9733

File tree

13 files changed

+125
-72
lines changed

13 files changed

+125
-72
lines changed

models/issues/issue_search.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
8888
sess.Asc("issue.created_unix").Asc("issue.id")
8989
case "recentupdate":
9090
sess.Desc("issue.updated_unix").Desc("issue.created_unix").Desc("issue.id")
91+
case "recentclose":
92+
sess.Desc("issue.closed_unix").Desc("issue.created_unix").Desc("issue.id")
9193
case "leastupdate":
9294
sess.Asc("issue.updated_unix").Asc("issue.created_unix").Asc("issue.id")
9395
case "mostcomment":

models/issues/pull_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptio
152152
applySorts(findSession, opts.SortType, 0)
153153
findSession = db.SetSessionPagination(findSession, opts)
154154
prs := make([]*PullRequest, 0, opts.PageSize)
155-
return prs, maxResults, findSession.Find(&prs)
155+
found := findSession.Find(&prs)
156+
return prs, maxResults, found
156157
}
157158

158159
// PullRequestList defines a list of pull requests

models/issues/pull_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/setting"
1515

1616
"github.com/stretchr/testify/assert"
17+
"github.com/stretchr/testify/require"
1718
)
1819

1920
func TestPullRequest_LoadAttributes(t *testing.T) {
@@ -76,6 +77,47 @@ func TestPullRequestsNewest(t *testing.T) {
7677
}
7778
}
7879

80+
func TestPullRequests_Closed_RecentSortType(t *testing.T) {
81+
// Issue ID | Closed At. | Updated At
82+
// 2 | 1707270001 | 1707270001
83+
// 3 | 1707271000 | 1707279999
84+
// 11 | 1707279999 | 1707275555
85+
tests := []struct {
86+
sortType string
87+
expectedIssueIDOrder []int64
88+
}{
89+
{"recentupdate", []int64{3, 11, 2}},
90+
{"recentclose", []int64{11, 3, 2}},
91+
}
92+
93+
assert.NoError(t, unittest.PrepareTestDatabase())
94+
_, err := db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707270001, updated_unix = 1707270001, is_closed = true WHERE id = 2")
95+
require.NoError(t, err)
96+
_, err = db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707271000, updated_unix = 1707279999, is_closed = true WHERE id = 3")
97+
require.NoError(t, err)
98+
_, err = db.Exec(db.DefaultContext, "UPDATE issue SET closed_unix = 1707279999, updated_unix = 1707275555, is_closed = true WHERE id = 11")
99+
require.NoError(t, err)
100+
101+
for _, test := range tests {
102+
t.Run(test.sortType, func(t *testing.T) {
103+
prs, _, err := issues_model.PullRequests(db.DefaultContext, 1, &issues_model.PullRequestsOptions{
104+
ListOptions: db.ListOptions{
105+
Page: 1,
106+
},
107+
State: "closed",
108+
SortType: test.sortType,
109+
})
110+
require.NoError(t, err)
111+
112+
if assert.Len(t, prs, len(test.expectedIssueIDOrder)) {
113+
for i := range test.expectedIssueIDOrder {
114+
assert.Equal(t, test.expectedIssueIDOrder[i], prs[i].IssueID)
115+
}
116+
}
117+
})
118+
}
119+
}
120+
79121
func TestLoadRequestedReviewers(t *testing.T) {
80122
assert.NoError(t, unittest.PrepareTestDatabase())
81123

modules/git/blame.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,22 @@ func (r *BlameReader) Close() error {
132132
}
133133

134134
// CreateBlameReader creates reader for given repository, commit and file
135-
func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (*BlameReader, error) {
136-
reader, stdout, err := os.Pipe()
137-
if err != nil {
138-
return nil, err
139-
}
135+
func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath string, commit *Commit, file string, bypassBlameIgnore bool) (rd *BlameReader, err error) {
136+
var ignoreRevsFileName string
137+
var ignoreRevsFileCleanup func()
138+
defer func() {
139+
if err != nil && ignoreRevsFileCleanup != nil {
140+
ignoreRevsFileCleanup()
141+
}
142+
}()
140143

141144
cmd := NewCommandNoGlobals("blame", "--porcelain")
142145

143-
var ignoreRevsFileName string
144-
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
145146
if DefaultFeatures().CheckVersionAtLeast("2.23") && !bypassBlameIgnore {
146-
ignoreRevsFileName, ignoreRevsFileCleanup = tryCreateBlameIgnoreRevsFile(commit)
147+
ignoreRevsFileName, ignoreRevsFileCleanup, err = tryCreateBlameIgnoreRevsFile(commit)
148+
if err != nil && !IsErrNotExist(err) {
149+
return nil, err
150+
}
147151
if ignoreRevsFileName != "" {
148152
// Possible improvement: use --ignore-revs-file /dev/stdin on unix
149153
// 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
154158
cmd.AddDynamicArguments(commit.ID.String()).AddDashesAndList(file)
155159

156160
done := make(chan error, 1)
161+
reader, stdout, err := os.Pipe()
162+
if err != nil {
163+
return nil, err
164+
}
157165
go func() {
158166
stderr := bytes.Buffer{}
159167
// 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
182190
}, nil
183191
}
184192

185-
func tryCreateBlameIgnoreRevsFile(commit *Commit) (string, func()) {
193+
func tryCreateBlameIgnoreRevsFile(commit *Commit) (string, func(), error) {
186194
entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs")
187195
if err != nil {
188-
log.Error("Unable to get .git-blame-ignore-revs file: GetTreeEntryByPath: %v", err)
189-
return "", nil
196+
return "", nil, err
190197
}
191198

192199
r, err := entry.Blob().DataAsync()
193200
if err != nil {
194-
log.Error("Unable to get .git-blame-ignore-revs file data: DataAsync: %v", err)
195-
return "", nil
201+
return "", nil, err
196202
}
197203
defer r.Close()
198204

199205
f, cleanup, err := setting.AppDataTempDir("git-repo-content").CreateTempFileRandom("git-blame-ignore-revs")
200206
if err != nil {
201-
log.Error("Unable to get .git-blame-ignore-revs file data: CreateTempFileRandom: %v", err)
202-
return "", nil
207+
return "", nil, err
203208
}
204209
filename := f.Name()
205210
_, err = io.Copy(f, r)
206211
_ = f.Close()
207212
if err != nil {
208213
cleanup()
209-
log.Error("Unable to get .git-blame-ignore-revs file data: Copy: %v", err)
210-
return "", nil
214+
return "", nil, err
211215
}
212216

213-
return filename, cleanup
217+
return filename, cleanup, nil
214218
}

options/locale/locale_it-IT.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ issues.context.edit=Modifica
11901190
issues.context.delete=Elimina
11911191
issues.reopen_issue=Riapri
11921192
issues.create_comment=Commento
1193-
issues.closed_at=`chiuso questo probleam <a id="%[1]s" href="#%[1]s">%[2]s</a>`
1193+
issues.closed_at=`ha chiuso questo problema <a id="%[1]s" href="#%[1]s">%[2]s</a>`
11941194
issues.reopened_at=`riaperto questo problema <a id="%[1]s" href="#%[1]s">%[2]s</a>`
11951195
issues.commit_ref_at=`ha fatto riferimento a questa issue dal commit <a id="%[1]s" href="#%[1]s">%[2]s</a>`
11961196
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>`

routers/api/v1/org/action.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,13 @@ func (Action) CreateVariable(ctx *context.APIContext) {
384384
// "$ref": "#/definitions/CreateVariableOption"
385385
// responses:
386386
// "201":
387-
// description: response when creating an org-level variable
388-
// "204":
389-
// description: response when creating an org-level variable
387+
// description: successfully created the org-level variable
390388
// "400":
391389
// "$ref": "#/responses/error"
392-
// "404":
393-
// "$ref": "#/responses/notFound"
390+
// "409":
391+
// description: variable name already exists.
392+
// "500":
393+
// "$ref": "#/responses/error"
394394

395395
opt := web.GetForm(ctx).(*api.CreateVariableOption)
396396

@@ -419,7 +419,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
419419
return
420420
}
421421

422-
ctx.Status(http.StatusNoContent)
422+
ctx.Status(http.StatusCreated)
423423
}
424424

425425
// UpdateVariable update an org-level variable

routers/api/v1/repo/action.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ func (Action) CreateVariable(ctx *context.APIContext) {
339339
// responses:
340340
// "201":
341341
// description: response when creating a repo-level variable
342-
// "204":
343-
// description: response when creating a repo-level variable
344342
// "400":
345343
// "$ref": "#/responses/error"
346-
// "404":
347-
// "$ref": "#/responses/notFound"
344+
// "409":
345+
// description: variable name already exists.
346+
// "500":
347+
// "$ref": "#/responses/error"
348348

349349
opt := web.GetForm(ctx).(*api.CreateVariableOption)
350350

@@ -373,7 +373,7 @@ func (Action) CreateVariable(ctx *context.APIContext) {
373373
return
374374
}
375375

376-
ctx.Status(http.StatusNoContent)
376+
ctx.Status(http.StatusCreated)
377377
}
378378

379379
// UpdateVariable update a repo-level variable

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func ListPullRequests(ctx *context.APIContext) {
7373
// in: query
7474
// description: Type of sort
7575
// type: string
76-
// enum: [oldest, recentupdate, leastupdate, mostcomment, leastcomment, priority]
76+
// enum: [oldest, recentupdate, recentclose, leastupdate, mostcomment, leastcomment, priority]
7777
// - name: milestone
7878
// in: query
7979
// description: ID of the milestone

routers/api/v1/user/action.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ func CreateVariable(ctx *context.APIContext) {
127127
// "$ref": "#/definitions/CreateVariableOption"
128128
// responses:
129129
// "201":
130-
// description: response when creating a variable
131-
// "204":
132-
// description: response when creating a variable
130+
// description: successfully created the user-level variable
133131
// "400":
134132
// "$ref": "#/responses/error"
135-
// "404":
136-
// "$ref": "#/responses/notFound"
133+
// "409":
134+
// description: variable name already exists.
137135

138136
opt := web.GetForm(ctx).(*api.CreateVariableOption)
139137

@@ -162,7 +160,7 @@ func CreateVariable(ctx *context.APIContext) {
162160
return
163161
}
164162

165-
ctx.Status(http.StatusNoContent)
163+
ctx.Status(http.StatusCreated)
166164
}
167165

168166
// UpdateVariable update a user-level variable which is created by current doer

templates/repo/actions/runs_list.tmpl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,23 @@
3636
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince $run.Updated}}</div>
3737
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{$run.Duration}}</div>
3838
</div>
39-
{{if and ($.AllowDeleteWorkflowRuns) ($run.Status.IsDone)}}
40-
<button class="btn interact-bg link-action tw-p-2"
41-
data-url="{{$run.Link}}/delete"
42-
data-modal-confirm="{{ctx.Locale.Tr "actions.runs.delete.description"}}"
43-
data-tooltip-content="{{ctx.Locale.Tr "actions.runs.delete"}}"
44-
>
45-
{{svg "octicon-trash"}}
46-
</button>
47-
{{end}}
39+
<div class="ui dropdown jump tw-p-2">
40+
{{svg "octicon-kebab-horizontal"}}
41+
<div class="menu flex-items-menu">
42+
<!-- TODO: This redundant link should be replaced by something else in future,
43+
because have not figured out how to add "View Workflow" or anything similar to GitHub.
44+
Related: https://github.com/go-gitea/gitea/pull/34530 -->
45+
<a class="item" href="{{$run.Link}}">{{svg "octicon-play"}}{{ctx.Locale.Tr "view"}}</a>
46+
{{if and $.AllowDeleteWorkflowRuns $run.Status.IsDone}}
47+
<a class="item link-action"
48+
data-url="{{$run.Link}}/delete"
49+
data-modal-confirm="{{ctx.Locale.Tr "actions.runs.delete.description"}}"
50+
>
51+
{{svg "octicon-trash"}}{{ctx.Locale.Tr "actions.runs.delete"}}
52+
</a>
53+
{{end}}
54+
</div>
55+
</div>
4856
</div>
4957
</div>
5058
{{end}}

0 commit comments

Comments
 (0)