8000 fix test and add ui · go-gitea/gitea@7062121 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7062121

Browse files
committed
fix test and add ui
1 parent 1c00cc3 commit 7062121

File tree

13 files changed

+201
-110
lines changed

13 files changed

+201
-110
lines changed

routers/web/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const (
4343
tplIssueChoose templates.TplName = "repo/issue/choose"
4444
tplIssueView templates.TplName = "repo/issue/view"
4545

46-
tplReactions templates.TplName = "repo/issue/view_content/reactions"
46+
tplPullMergeBox templates.TplName = "repo/issue/view_content/pull_merge_box"
47+
tplReactions templates.TplName = "repo/issue/view_content/reactions"
4748

4849
issueTemplateKey = "IssueTemplate"
4950
issueTemplateTitleKey = "IssueTemplateTitle"

routers/web/repo/issue_view.go

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"code.gitea.io/gitea/modules/setting"
3232
"code.gitea.io/gitea/modules/templates"
3333
"code.gitea.io/gitea/modules/templates/vars"
34+
"code.gitea.io/gitea/modules/util"
3435
asymkey_service "code.gitea.io/gitea/services/asymkey"
3536
"code.gitea.io/gitea/services/context"
3637
"code.gitea.io/gitea/services/context/upload"
@@ -271,8 +272,23 @@ func combineLabelComments(issue *issues_model.Issue) {
271272
}
272273
}
273274

274-
// ViewIssue render issue view page
275-
func ViewIssue(ctx *context.Context) {
275+
func prepareIssueViewLoad(ctx *context.Context) *issues_model.Issue {
276+
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
277+
if err != nil {
278+
ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err)
279+
return nil
280+
}
281+
issue.Repo = ctx.Repo.Repository
282+
ctx.Data["Issue"] = issue
283+
284+
if err = issue.LoadPullRequest(ctx); err != nil {
285+
ctx.ServerError("LoadPullRequest", err)
286+
return nil
287+
}
288+
return issue
289+
}
290+
291+
func handleViewIssueRedirectExternal(ctx *context.Context) {
276292
if ctx.PathParam("type") == "issues" {
277293
// If issue was requested we check if repo has external tracker and redirect
278294
extIssueUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit.TypeExternalTracker)
@@ -294,18 +310,18 @@ func ViewIssue(ctx *context.Context) {
294310
return
295311
}
296312
}
313+
}
297314

