Skip to content

Commit e2f365b

Browse files
authored
Display head branch more comfortable on pull request view (#32000)
This PR do some minor improvements for head branch display on pull request view UI. - [x] Remove the link if the head branch has been deleted with a tooltip, so that users will not result in a 404 page - [x] Display a label if this pull request is an agit based one. ![图片](https://github.com/user-attachments/assets/872f26b6-f1cf-4427-9e41-e3a5b176dfa4)
1 parent aadbe04 commit e2f365b

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

models/issues/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
268268
return nil
269269
}
270270

271+
func (pr *PullRequest) IsAgitFlow() bool {
272+
return pr.Flow == PullRequestFlowAGit
273+
}
274+
271275
// LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist
272276
// and thus ErrRepoNotExist will never be returned
273277
func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p
19271927
pulls.recently_pushed_new_branches = You pushed on branch <strong>%[1]s</strong> %[2]s
19281928

19291929
pull.deleted_branch = (deleted):%s
1930+
pull.agit_documentation = Review documentation about AGit
19301931

19311932
comments.edit.already_changed = Unable to save changes to the comment. It appears the content has already been changed by another user. Please refresh the page and try editing again to avoid overwriting their changes
19321933

routers/web/repo/pull.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,19 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
164164
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
165165
}
166166
ctx.Data["BaseTarget"] = pull.BaseBranch
167-
ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx)
167+
headBranchLink := ""
168+
if pull.Flow == issues_model.PullRequestFlowGithub {
169+
b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, pull.HeadBranch)
170+
switch {
171+
case err == nil:
172+
if !b.IsDeleted {
173+
headBranchLink = pull.GetHeadBranchLink(ctx)
174+
}
175+
case !git_model.IsErrBranchNotExist(err):
176+
log.Error("GetBranch: %v", err)
177+
}
178+
}
179+
ctx.Data["HeadBranchLink"] = headBranchLink
168180
ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx)
169181
}
170182

templates/repo/issue/view_title.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@
5050
{{if .Issue.IsPull}}
5151
{{$headHref := .HeadTarget}}
5252
{{if .HeadBranchLink}}
53-
{{$headHref = HTMLFormat `<a href="%s">%s</a>` .HeadBranchLink $headHref}}
53+
{{$headHref = HTMLFormat `<a href="%s">%s</a> <button class="btn interact-fg" data-tooltip-content="%s" data-clipboard-text="%s">%s</button>` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}}
54+
{{else}}
55+
{{if .Issue.PullRequest.IsAgitFlow}}
56+
{{$headHref = HTMLFormat `%s <a href="%s" target="_blank"><span class="ui label basic tiny" data-tooltip-content="%s">AGit</span></a>` $headHref "https://docs.gitea.com/usage/agit" (ctx.Locale.Tr "repo.pull.agit_documentation")}}
57+
{{else}}
58+
{{$headHref = HTMLFormat `<span data-tooltip-content="%s">%s</span>` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}}
59+
{{end}}
5460
{{end}}
55-
{{$headHref = HTMLFormat `%s <button class="btn interact-fg" data-tooltip-content="%s" data-clipboard-text="%s">%s</button>` $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}}
5661
{{$baseHref := .BaseTarget}}
5762
{{if .BaseBranchLink}}
5863
{{$baseHref = HTMLFormat `<a href="%s">%s</a>` .BaseBranchLink $baseHref}}

0 commit comments

Comments
 (0)