Skip to content

Commit cf52263

Browse files
committed
use link-action button
1 parent 4096abc commit cf52263

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

routers/web/repo/actions/view.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,9 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
840840

841841
func ApproveAllChecks(ctx *context_module.Context) {
842842
repo := ctx.Repo.Repository
843-
sha := ctx.FormString("sha")
844-
redirect := ctx.FormString("redirect")
843+
commitID := ctx.FormString("commit_id")
845844

846-
commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, sha, db.ListOptionsAll)
845+
commitStatuses, err := git_model.GetLatestCommitStatus(ctx, repo.ID, commitID, db.ListOptionsAll)
847846
if err != nil {
848847
ctx.ServerError("GetLatestCommitStatus", err)
849848
return
@@ -862,7 +861,7 @@ func ApproveAllChecks(ctx *context_module.Context) {
862861
}
863862

864863
if len(runIndexes) == 0 {
865-
ctx.Redirect(redirect)
864+
ctx.JSONOK()
866865
return
867866
}
868867

@@ -872,7 +871,7 @@ func ApproveAllChecks(ctx *context_module.Context) {
872871
}
873872

874873
ctx.Flash.Success(ctx.Tr("actions.approve_all_success"))
875-
ctx.Redirect(redirect)
874+
ctx.JSONOK()
876875
}
877876

878877
func DisableWorkflowFile(ctx *context_module.Context) {

routers/web/repo/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ type pullCommitStatusCheckData struct {
317317
IsContextRequired func(string) bool
318318
RequireApproval bool
319319
CanApprove bool
320-
ApproveActionLink string
320+
ApproveLink string
321321
}
322322

323323
// prepareViewPullInfo show meta information for a pull request preview page
@@ -466,7 +466,7 @@ func prepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *pull_
466466
}
467467

468468
statusCheckData := &pullCommitStatusCheckData{
469-
ApproveActionLink: fmt.Sprintf("%s/actions/approve-all-checks?sha=%s&redirect=%s", repo.Link(), sha, issue.Link()),
469+
ApproveLink: fmt.Sprintf("%s/actions/approve-all-checks?commit_id=%s", repo.Link(), sha),
470470
}
471471
ctx.Data["StatusCheckData"] = statusCheckData
472472

templates/repo/pulls/status.tmpl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* IsContextRequired: function to check whether a context is required
88
* RequireApproval: whether approval is required for workflow runs
99
* CanApprove: whether the user can approve workflow runs
10-
* ApproveActionLink: link to approve all checks
10+
* ApproveLink: link to approve all checks
1111
*/}}
1212

1313
{{if .CommitStatus}}
@@ -29,12 +29,9 @@
2929

3030
<div class="ui right">
3131
{{if and .StatusCheckData .StatusCheckData.RequireApproval .StatusCheckData.CanApprove}}
32-
<form method="post" action="{{.StatusCheckData.ApproveActionLink}}">
33-
{{ctx.RootData.CsrfTokenHtml}}
34-
<button type="submit" class="ui basic small compact button">
35-
{{ctx.Locale.Tr "repo.pulls.status_checks_approve_all"}}
36-
</button>
37-
</form>
32+
<button class="ui basic small compact button link-action" data-url="{{.StatusCheckData.ApproveLink}}">
33+
{{ctx.Locale.Tr "repo.pulls.status_checks_approve_all"}}
34+
</button>
3835
{{end}}
3936
{{if .ShowHideChecks}}
4037
<button class="commit-status-hide-checks btn interact-fg"

tests/integration/actions_approve_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,26 @@ jobs:
112112
req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d", baseRepo.OwnerName, baseRepo.Name, apiPull.Index))
113113
resp = user4Session.MakeRequest(t, req, http.StatusOK)
114114
htmlDoc := NewHTMLParser(t, resp.Body)
115-
assert.Zero(t, htmlDoc.doc.Find(".commit-status-header form").Length())
115+
assert.Zero(t, htmlDoc.doc.Find(".commit-status-header button.link-action").Length())
116116

117117
// user2 can see the approve button
118118
req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d", baseRepo.OwnerName, baseRepo.Name, apiPull.Index))
119119
resp = user2Session.MakeRequest(t, req, http.StatusOK)
120120
htmlDoc = NewHTMLParser(t, resp.Body)
121-
formAction, exist := htmlDoc.doc.Find(".commit-status-header form").Attr("action")
121+
dataURL, exist := htmlDoc.doc.Find(".commit-status-header button.link-action").Attr("data-url")
122122
assert.True(t, exist)
123123
assert.Equal(t,
124-
fmt.Sprintf("%s/actions/approve-all-checks?sha=%s&redirect=/%s/%s/pulls/%d",
125-
baseRepo.Link(), apiPull.Head.Sha, baseRepo.OwnerName, baseRepo.Name, apiPull.Index),
126-
formAction,
124+
fmt.Sprintf("%s/actions/approve-all-checks?commit_id=%s",
125+
baseRepo.Link(), apiPull.Head.Sha),
126+
dataURL,
127127
)
128128

129129
// user2 approves all runs
130-
req = NewRequestWithValues(t, "POST", formAction,
130+
req = NewRequestWithValues(t, "POST", dataURL,
131131
map[string]string{
132132
"_csrf": GetUserCSRFToken(t, user2Session),
133133
})
134-
user2Session.MakeRequest(t, req, http.StatusSeeOther)
134+
user2Session.MakeRequest(t, req, http.StatusOK)
135135

136136
// check runs
137137
run1 = unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: run1.ID})

0 commit comments

Comments
 (0)