298-
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("index"))
299-
if err != nil {
300-
if issues_model.IsErrIssueNotExist(err) {
301-
ctx.NotFound(err)
302-
} else {
303-
ctx.ServerError("GetIssueByIndex", err)
304-
}
315+
// ViewIssue render issue view page
316+
func ViewIssue(ctx *context.Context) {
317+
handleViewIssueRedirectExternal(ctx)
318+
if ctx.Written() {
305319
return
306320
}
307-
if issue.Repo == nil {
308-
issue.Repo = ctx.Repo.Repository
321+
322+
issue := prepareIssueViewLoad(ctx)
323+
if ctx.Written() {
324+
return
309325
}
310326

311327
// Make sure type and URL matches.
@@ -337,12 +353,12 @@ func ViewIssue(ctx *context.Context) {
337353
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
338354
upload.AddUploadContext(ctx, "comment")
339355

340-
if err = issue.LoadAttributes(ctx); err != nil {
356+
if err := issue.LoadAttributes(ctx); err != nil {
341357
ctx.ServerError("LoadAttributes", err)
342358
return
343359
}
344360

345-
if err = filterXRefComments(ctx, issue); err != nil {
361+
if err := filterXRefComments(ctx, issue); err != nil {
346362
ctx.ServerError("filterXRefComments", err)
347363
return
348364
}
@@ -351,7 +367,7 @@ func ViewIssue(ctx *context.Context) {
351367

352368
if ctx.IsSigned {
353369
// Update issue-user.
354 93D4 -
if err = activities_model.SetIssueReadBy(ctx, issue.ID, ctx.Doer.ID); err != nil {
370+
if err := activities_model.SetIssueReadBy(ctx, issue.ID, ctx.Doer.ID); err != nil {
355371
ctx.ServerError("ReadBy", err)
356372
return
357373
}
@@ -365,15 +381,13 @@ func ViewIssue(ctx *context.Context) {
365381

366382
prepareFuncs := []func(*context.Context, *issues_model.Issue){
367383
prepareIssueViewContent,
368-
func(ctx *context.Context, issue *issues_model.Issue) {
369-
preparePullViewPullInfo(ctx, issue)
370-
},
371384
prepareIssueViewCommentsAndSidebarParticipants,
372-
preparePullViewReviewAndMerge,
373385
prepareIssueViewSidebarWatch,
374386
prepareIssueViewSidebarTimeTracker,
375387
prepareIssueViewSidebarDependency,
376388
prepareIssueViewSidebarPin,
389+
func(ctx *context.Context, issue *issues_model.Issue) { preparePullViewPullInfo(ctx, issue) },
390+
preparePullViewReviewAndMerge,
377391
}
378392

379393
for _, prepareFunc := range prepareFuncs {
@@ -412,9 +426,25 @@ func ViewIssue(ctx *context.Context) {
412426
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
413427
}
414428

429+
if !issue.PullRequest.IsChecking() && !setting.IsProd {
430+
ctx.Data["PullMergeBoxReloadingInterval"] = 1 // in dev env, force using the reloading logic to make sure it won't break
431+
}
432+
415433
ctx.HTML(http.StatusOK, tplIssueView)
416434
}
417435

436+
func ViewPullMergeBox(ctx *context.Context) {
437+
issue := prepareIssueViewLoad(ctx)
438+
if !issue.IsPull {
439+
ctx.NotFound(nil)
440+
return
441+
}
442+
preparePullViewPullInfo(ctx, issue)
443+
preparePullViewReviewAndMerge(ctx, issue)
444+
ctx.Data["PullMergeBoxReloading"] = issue.PullRequest.IsChecking()
445+
ctx.HTML(http.StatusOK, tplPullMergeBox)
446+
}
447+
418448
func prepareIssueViewSidebarDependency(ctx *context.Context, issue *issues_model.Issue) {
419449
if issue.IsPull && !ctx.Repo.CanRead(unit.TypeIssues) {
420450
ctx.Data["IssueDependencySearchType"] = "pulls"
@@ -840,6 +870,7 @@ func preparePullViewReviewAndMerge(ctx *context.Context, issue *issues_model.Iss
840870
}
841871
}
842872

873+
ctx.Data["PullMergeBoxReloadingInterval"] = util.Iif(issue.PullRequest.IsChecking(), 2000, 0)
843874
ctx.Data["CanWriteToHeadRepo"] = canWriteToHeadRepo
844875
ctx.Data["ShowMergeInstructions"] = canWriteToHeadRepo
845876
ctx.Data["AllowMerge"] = allowMerge

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ func registerWebRoutes(m *web.Router) {
15051505
m.Get("", repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewIssue)
15061506
m.Get(".diff", repo.DownloadPullDiff)
15071507
m.Get(".patch", repo.DownloadPullPatch)
1508+
m.Get("/merge_box", repo.ViewPullMergeBox)
15081509
m.Group("/commits", func() {
15091510
m.Get("", repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits)
15101511
m.Get("/list", repo.GetPullCommits)

services/pull/check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
3636
assert.NoError(t, err)
3737

3838
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
39-
AddToTaskQueue(db.DefaultContext, pr)
39+
StartPullRequestCheckImmediately(db.DefaultContext, pr)
4040

4141
assert.Eventually(t, func() bool {
4242
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})

templates/repo/issue/view_content.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{{template "repo/issue/view_content/comments" .}}
6969

7070
{{if and .Issue.IsPull (not $.Repository.IsArchived)}}
71-
{{template "repo/issue/view_content/pull".}}
71+
{{template "repo/issue/view_content/pull_merge_box".}}
7272
{{end}}
7373

7474
{{if .IsSigned}}

templates/repo/issue/view_content/pull.tmpl renamed to templates/repo/issue/view_content/pull_merge_box.tmpl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{{if and .Issue.PullRequest.HasMerged (not .IsPullBranchDeletable)}}
22
{{/* Then the merge box will not be displayed because this page already contains enough information */}}
33
{{else}}
4-
<div class="timeline-item comment merge box">
4+
<div class="timeline-item comment pull-merge-box"
5+
data-global-init="initRepoPullMergeBox"
6+
{{if .PullMergeBoxReloadingInterval}}
7+
data-pull-merge-box-reloading-interval="{{.PullMergeBoxReloadingInterval}}"
8+
data-pull-link="{{.Issue.Link}}"
9+
{{end}}
10+
>
511
<div class="timeline-avatar text {{if .Issue.PullRequest.HasMerged}}purple
612
{{- else if .Issue.IsClosed}}grey
713
{{- else if .IsPullWorkInProgress}}grey
@@ -217,7 +223,7 @@
217223
const defaultMergeMessage = {{.DefaultMergeBody}};
218224
const defaultSquashMergeMessage = {{.DefaultSquashMergeBody}};
219225
const mergeForm = {
220-
'baseLink': {{.Link}},
226+
'baseLink': {{.Issue.Link}},
221227
'textCancel': {{ctx.Locale.Tr "cancel"}},
222228
'textDeleteBranch': {{ctx.Locale.Tr "repo.branch.delete" .HeadTarget}},
223229
'textAutoMergeButtonWhenSucceed': {{ctx.Locale.Tr "repo.pulls.auto_merge_button_when_succeed"}},
@@ -378,7 +384,7 @@
378384
*/}}
379385
{{if and $.StillCanManualMerge (not $showGeneralMergeForm)}}
380386
<div class="divider"></div>
381-
<form class="ui form form-fetch-action" action="{{.Link}}/merge" method="post">{{/* another similar form is in PullRequestMergeForm.vue*/}}
387+
<form class="ui form form-fetch-action" action="{{.Issue.Link}}/merge" method="post">{{/* another similar form is in PullRequestMergeForm.vue*/}}
382388
{{.CsrfTokenHtml}}
383389
<div class="field">
384390
<input type="text" name="merge_commit_id" placeholder="{{ctx.Locale.Tr "repo.pulls.merge_commit_id"}}">

templates/repo/issue/view_content/update_branch_by_merge.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
{{if and $.UpdateAllowed $.UpdateByRebaseAllowed}}
1010
<div class="tw-inline-block">
1111
<div id="update-pr-branch-with-base" class="ui buttons">
12-
<button class="ui button" data-do="{{$.Link}}/update" data-redirect="{{$.Link}}">
12+
<button class="ui button" data-do="{{$.Issue.Link}}/update" data-redirect="{{$.Issue.Link}}">
1313
<span class="button-text">
1414
{{ctx.Locale.Tr "repo.pulls.update_branch"}}
1515
</span>
1616
</button>
1717
<div class="ui dropdown icon button">
1818
{{svg "octicon-triangle-down"}}
1919
<div class="menu">
20-
<a class="item active selected" data-do="{{$.Link}}/update">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</a>
21-
<a class="item" data-do="{{$.Link}}/update?style=rebase">{{ctx.Locale.Tr "repo.pulls.update_branch_rebase"}}</a>
20+
<a class="item active selected" data-do="{{$.Issue.Link}}/update">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</a>
21+
<a class="item" data-do="{{$.Issue.Link}}/update?style=rebase">{{ctx.Locale.Tr "repo.pulls.update_branch_rebase"}}</a>
2222
</div>
2323
</div>
2424
</div>
2525
</div>
2626
{{end}}
2727
{{if and $.UpdateAllowed (not $.UpdateByRebaseAllowed)}}
28-
<form action="{{$.Link}}/update" method="post" class="ui update-branch-form">
28+
<form action="{{$.Issue.Link}}/update" method="post" class="ui update-branch-form">
2929
{{$.CsrfTokenHtml}}
3030
<button class="ui compact button">
3131
<span class="ui text">{{ctx.Locale.Tr "repo.pulls.update_branch"}}</span>

web_src/css/repo.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,6 @@ td .commit-summary {
476476
margin-right: 5px;
477477
}
478478

479-
.repository.view.issue .merge.box .branch-update.grid .row {
480-
padding-bottom: 1rem;
481-
}
482-
483-
.repository.view.issue .merge.box .branch-update.grid .row .icon {
484-
margin-top: 1.1rem;
485-
}
486-
487479
.repository.view.issue .comment-list:not(.prevent-before-timeline)::before {
488480
display: block;
489481
content: "";

web_src/js/features/repo-issue-pr-form.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

web_src/js/features/repo-issue-pr-status.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0