mirror of https://github.com/go-gitea/gitea.git
feat: expose url field on issue api. (#982)
* Add api url func. Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * fix: Add unit testing. * fix: conflicts * fix: remove trim * fix: revert test function name.
This commit is contained in:
parent
0afab87631
commit
d76d67de23
|
@ -7,6 +7,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -200,6 +201,11 @@ func (issue *Issue) GetIsRead(userID int64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APIURL returns the absolute APIURL to this issue.
|
||||||
|
func (issue *Issue) APIURL() string {
|
||||||
|
return issue.Repo.APIURL() + "/" + path.Join("issues", fmt.Sprint(issue.ID))
|
||||||
|
}
|
||||||
|
|
||||||
// HTMLURL returns the absolute URL to this issue.
|
// HTMLURL returns the absolute URL to this issue.
|
||||||
func (issue *Issue) HTMLURL() string {
|
func (issue *Issue) HTMLURL() string {
|
||||||
var path string
|
var path string
|
||||||
|
@ -246,6 +252,7 @@ func (issue *Issue) APIFormat() *api.Issue {
|
||||||
|
|
||||||
apiIssue := &api.Issue{
|
apiIssue := &api.Issue{
|
||||||
ID: issue.ID,
|
ID: issue.ID,
|
||||||
|
URL: issue.APIURL(),
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
Poster: issue.Poster.APIFormat(),
|
Poster: issue.Poster.APIFormat(),
|
||||||
Title: issue.Title,
|
Title: issue.Title,
|
||||||
|
|
|
@ -33,3 +33,12 @@ func TestIssue_ReplaceLabels(t *testing.T) {
|
||||||
testSuccess(1, []int64{1, 2})
|
testSuccess(1, []int64{1, 2})
|
||||||
testSuccess(1, []int64{})
|
testSuccess(1, []int64{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssueAPIURL(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||||
|
err := issue.LoadAttributes()
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL())
|
||||||
|
}
|
||||||
|
|
|
@ -264,6 +264,11 @@ func (repo *Repository) HTMLURL() string {
|
||||||
return setting.AppURL + repo.FullName()
|
return setting.AppURL + repo.FullName()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APIURL returns the repository API URL
|
||||||
|
func (repo *Repository) APIURL() string {
|
||||||
|
return setting.AppURL + path.Join("api/v1/repos", repo.FullName())
|
||||||
|
}
|
||||||
|
|
||||||
// APIFormat converts a Repository to api.Repository
|
// APIFormat converts a Repository to api.Repository
|
||||||
func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
|
func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
|
||||||
cloneLink := repo.CloneLink()
|
cloneLink := repo.CloneLink()
|
||||||
|
|
|
@ -125,3 +125,10 @@ func TestForkRepository(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.True(t, IsErrRepoAlreadyExist(err))
|
assert.True(t, IsErrRepoAlreadyExist(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRepoAPIURL(t *testing.T) {
|
||||||
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository)
|
||||||
|
|
||||||
|
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue