From 7ce388f740843bd2291be5aa1b8e318e96cb1126 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2024 16:11:54 -0800 Subject: [PATCH 1/6] Add line-through for deleted branch on pull request view page --- routers/web/repo/pull.go | 2 ++ templates/repo/issue/view_title.tmpl | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index bb814eab6e70d..d2f74ccf73b60 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -348,6 +348,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C } if !baseGitRepo.IsBranchExist(pull.BaseBranch) { + ctx.Data["BaseBranchNotExist"] = true ctx.Data["IsPullRequestBroken"] = true ctx.Data["BaseTarget"] = pull.BaseBranch ctx.Data["HeadTarget"] = pull.HeadBranch @@ -431,6 +432,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C ctx.Data["GetCommitMessages"] = pull_service.GetSquashMergeCommitMessages(ctx, pull) } else { ctx.Data["GetCommitMessages"] = "" + ctx.Data["HeadBranchNotExist"] = true } sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName()) diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 26b36d6ffcf81..dfc7c51eace50 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -56,7 +56,11 @@ {{if .Issue.IsPull}} {{$headHref := .HeadTarget}} {{if .HeadBranchLink}} - {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} + {{if .HeadBranchNotExist}} + {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} + {{else}} + {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} + {{end}} {{else}} {{if .Issue.PullRequest.IsAgitFlow}} {{$headHref = HTMLFormat `%s AGit` $headHref "https://docs.gitea.com/usage/agit" (ctx.Locale.Tr "repo.pull.agit_documentation")}} @@ -66,8 +70,13 @@ {{end}} {{$baseHref := .BaseTarget}} {{if .BaseBranchLink}} - {{$baseHref = HTMLFormat `%s` .BaseBranchLink $baseHref}} + {{if .BaseBranchNotExist}} + {{$baseHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $baseHref}} + {{else}} + {{$baseHref = HTMLFormat `%s` .BaseBranchLink $baseHref}} + {{end}} {{end}} + {{if .Issue.PullRequest.HasMerged}} {{$mergedStr:= DateUtils.TimeSince .Issue.PullRequest.MergedUnix}} {{if .Issue.OriginalAuthor}} From d139e94b0e14284d2aa8e75d92c246066b698891 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2024 16:22:54 -0800 Subject: [PATCH 2/6] Add line-through for deleted branch comment --- templates/repo/issue/view_content/comments.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 477b6b33c6a5c..478a595b9446a 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -231,7 +231,8 @@ {{template "shared/user/avatarlink" dict "user" .Poster}} {{template "shared/user/authorlink" .Poster}} - {{ctx.Locale.Tr "repo.issues.delete_branch_at" .OldRef $createdStr}} + {{ $oldRef := HTMLFormat `%s` .OldRef }} + {{ctx.Locale.Tr "repo.issues.delete_branch_at" $oldRef $createdStr}} {{else if eq .Type 12}} From d7efc1ec1597fc0fd98eb98d861aa5e07f9fdece Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2024 18:16:49 -0800 Subject: [PATCH 3/6] Fix bug --- routers/web/repo/pull.go | 1 - templates/repo/issue/view_title.tmpl | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index d2f74ccf73b60..cd20c0b18e889 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -432,7 +432,6 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C ctx.Data["GetCommitMessages"] = pull_service.GetSquashMergeCommitMessages(ctx, pull) } else { ctx.Data["GetCommitMessages"] = "" - ctx.Data["HeadBranchNotExist"] = true } sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName()) diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index dfc7c51eace50..ac20dea40851b 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -56,16 +56,12 @@ {{if .Issue.IsPull}} {{$headHref := .HeadTarget}} {{if .HeadBranchLink}} - {{if .HeadBranchNotExist}} - {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} - {{else}} - {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} - {{end}} + {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} {{else}} {{if .Issue.PullRequest.IsAgitFlow}} {{$headHref = HTMLFormat `%s AGit` $headHref "https://docs.gitea.com/usage/agit" (ctx.Locale.Tr "repo.pull.agit_documentation")}} {{else}} - {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} + {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} {{end}} {{end}} {{$baseHref := .BaseTarget}} From d5559d198df6f3c053ddffa9428799ed7f18d8d9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 13 Nov 2024 22:38:39 -0800 Subject: [PATCH 4/6] Fix lint --- templates/repo/issue/view_title.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index ac20dea40851b..cf775f22b57ba 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -72,7 +72,6 @@ {{$baseHref = HTMLFormat `%s` .BaseBranchLink $baseHref}} {{end}} {{end}} - {{if .Issue.PullRequest.HasMerged}} {{$mergedStr:= DateUtils.TimeSince .Issue.PullRequest.MergedUnix}} {{if .Issue.OriginalAuthor}} From b9cb143e177ea46d0e6eb29ff38dc90c99faf25f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 14 Nov 2024 11:05:34 -0800 Subject: [PATCH 5/6] Fix checks --- templates/repo/issue/view_content/comments.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index 478a595b9446a..47551c86e473d 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -231,7 +231,7 @@ {{template "shared/user/avatarlink" dict "user" .Poster}} {{template "shared/user/authorlink" .Poster}} - {{ $oldRef := HTMLFormat `%s` .OldRef }} + {{$oldRef := HTMLFormat `%s` .OldRef}} {{ctx.Locale.Tr "repo.issues.delete_branch_at" $oldRef $createdStr}} From 3e14585b2df3162c8764e9ccd7b37a38427172b6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 14 Nov 2024 15:11:34 -0800 Subject: [PATCH 6/6] Fix test --- tests/integration/pull_merge_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index 2351e169bc520..bbd99f7aab0af 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -589,7 +589,8 @@ func TestPullDontRetargetChildOnWrongRepo(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - targetBranch := htmlDoc.doc.Find("#branch_target>a").Text() + // the branch has been deleted, so there is no a html tag instead of span + targetBranch := htmlDoc.doc.Find("#branch_target>span").Text() prStatus := strings.TrimSpace(htmlDoc.doc.Find(".issue-title-meta>.issue-state-label").Text()) assert.EqualValues(t, "base-pr", targetBranch)