Skip to content

Commit 4078981

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix incorrect actions ref_name (go-gitea#25358) Make backend code respond correct JSON when creating PR (go-gitea#25353) Fix loading state regression in markup content (go-gitea#25349) Batch delete issue and improve tippy opts (go-gitea#25253)
2 parents 124bf3d + bd2e322 commit 4078981

File tree

16 files changed

+141
-99
lines changed

16 files changed

+141
-99
lines changed

modules/context/base.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ func (b *Base) JSONRedirect(redirect string) {
140140
b.JSON(http.StatusOK, map[string]any{"redirect": redirect})
141141
}
142142

143+
func (b *Base) JSONOK() {
144+
b.JSON(http.StatusOK, map[string]any{"ok": true}) // this is only a dummy response, frontend seldom uses it
145+
}
146+
143147
func (b *Base) JSONError(msg string) {
144148
b.JSON(http.StatusBadRequest, map[string]any{"errorMessage": msg})
145149
}

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ show_timestamps = Show timestamps
130130
show_log_seconds = Show seconds
131131
show_full_screen = Show full screen
132132

133+
confirm_delete_selected = Confirm to delete all selected items?
134+
133135
[aria]
134136
navbar = Navigation Bar
135137
footer = Footer

routers/api/actions/runner/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func generateTaskContext(t *actions_model.ActionTask) *structpb.Struct {
119119
"head_ref": headRef, // string, The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target.
120120
"job": fmt.Sprint(t.JobID), // string, The job_id of the current job.
121121
"ref": t.Job.Run.Ref, // string, The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/<branch_name>, for pull requests it is refs/pull/<pr_number>/merge, and for tags it is refs/tags/<tag_name>. For example, refs/heads/feature-branch-1.
122-
"ref_name": refName.String(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
122+
"ref_name": refName.ShortName(), // string, The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1.
123123
"ref_protected": false, // boolean, true if branch protections are configured for the ref that triggered the workflow run.
124124
"ref_type": refName.RefType(), // string, The type of ref that triggered the workflow run. Valid values are branch or tag.
125125
"path": "", // string, Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see "Workflow commands for GitHub Actions."

routers/web/repo/issue.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,20 @@ func ListIssues(ctx *context.Context) {
27052705
ctx.JSON(http.StatusOK, convert.ToAPIIssueList(ctx, issues))
27062706
}
27072707

2708+
func BatchDeleteIssues(ctx *context.Context) {
2709+
issues := getActionIssues(ctx)
2710+
if ctx.Written() {
2711+
return
2712+
}
2713+
for _, issue := range issues {
2714+
if err := issue_service.DeleteIssue(ctx, ctx.Doer, ctx.Repo.GitRepo, issue); err != nil {
2715+
ctx.ServerError("DeleteIssue", err)
2716+
return
2717+
}
2718+
}
2719+
ctx.JSONOK()
2720+
}
2721+
27082722
// UpdateIssueStatus change issue's status
27092723
func UpdateIssueStatus(ctx *context.Context) {
27102724
issues := getActionIssues(ctx)
@@ -2740,9 +2754,7 @@ func UpdateIssueStatus(ctx *context.Context) {
27402754
}
27412755
}
27422756
}
2743-
ctx.JSON(http.StatusOK, map[string]interface{}{
2744-
"ok": true,
2745-
})
2757+
ctx.JSONOK()
27462758
}
27472759

27482760
// NewComment create a comment for issue

routers/web/repo/pull.go

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"code.gitea.io/gitea/modules/upload"
3838
"code.gitea.io/gitea/modules/util"
3939
"code.gitea.io/gitea/modules/web"
40-
"code.gitea.io/gitea/modules/web/middleware"
4140
"code.gitea.io/gitea/routers/utils"
4241
asymkey_service "code.gitea.io/gitea/services/asymkey"
4342
"code.gitea.io/gitea/services/automerge"
@@ -1206,36 +1205,12 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12061205
}
12071206

12081207
if ctx.HasError() {
1209-
middleware.AssignForm(form, ctx.Data)
1210-
1211-
// This stage is already stop creating new pull request, so it does not matter if it has
1212-
// something to compare or not.
1213-
PrepareCompareDiff(ctx, ci,
1214-
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
1215-
if ctx.Written() {
1216-
return
1217-
}
1218-
1219-
if len(form.Title) > 255 {
1220-
var trailer string
1221-
form.Title, trailer = util.SplitStringAtByteN(form.Title, 255)
1222-
1223-
form.Content = trailer + "\n\n" + form.Content
1224-
}
1225-
middleware.AssignForm(form, ctx.Data)
1226-
1227-
ctx.HTML(http.StatusOK, tplCompareDiff)
1208+
ctx.JSONError(ctx.GetErrMsg())
12281209
return
12291210
}
12301211

12311212
if util.IsEmptyString(form.Title) {
1232-
PrepareCompareDiff(ctx, ci,
1233-
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
1234-
if ctx.Written() {
1235-
return
1236-
}
1237-
1238-
ctx.RenderWithErr(ctx.Tr("repo.issues.new.title_empty"), tplCompareDiff, form)
1213+
ctx.JSONError(ctx.Tr("repo.issues.new.title_empty"))
12391214
return
12401215
}
12411216

@@ -1278,28 +1253,28 @@ func CompareAndPullRequestPost(ctx *context.Context) {
12781253
pushrejErr := err.(*git.ErrPushRejected)
12791254
message := pushrejErr.Message
12801255
if len(message) == 0 {
1281-
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
1282-
} else {
1283-
flashError, err := ctx.RenderToString(tplAlertDetails, map[string]interface{}{
1284-
"Message": ctx.Tr("repo.pulls.push_rejected"),
1285-
"Summary": ctx.Tr("repo.pulls.push_rejected_summary"),
1286-
"Details": utils.SanitizeFlashErrorString(pushrejErr.Message),
1287-
})
1288-
if err != nil {
1289-
ctx.ServerError("CompareAndPullRequest.HTMLString", err)
1290-
return
1291-
}
1292-
ctx.Flash.Error(flashError)
1256+
ctx.JSONError(ctx.Tr("repo.pulls.push_rejected_no_message"))
1257+
return
12931258
}
1294-
ctx.Redirect(pullIssue.Link())
1259+
flashError, err := ctx.RenderToString(tplAlertDetails, map[string]interface{}{
1260+
"Message": ctx.Tr("repo.pulls.push_rejected"),
1261+
"Summary": ctx.Tr("repo.pulls.push_rejected_summary"),
1262+
"Details": utils.SanitizeFlashErrorString(pushrejErr.Message),
1263+
})
1264+
if err != nil {
1265+
ctx.ServerError("CompareAndPullRequest.HTMLString", err)
1266+
return
1267+
}
1268+
ctx.Flash.Error(flashError)
1269+
ctx.JSONRedirect(pullIssue.Link()) // FIXME: it's unfriendly, and will make the content lost
12951270
return
12961271
}
12971272
ctx.ServerError("NewPullRequest", err)
12981273
return
12991274
}
13001275

13011276
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
1302-
ctx.Redirect(pullIssue.Link())
1277+
ctx.JSONRedirect(pullIssue.Link())
13031278
}
13041279

13051280
// CleanUpPullRequest responses for delete merged branch when PR has been merged

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ func registerRoutes(m *web.Route) {
10241024
m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest)
10251025
m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview)
10261026
m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus)
1027+
m.Post("/delete", reqRepoAdmin, repo.BatchDeleteIssues)
10271028
m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation)
10281029
m.Post("/attachments", repo.UploadIssueAttachment)
10291030
m.Post("/attachments/remove", repo.DeleteAttachment)

templates/devtest/fetch-action.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
It might be renamed to "link-fetch-action" to match the "form-fetch-action".
99
</div>
1010
<div>
11-
<button class="link-action" data-url="fetch-action-test?k=1">test</button>
11+
<button class="link-action" data-url="fetch-action-test?k=1">test action</button>
12+
<button class="link-action" data-url="fetch-action-test?k=1" data-modal-confirm="confirm?">test with confirm</button>
13+
<button class="ui red button link-action" data-url="fetch-action-test?k=1" data-modal-confirm="confirm?">test with risky confirm</button>
1214
</div>
1315
</div>
1416
<div>

