File tree 4 files changed +28
-0
lines changed
4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package models
7
7
import (
8
8
"errors"
9
9
"fmt"
10
+ "path"
10
11
"sort"
11
12
"strings"
12
13
"time"
@@ -200,6 +201,11 @@ func (issue *Issue) GetIsRead(userID int64) error {
200
201
return nil
201
202
}
202
203
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
+
203
209
// HTMLURL returns the absolute URL to this issue.
204
210
func (issue * Issue ) HTMLURL () string {
205
211
var path string
@@ -246,6 +252,7 @@ func (issue *Issue) APIFormat() *api.Issue {
246
252
247
253
apiIssue := & api.Issue {
248
254
ID : issue .ID ,
255
+ URL : issue .APIURL (),
249
256
Index : issue .Index ,
250
257
Poster : issue .Poster .APIFormat (),
251
258
Title : issue .Title ,
Original file line number Diff line number Diff line change @@ -33,3 +33,12 @@ func TestIssue_ReplaceLabels(t *testing.T) {
33
33
testSuccess (1 , []int64 {1 , 2 })
34
34
testSuccess (1 , []int64 {})
35
35
}
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 {
264
264
return setting .AppURL + repo .FullName ()
265
265
}
266
266
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
+
267
272
// APIFormat converts a Repository to api.Repository
268
273
func (repo * Repository ) APIFormat (mode AccessMode ) * api.Repository {
269
274
cloneLink := repo .CloneLink ()
Original file line number Diff line number Diff line change @@ -125,3 +125,10 @@ func TestForkRepository(t *testing.T) {
125
125
assert .Error (t , err )
126
126
assert .True (t , IsErrRepoAlreadyExist (err ))
127
127
}
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