Merge pull request '[GITEA] Make reference URL absolute' (#2100) from gusted/forgejo-absolute-reference-url into forgejo-dependency

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2100
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Gusted 2024-01-06 19:08:17 +00:00
commit 55f2cfccba
2 changed files with 30 additions and 2 deletions

View file

@ -5,9 +5,9 @@
<div class="menu"> <div class="menu">
{{$referenceUrl := ""}} {{$referenceUrl := ""}}
{{if .issue}} {{if .issue}}
{{$referenceUrl = printf "%s#%s" .ctxData.Issue.Link .item.HashTag}} {{$referenceUrl = printf "%s#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{else}} {{else}}
{{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.Link .item.HashTag}} {{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{end}} {{end}}
<div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.copy_link"}}</div> <div class="item context js-aria-clickable" data-clipboard-text-type="url" data-clipboard-text="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.copy_link"}}</div>
{{if and .ctxData.IsSigned (not .ctxData.Repository.IsArchived)}} {{if and .ctxData.IsSigned (not .ctxData.Repository.IsArchived)}}

View file

@ -699,3 +699,31 @@ func TestIssuePinMove(t *testing.T) {
issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID}) issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue.ID})
assert.EqualValues(t, newPosition, issue.PinOrder) assert.EqualValues(t, newPosition, issue.PinOrder)
} }
func TestAbsoluteReferenceURL(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
issue1 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue1.RepoID})
req := NewRequest(t, "GET", fmt.Sprintf("%s/issues/%d", repo.FullName(), issue1.Index))
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
t.Run("Issue", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
referenceURL, ok := htmlDoc.Find(".reference-issue").Attr("data-reference")
assert.True(t, ok)
assert.EqualValues(t, setting.AppURL+"user2/repo1/issues/1#issue-1", referenceURL)
})
t.Run("Comment", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
referenceURL, ok := htmlDoc.Find(`[id^="issuecomment"] .reference-issue`).Attr("data-reference")
assert.True(t, ok)
assert.EqualValues(t, setting.AppURL+"user2/repo1/issues/1#issuecomment-2", referenceURL)
})
}