Skip to content

Commit 6930959

Browse files
committed
Display head branch more comfortable on pull request view
1 parent 2da2000 commit 6930959

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
@@ -1922,6 +1922,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p
19221922
pulls.recently_pushed_new_branches = You pushed on branch <strong>%[1]s</strong> %[2]s
19231923

19241924
pull.deleted_branch = (deleted):%s
1925+
pull.agit_documentation = Review documentation about AGit
19251926

19261927
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
19271928

routers/web/repo/pull.go

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

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)