@@ -54,6 +54,56 @@ func GetRelease(ctx *context.APIContext) {
54
54
ctx .JSON (200 , release .APIFormat ())
55
55
}
56
56
57
+ // ListReleaseAttachments get all the attachments of a release
58
+ func ListReleaseAttachments (ctx * context.APIContext ) {
59
+ id := ctx .ParamsInt64 (":id" )
60
+ release , err := models .GetReleaseByID (id )
61
+ if err != nil {
62
+ ctx .Error (500 , "GetReleaseByID" , err )
63
+ return
64
+ }
65
+ if release .RepoID != ctx .Repo .Repository .ID {
66
+ ctx .Status (404 )
67
+ return
68
+ }
69
+ // load the attachments of this release
70
+ attachments , err := models .GetAttachmentsByReleaseID (id )
71
+ if err != nil {
72
+ ctx .Error (500 , "GetAttachmentsByReleaseID" , err )
73
+ return
74
+ }
75
+ // build the attachment list
76
+ apiAttachments := make ([]* api.Attachment , len (attachments ))
77
+ for i := range attachments {
78
+ apiAttachments [i ] = attachments [i ].APIFormat ()
79
+ }
80
+ ctx .JSON (200 , apiAttachments )
81
+ }
82
+
83
+ // GetReleaseAttachment get a single attachment of a release
84
+ func GetReleaseAttachment (ctx * context.APIContext ) {
85
+ id := ctx .ParamsInt64 (":id" )
86
+ attachmentID := ctx .ParamsInt64 (":assetId" )
87
+ release , err := models .GetReleaseByID (id )
88
+ if err != nil {
89
+ ctx .Error (500 , "GetReleaseByID" , err )
90
+ return
91
+ }
92
+ if release .RepoID != ctx .Repo .Repository .ID {
93
+ ctx .Status (404 )
94
+ return
95
+ }
96
+ // load the attachments of this release
97
+ attachment , err := models .GetAttachmentByID (attachmentID )
98
+ // if the attachment was not found, or it was found but is not associated with this release, then throw 404
99
+ if err != nil || id != attachment .ReleaseID {
100
+ ctx .Status (404 )
101
+ return
102
+ }
103
+
104
+ ctx .JSON (200 , attachment .APIFormat ())
105
+ }
106
+
57
107
// ListReleases list a repository's releases
58
108
func ListReleases (ctx * context.APIContext ) {
59
109
// swagger:operation GET /repos/{owner}/{repo}/releases repository repoListReleases
@@ -94,6 +144,29 @@ func ListReleases(ctx *context.APIContext) {
94
144
ctx .JSON (200 , rels )
95
145
}
96
146
147
+ // GetLatestRelease Gets the latest release in a repository. Draft releases and prereleases are not returned
148
+ func GetLatestRelease (ctx * context.APIContext ) {
149
+ // we set the pageSize to 1 to get back only one release
150
+ releases , err := models .GetReleasesByRepoID (ctx .Repo .Repository .ID , models.FindReleasesOptions {
151
+ IncludeDrafts : false ,
152
+ ExcludePrereleases : true ,
153
+ }, 1 , 1 )
154
+ if err != nil {
155
+ ctx .Error (500 , "GetReleasesByRepoID" , err )
156
+ return
157
+ }
158
+ if len (releases ) <= 0 {
159
+ // no releases found, just return 404
160
+ ctx .Status (404 )
161
+ return
162
+ }
163
+ if err := releases [0 ].LoadAttributes (); err != nil {
164
+ ctx .Error (500 , "LoadAttributes" , err )
165
+ return
166
+ }
167
+ ctx .JSON (200 , releases [0 ].APIFormat ())
168
+ }
169
+
97
170
// CreateRelease create a release
98
171
func CreateRelease (ctx * context.APIContext , form api.CreateReleaseOption ) {
99
172
// swagger:operation GET /repos/{owner}/{repo}/releases repository repoCreateRelease
0 commit comments