diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-09-21 22:51:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-21 16:51:42 -0400 |
commit | f52fe82add25cba5532b6f650cb702f6b31f4aa9 (patch) | |
tree | 68ca141530ee57b7942338ccb61a7fb890dae556 /models | |
parent | acee32ca09ea8573687759ec039a8d480da97127 (diff) | |
download | gitea-f52fe82add25cba5532b6f650cb702f6b31f4aa9.tar.gz gitea-f52fe82add25cba5532b6f650cb702f6b31f4aa9.zip |
Use absolute links in feeds (#21229)
fixes #20864
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r-- | models/activities/action.go | 5 | ||||
-rw-r--r-- | models/activities/action_test.go | 10 |
2 files changed, 12 insertions, 3 deletions
diff --git a/models/activities/action.go b/models/activities/action.go index 31ecdedd5b..3c8acb5ba8 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -218,6 +218,11 @@ func (a *Action) GetRepoLink() string { return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName()), url.PathEscape(a.GetRepoName())) } +// GetRepoAbsoluteLink returns the absolute link to action repository. +func (a *Action) GetRepoAbsoluteLink() string { + return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName()) +} + // GetCommentLink returns link to action comment. func (a *Action) GetCommentLink() string { return a.getCommentLink(db.DefaultContext) diff --git a/models/activities/action_test.go b/models/activities/action_test.go index 83fd9ee38d..ac2a3043a6 100644 --- a/models/activities/action_test.go +++ b/models/activities/action_test.go @@ -10,6 +10,7 @@ import ( activities_model "code.gitea.io/gitea/models/activities" "code.gitea.io/gitea/models/db" + issue_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -20,7 +21,7 @@ import ( func TestAction_GetRepoPath(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) action := &activities_model.Action{RepoID: repo.ID} assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath()) @@ -28,12 +29,15 @@ func TestAction_GetRepoPath(t *testing.T) { func TestAction_GetRepoLink(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) - action := &activities_model.Action{RepoID: repo.ID} + comment := unittest.AssertExistsAndLoadBean(t, &issue_model.Comment{ID: 2}) + action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID} setting.AppSubURL = "/suburl" expected := path.Join(setting.AppSubURL, owner.Name, repo.Name) assert.Equal(t, expected, action.GetRepoLink()) + assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink()) + assert.Equal(t, comment.HTMLURL(), action.GetCommentLink()) } func TestGetFeeds(t *testing.T) { |