Merge pull request '[GITEA] Make reference URL absolute' (#2104) from gusted/forgejo-bp-2100 into v1.21/forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2104
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Gusted 2024-01-06 19:49:11 +00:00
commit 316b633e62
2 changed files with 30 additions and 2 deletions

View file

@ -5,9 +5,9 @@
<div class="menu">
{{$referenceUrl := ""}}
{{if .issue}}
{{$referenceUrl = printf "%s#%s" .ctxData.Issue.Link .item.HashTag}}
{{$referenceUrl = printf "%s#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{else}}
{{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.Link .item.HashTag}}
{{$referenceUrl = printf "%s/files#%s" .ctxData.Issue.HTMLURL .item.HashTag}}
{{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>
{{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})
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)
})
}