[UI] Agit: Add AGit label to AGit-created PRs
Adds a label to Pull Requests that were created using AGit-Flow, in order to prevent situations where a contributor uses AGit-Flow to push new changes - only to realize that they did not use AGit-Flow in the first place, and that they just opened a new PR accidentally (that was me). Also intended to raise general awareness about the feature. Some additional work, such as adding a tooltip, still needs to be done. A small typo fix for a comment and (exclusively) formatting fixes in the copyright header are also included. Refs: https://codeberg.org/forgejo/forgejo/issues/2433
This commit is contained in:
parent
c47e6ceb82
commit
bf7fb89178
|
@ -1505,6 +1505,7 @@ issues.action_check_all = Check/Uncheck all items
|
||||||
issues.opened_by = opened %[1]s by <a href="%[2]s">%[3]s</a>
|
issues.opened_by = opened %[1]s by <a href="%[2]s">%[3]s</a>
|
||||||
pulls.merged_by = by <a href="%[2]s">%[3]s</a> was merged %[1]s
|
pulls.merged_by = by <a href="%[2]s">%[3]s</a> was merged %[1]s
|
||||||
pulls.merged_by_fake = by %[2]s was merged %[1]s
|
pulls.merged_by_fake = by %[2]s was merged %[1]s
|
||||||
|
pulls.made_using_agit = AGit
|
||||||
issues.closed_by = by <a href="%[2]s">%[3]s</a> was closed %[1]s
|
issues.closed_by = by <a href="%[2]s">%[3]s</a> was closed %[1]s
|
||||||
issues.opened_by_fake = opened %[1]s by %[2]s
|
issues.opened_by_fake = opened %[1]s by %[2]s
|
||||||
issues.closed_by_fake = by %[2]s was closed %[1]s
|
issues.closed_by_fake = by %[2]s was closed %[1]s
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// Copyright 2018 The Gitea Authors.
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
// Copyright 2014 The Gogs Authors.
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||||
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
@ -381,6 +382,11 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
|
||||||
} else {
|
} else {
|
||||||
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
|
ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pull.Flow == issues_model.PullRequestFlowAGit {
|
||||||
|
ctx.Data["MadeUsingAGit"] = true
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Data["BaseTarget"] = pull.BaseBranch
|
ctx.Data["BaseTarget"] = pull.BaseBranch
|
||||||
ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx)
|
ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx)
|
||||||
ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx)
|
ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx)
|
||||||
|
|
|
@ -47,7 +47,9 @@
|
||||||
{{if .HeadBranchLink}}
|
{{if .HeadBranchLink}}
|
||||||
{{$headHref = printf `<a href="%s">%s</a>` (.HeadBranchLink | Escape) $headHref}}
|
{{$headHref = printf `<a href="%s">%s</a>` (.HeadBranchLink | Escape) $headHref}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if not .MadeUsingAGit}}
|
||||||
{{$headHref = printf `%s <button class="btn interact-fg" data-tooltip-content="%s" data-clipboard-text="%s">%s</button>` $headHref (ctx.Locale.Tr "copy_branch") (.HeadTarget | Escape) (svg "octicon-copy" 14)}}
|
{{$headHref = printf `%s <button class="btn interact-fg" data-tooltip-content="%s" data-clipboard-text="%s">%s</button>` $headHref (ctx.Locale.Tr "copy_branch") (.HeadTarget | Escape) (svg "octicon-copy" 14)}}
|
||||||
|
{{end}}
|
||||||
{{$baseHref := .BaseTarget|Escape}}
|
{{$baseHref := .BaseTarget|Escape}}
|
||||||
{{if .BaseBranchLink}}
|
{{if .BaseBranchLink}}
|
||||||
{{$baseHref = printf `<a href="%s">%s</a>` (.BaseBranchLink | Escape) $baseHref}}
|
{{$baseHref = printf `<a href="%s">%s</a>` (.BaseBranchLink | Escape) $baseHref}}
|
||||||
|
@ -70,6 +72,12 @@
|
||||||
{{ctx.Locale.Tr "repo.pulls.title_desc" .NumCommits ($headHref|Safe) ($baseHref|Safe)}}
|
{{ctx.Locale.Tr "repo.pulls.title_desc" .NumCommits ($headHref|Safe) ($baseHref|Safe)}}
|
||||||
</span>
|
</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if .MadeUsingAGit}}
|
||||||
|
{{/* TODO: Add tooltip and a link to the documentation */}}
|
||||||
|
<span id="agit-label" class="ui small label">
|
||||||
|
{{ctx.Locale.Tr "repo.pulls.made_using_agit"}}
|
||||||
|
</span>
|
||||||
|
{{end}}
|
||||||
<span id="pull-desc-edit" class="gt-hidden flex-text-block">
|
<span id="pull-desc-edit" class="gt-hidden flex-text-block">
|
||||||
<div class="ui floating filter dropdown">
|
<div class="ui floating filter dropdown">
|
||||||
<div class="ui basic small button gt-mr-0">
|
<div class="ui basic small button gt-mr-0">
|
||||||
|
|
|
@ -470,6 +470,19 @@ func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) fun
|
||||||
}
|
}
|
||||||
t.Run("EnsureCanSeePull", doEnsureCanSeePull(headCtx, pr, true))
|
t.Run("EnsureCanSeePull", doEnsureCanSeePull(headCtx, pr, true))
|
||||||
|
|
||||||
|
// Confirm that there is no AGit Label
|
||||||
|
// TODO: Refactor and move this check to a function
|
||||||
|
t.Run("AGitLabelIsMissing", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
session := loginUser(t, ctx.Username)
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d", baseCtx.Username, baseCtx.Reponame, pr.Index))
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
htmlDoc.AssertElement(t, "#agit-label", false)
|
||||||
|
})
|
||||||
|
|
||||||
// Then get the diff string
|
// Then get the diff string
|
||||||
var diffHash string
|
var diffHash string
|
||||||
var diffLength int
|
var diffLength int
|
||||||
|
@ -813,6 +826,17 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("AGitLabelIsPresent", func(t *testing.T) {
|
||||||
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
|
session := loginUser(t, ctx.Username)
|
||||||
|
|
||||||
|
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/pulls/%d", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), pr2.Index))
|
||||||
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
htmlDoc.AssertElement(t, "#agit-label", true)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("AddCommit2", func(t *testing.T) {
|
t.Run("AddCommit2", func(t *testing.T) {
|
||||||
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0o666)
|
err := os.WriteFile(path.Join(dstPath, "test_file"), []byte("## test content \n ## test content 2"), 0o666)
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
|
|
Loading…
Reference in a new issue