-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Added attachments to releases API #3075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
041b64e
87bcd3b
c788b3d
a253b34
25b23c2
fdc4d39
d1f288a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,6 +461,16 @@ func RegisterRoutes(m *macaron.Macaron) { | |
m.Combo("/:id").Get(repo.GetRelease). | ||
Patch(reqToken(), reqRepoWriter(), bind(api.EditReleaseOption{}), repo.EditRelease). | ||
Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease) | ||
m.Combo("/latest").Get(repo.GetLatestRelease) | ||
m.Group("/:id", func() { | ||
m.Combo("").Get(repo.GetRelease). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 466-468 duplicate lines 461-463; please remove one or the other. |
||
Patch(bind(api.EditReleaseOption{}), repo.EditRelease). | ||
Delete(repo.DeleteRelease) | ||
m.Group("/assets", func() { | ||
m.Combo("").Get(repo.ListReleaseAttachments) | ||
m.Combo("/:assetId").Get(repo.GetReleaseAttachment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This route is incorrect; see https://developer.github.com/v3/repos/releases/#get-a-single-release-asset |
||
}) | ||
}) | ||
}) | ||
m.Post("/mirror-sync", reqToken(), reqRepoWriter(), repo.MirrorSync) | ||
m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,56 @@ func GetRelease(ctx *context.APIContext) { | |
ctx.JSON(200, release.APIFormat()) | ||
} | ||
|
||
// ListReleaseAttachments get all the attachments of a release | ||
func ListReleaseAttachments(ctx *context.APIContext) { | ||
id := ctx.ParamsInt64(":id") | ||
release, err := models.GetReleaseByID(id) | ||
if err != nil { | ||
ctx.Error(500, "GetReleaseByID", err) | ||
return | ||
} | ||
if release.RepoID != ctx.Repo.Repository.ID { | ||
ctx.Status(404) | ||
return | ||
} | ||
// load the attachments of this release | ||
attachments, err := models.GetAttachmentsByReleaseID(id) | ||
if err != nil { | ||
ctx.Error(500, "GetAttachmentsByReleaseID", err) | ||
return | ||
} | ||
// build the attachment list | ||
apiAttachments := make([]*api.Attachment, len(attachments)) | ||
for i := range attachments { | ||
apiAttachments[i] = attachments[i].APIFormat() | ||
} | ||
ctx.JSON(200, apiAttachments) | ||
} | ||
|
||
// GetReleaseAttachment get a single attachment of a release | ||
func GetReleaseAttachment(ctx *context.APIContext) { | ||
id := ctx.ParamsInt64(":id") | ||
attachmentID := ctx.ParamsInt64(":assetId") | ||
release, err := models.GetReleaseByID(id) | ||
if err != nil { | ||
ctx.Error(500, "GetReleaseByID", err) | ||
return | ||
} | ||
if release.RepoID != ctx.Repo.Repository.ID { | ||
ctx.Status(404) | ||
return | ||
} | ||
// load the attachments of this release | ||
attachment, err := models.GetAttachmentByID(attachmentID) | ||
// if the attachment was not found, or it was found but is not associated with this release, then throw 404 | ||
if err != nil || id != attachment.ReleaseID { | ||
ctx.Status(404) | ||
return | ||
} | ||
|
||
ctx.JSON(200, attachment.APIFormat()) | ||
} | ||
|
||
// ListReleases list a repository's releases | ||
func ListReleases(ctx *context.APIContext) { | ||
// swagger:operation GET /repos/{owner}/{repo}/releases repository repoListReleases | ||
|
@@ -94,6 +144,29 @@ func ListReleases(ctx *context.APIContext) { | |
ctx.JSON(200, rels) | ||
} | ||
|
||
// GetLatestRelease Gets the latest release in a repository. Draft releases and prereleases are not returned | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Gets -> gets |
||
func GetLatestRelease(ctx *context.APIContext) { | ||
// we set the pageSize to 1 to get back only one release | ||
releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, models.FindReleasesOptions{ | ||
IncludeDrafts: false, | ||
ExcludePrereleases: true, | ||
}, 1, 1) | ||
if err != nil { | ||
ctx.Error(500, "GetReleasesByRepoID", err) | ||
return | ||
} | ||
if len(releases) <= 0 { | ||
// no releases found, just return 404 | ||
ctx.Status(404) | ||
return | ||
} | ||
if err := releases[0].LoadAttributes(); err != nil { | ||
ctx.Error(500, "LoadAttributes", err) | ||
return | ||
} | ||
ctx.JSON(200, releases[0].APIFormat()) | ||
} | ||
|
||
// CreateRelease create a release | ||
func CreateRelease(ctx *context.APIContext, form api.CreateReleaseOption) { | ||
// swagger:operation GET /repos/{owner}/{repo}/releases repository repoCreateRelease | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only work if
r.Attachments
has been populated before callingAPIFormat()
. This means we will need to update each endpoint that usesRelease.APIFormat()
accordingly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am populating the list in loadAttributes on line 71->78. Is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that. Never mind then