]> source.dussan.org Git - gitea.git/commitdiff
Display head branch more comfortable on pull request view (#32000)
authorLunny Xiao <xiaolunwen@gmail.com>
Tue, 24 Sep 2024 04:14:57 +0000 (12:14 +0800)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 04:14:57 +0000 (04:14 +0000)
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)

models/issues/pull.go
options/locale/locale_en-US.ini
routers/web/repo/pull.go
templates/repo/issue/view_title.tmpl

index 5fe95d56cc2536b0181d9a0a962d1ad0fece600a..4a5782f836c896250608a4c1c3206badd03f93d0 100644 (file)
@@ -268,6 +268,10 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
        return nil
 }
 
+func (pr *PullRequest) IsAgitFlow() bool {
+       return pr.Flow == PullRequestFlowAGit
+}
+
 // LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist
 // and thus ErrRepoNotExist will never be returned
 func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {
index 957e73b171d32ccc29ccfd3d5268eedb1ac18ee8..f77fd203a2d6b38a1b081df17f0917389baf99e1 100644 (file)
@@ -1927,6 +1927,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p
 pulls.recently_pushed_new_branches = You pushed on branch <strong>%[1]s</strong> %[2]s
 
 pull.deleted_branch = (deleted):%s
+pull.agit_documentation = Review documentation about AGit
 
 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
 
index 95299b44d5a253e27c47438ef1062631bc32ed76..ced0bbc15a00e21c95366912071b4fe3fdd4d024 100644 (file)
@@ -164,7 +164,19 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
                ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
        }
        ctx.Data["BaseTarget"] = pull.BaseBranch
-       ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx)
+       headBranchLink := ""
+       if pull.Flow == issues_model.PullRequestFlowGithub {
+               b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, pull.HeadBranch)
+               switch {
+               case err == nil:
+                       if !b.IsDeleted {
+                               headBranchLink = pull.GetHeadBranchLink(ctx)
+                       }
+               case !git_model.IsErrBranchNotExist(err):
+                       log.Error("GetBranch: %v", err)
+               }
+       }
+       ctx.Data["HeadBranchLink"] = headBranchLink
        ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx)
 }
 
index 1243681f3a219bd1080a55f8a09199ae5dc02b77..7fa77b3f1cf334de7e49075a0994fcfd2332741f 100644 (file)
                        {{if .Issue.IsPull}}
                                {{$headHref := .HeadTarget}}
                                {{if .HeadBranchLink}}
-                                       {{$headHref = HTMLFormat `<a href="%s">%s</a>` .HeadBranchLink $headHref}}
+                                       {{$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)}}
+                               {{else}}
+                                       {{if .Issue.PullRequest.IsAgitFlow}}
+                                               {{$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")}}
+                                       {{else}}
+                                               {{$headHref = HTMLFormat `<span data-tooltip-content="%s">%s</span>` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}}
+                                       {{end}}
                                {{end}}
-                               {{$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)}}
                                {{$baseHref := .BaseTarget}}
                                {{if .BaseBranchLink}}
                                        {{$baseHref = HTMLFormat `<a href="%s">%s</a>` .BaseBranchLink $baseHref}}