File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed
Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package models
77import (
88 "errors"
99 "fmt"
10+ "path"
1011 "sort"
1112 "strings"
1213 "time"
@@ -200,6 +201,11 @@ func (issue *Issue) GetIsRead(userID int64) error {
200201 return nil
201202}
202203
204+ // APIURL returns the absolute APIURL to this issue.
205+ func (issue * Issue ) APIURL () string {
206+ return issue .Repo .APIURL () + "/" + path .Join ("issues" , fmt .Sprint (issue .ID ))
207+ }
208+
203209// HTMLURL returns the absolute URL to this issue.
204210func (issue * Issue ) HTMLURL () string {
205211 var path string
@@ -246,6 +252,7 @@ func (issue *Issue) APIFormat() *api.Issue {
246252
247253 apiIssue := & api.Issue {
248254 ID : issue .ID ,
255+ URL : issue .APIURL (),
249256 Index : issue .Index ,
250257 Poster : issue .Poster .APIFormat (),
251258 Title : issue .Title ,
Original file line number Diff line number Diff line change @@ -33,3 +33,12 @@ func TestIssue_ReplaceLabels(t *testing.T) {
3333 testSuccess (1 , []int64 {1 , 2 })
3434 testSuccess (1 , []int64 {})
3535}
36+
37+ func TestIssueAPIURL (t * testing.T ) {
38+ assert .NoError (t , PrepareTestDatabase ())
39+ issue := AssertExistsAndLoadBean (t , & Issue {ID : 1 }).(* Issue )
40+ err := issue .LoadAttributes ()
41+
42+ assert .NoError (t , err )
43+ assert .Equal (t , "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1" , issue .APIURL ())
44+ }
Original file line number Diff line number Diff line change @@ -264,6 +264,11 @@ func (repo *Repository) HTMLURL() string {
264264 return setting .AppURL + repo .FullName ()
265265}
266266
267+ // APIURL returns the repository API URL
268+ func (repo * Repository ) APIURL () string {
269+ return setting .AppURL + path .Join ("api/v1/repos" , repo .FullName ())
270+ }
271+
267272// APIFormat converts a Repository to api.Repository
268273func (repo * Repository ) APIFormat (mode AccessMode ) * api.Repository {
269274 cloneLink := repo .CloneLink ()
Original file line number Diff line number Diff line change @@ -125,3 +125,10 @@ func TestForkRepository(t *testing.T) {
125125 assert .Error (t , err )
126126 assert .True (t , IsErrRepoAlreadyExist (err ))
127127}
128+
129+ func TestRepoAPIURL (t * testing.T ) {
130+ assert .NoError (t , PrepareTestDatabase ())
131+ repo := AssertExistsAndLoadBean (t , & Repository {ID : 10 }).(* Repository )
132+
133+ assert .Equal (t , "https://try.gitea.io/api/v1/repos/user12/repo10" , repo .APIURL ())
134+ }
You can’t perform that action at this time.
0 commit comments