templates/repo/issue/list.tmpl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,15 @@
282282
{{if not .Repository.IsArchived}}
283283
<!-- Action Button -->
284284
{{if .IsShowClosed}}
285-
<button class="ui green active basic button issue-action gt-ml-auto" data-action="open" data-url="{{$.RepoLink}}/issues/status">{{.locale.Tr "repo.issues.action_open"}}</button>
285+
<button class="ui green basic button issue-action gt-ml-auto" data-action="open" data-url="{{$.RepoLink}}/issues/status">{{.locale.Tr "repo.issues.action_open"}}</button>
286286
{{else}}
287-
<button class="ui red active basic button issue-action gt-ml-auto" data-action="close" data-url="{{$.RepoLink}}/issues/status">{{.locale.Tr "repo.issues.action_close"}}</button>
287+
<button class="ui red basic button issue-action gt-ml-auto" data-action="close" data-url="{{$.RepoLink}}/issues/status">{{.locale.Tr "repo.issues.action_close"}}</button>
288+
{{end}}
289+
{{if $.IsRepoAdmin}}
290+
<button class="ui red button issue-action gt-ml-auto"
291+
data-action="delete" data-url="{{$.RepoLink}}/issues/delete"
292+
data-action-delete-confirm="{{.locale.Tr "confirm_delete_selected"}}"
293+
>{{.locale.Tr "repo.issues.delete"}}</button>
288294
{{end}}
289295
<!-- Labels -->
290296
<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item">

tests/integration/pull_create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"testing"
1313

14+
"code.gitea.io/gitea/modules/test"
1415
"code.gitea.io/gitea/tests"
1516

1617
"github.com/stretchr/testify/assert"
@@ -39,8 +40,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl
3940
"_csrf": htmlDoc.GetCSRF(),
4041
"title": title,
4142
})
42-
resp = session.MakeRequest(t, req, http.StatusSeeOther)
43-
43+
resp = session.MakeRequest(t, req, http.StatusOK)
4444
return resp
4545
}
4646

@@ -52,7 +52,7 @@ func TestPullCreate(t *testing.T) {
5252
resp := testPullCreate(t, session, "user1", "repo1", "master", "This is a pull title")
5353

5454
// check the redirected URL
55-
url := resp.Header().Get("Location")
55+
url := test.RedirectURL(resp)
5656
assert.Regexp(t, "^/user2/repo1/pulls/[0-9]*$", url)
5757

5858
// check .diff can be accessed and matches performed change
@@ -80,7 +80,7 @@ func TestPullCreate_TitleEscape(t *testing.T) {
8080
resp := testPullCreate(t, session, "user1", "repo1", "master", "<i>XSS PR</i>")
8181

8282
// check the redirected URL
83-
url := resp.Header().Get("Location")
83+
url := test.RedirectURL(resp)
8484
assert.Regexp(t, "^/user2/repo1/pulls/[0-9]*$", url)
8585

8686
// Edit title
@@ -145,7 +145,7 @@ func TestPullBranchDelete(t *testing.T) {
145145
resp := testPullCreate(t, session, "user1", "repo1", "master1", "This is a pull title")
146146

147147
// check the redirected URL
148-
url := resp.Header().Get("Location")
148+
url := test.RedirectURL(resp)
149149
assert.Regexp(t, "^/user2/repo1/pulls/[0-9]*$", url)
150150
req := NewRequest(t, "GET", url)
151151
session.MakeRequest(t, req, http.StatusOK)

tests/integration/pull_merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func TestCantMergeWorkInProgress(t *testing.T) {
199199

200200
resp := testPullCreate(t, session, "user1", "repo1", "master", "[wip] This is a pull title")
201201

202-
req := NewRequest(t, "GET", resp.Header().Get("Location"))
202+
req := NewRequest(t, "GET", test.RedirectURL(resp))
203203
resp = session.MakeRequest(t, req, http.StatusOK)
204204
htmlDoc := NewHTMLParser(t, resp.Body)
205205
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())

tests/integration/pull_status_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestPullCreate_CommitStatus(t *testing.T) {
3030
"title": "pull request from status1",
3131
},
3232
)
33-
session.MakeRequest(t, req, http.StatusSeeOther)
33+
session.MakeRequest(t, req, http.StatusOK)
3434

3535
req = NewRequest(t, "GET", "/user1/repo1/pulls")
3636
resp := session.MakeRequest(t, req, http.StatusOK)
@@ -127,7 +127,7 @@ func TestPullCreate_EmptyChangesWithDifferentCommits(t *testing.T) {
127127
"title": "pull request from status1",
128128
},
129129
)
130-
session.MakeRequest(t, req, http.StatusSeeOther)
130+
session.MakeRequest(t, req, http.StatusOK)
131131

132132
req = NewRequest(t, "GET", "/user1/repo1/pulls/1")
133133
resp := session.MakeRequest(t, req, http.StatusOK)
@@ -150,7 +150,7 @@ func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
150150
"title": "pull request from status1",
151151
},
152152
)
153-
session.MakeRequest(t, req, http.StatusSeeOther)
153+
session.MakeRequest(t, req, http.StatusOK)
154154
req = NewRequest(t, "GET", "/user1/repo1/pulls/1")
155155
resp := session.MakeRequest(t, req, http.StatusOK)
156156
doc := NewHTMLParser(t, resp.Body)

web_src/css/modules/animations.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
position: absolute;
1919
display: block;
2020
height: 4rem;
21-
max-height: 50%;
2221
aspect-ratio: 1 / 1;
2322
left: 50%;
2423
top: 50%;
24+
max-height: 100%;
25+
max-width: 100%;
2526
transform: translate(-50%, -50%);
2627
animation: isloadingspin 500ms infinite linear;
2728
border-width: 4px;
@@ -40,6 +41,15 @@
4041
height: var(--height-loading);
4142
}
4243

44+
.markup .is-loading > * {
45+
visibility: hidden;
46+
}
47+
48+
.markup .is-loading {
49+
color: transparent;
50+
background: transparent;
51+
}
52+
4353
/* TODO: not needed, use "is-loading small-loading-icon" instead */
4454
.btn-octicon.is-loading::after {
4555
border-width: 2px;

web_src/js/features/common-global.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {svg} from '../svg.js';
88
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
99
import {htmlEscape} from 'escape-goat';
1010
import {createTippy} from '../modules/tippy.js';
11+
import {confirmModal} from './comp/ConfirmModal.js';
1112

1213
const {appUrl, appSubUrl, csrfToken, i18n} = window.config;
1314

@@ -264,7 +265,7 @@ export function initGlobalDropzone() {
264265
}
265266
}
266267

267-
function linkAction(e) {
268+
async function linkAction(e) {
268269
e.preventDefault();
269270

270271
// A "link-action" can post AJAX request to its "data-url"
@@ -291,33 +292,16 @@ function linkAction(e) {
291292
});
292293
};
293294

294-
const modalConfirmHtml = htmlEscape($this.attr('data-modal-confirm') || '');
295-
if (!modalConfirmHtml) {
295+
const modalConfirmContent = htmlEscape($this.attr('data-modal-confirm') || '');
296+
if (!modalConfirmContent) {
296297
doRequest();
297298
return;
298299
}
299300

300-
const okButtonColor = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative') ? 'orange' : 'green';
301-
302-
const $modal = $(`
303-
<div class="ui g-modal-confirm modal">
304-
<div class="content">${modalConfirmHtml}</div>
305-
<div class="actions">
306-
<button class="ui basic cancel button">${svg('octicon-x')} ${i18n.modal_cancel}</button>
307-
<button class="ui ${okButtonColor} ok button">${svg('octicon-check')} ${i18n.modal_confirm}</button>
308-
</div>
309-
</div>
310-
`);
311-
312-
$modal.appendTo(document.body);
313-
$modal.modal({
314-
onApprove() {
315-
doRequest();
316-
},
317-
onHidden() {
318-
$modal.remove();
319-
},
320-
}).modal('show');
301+
const isRisky = $this.hasClass('red') || $this.hasClass('yellow') || $this.hasClass('orange') || $this.hasClass('negative');
302+
if (await confirmModal({content: modalConfirmContent, buttonColor: isRisky ? 'orange' : 'green'})) {
303+
doRequest();
304+
}
321305
}
322306

323307
export function initGlobalLinkActions() {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import $ from 'jquery';
2+
import {svg} from '../../svg.js';
3+
import {htmlEscape} from 'escape-goat';
4+
5+
const {i18n} = window.config;
6+
7+
export async function confirmModal(opts = {content: '', buttonColor: 'green'}) {
8+
return new Promise((resolve) => {
9+
const $modal = $(`
10+
<div class="ui g-modal-confirm modal">
11+
<div class="content">${htmlEscape(opts.content)}</div>
12+
<div class="actions">
13+
<button class="ui basic cancel button">${svg('octicon-x')} ${i18n.modal_cancel}</button>
14+
<button class="ui ${opts.buttonColor || 'green'} ok button">${svg('octicon-check')} ${i18n.modal_confirm}</button>
15+
</div>
16+
</div>
17+
`);
18+
19+
$modal.appendTo(document.body);
20+
$modal.modal({
21+
onApprove() {
22+
resolve(true);
23+
},
24+
onHidden() {
25+
$modal.remove();
26+
resolve(false);
27+
},
28+
}).modal('show');
29+
});
30+
}

0 commit comments

Comments
 (0)