-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Added attachments to the releases API #2084
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
Conversation
models/release.go
Outdated
@@ -71,6 +71,10 @@ func (r *Release) loadAttributes(e Engine) error { | |||
return err | |||
} | |||
} | |||
// load the attachments of this release | |||
if r.Attachments == nil { | |||
GetReleaseAttachments(r) |
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.
The error
returned by GetReleaseAttachments(r)
is unchecked.
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 think we should follow GitHub api as close as possible so it would be better to name features same as GitHub so in this case as Assets.
Also do not change anything under vendor directory directly. If changes need to be done in sdk first you need to submit PR in https://github.com/go-gitea/go-sdk
Aslo this would need test
Don't ignore gravatar error
Somes layer are created and aren't usefull, so I compress this :)
Understood. I'll separate this into 2 PRs for the appropriate repos. Thanks for the tips |
Signed-off-by: Petrisor Lacatus <[email protected]>
This reverts commit 789188f.
Signed-off-by: Petrisor Lacatus <[email protected]>
…nd to get all the attachments associated with a given release Signed-off-by: Petrisor Lacatus <[email protected]>
as well getting a given attachment of a release Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
Fixed the issue mentioned by @ethantkoenig
@tboerger : can you give me some quick tips about adding tests? I'm a bit in the dark there. |
Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
models/attachment.go
Outdated
@@ -58,6 +59,20 @@ func (a *Attachment) IncreaseDownloadCount() error { | |||
return nil | |||
} | |||
|
|||
// GetSize gets the size of the attachment in bytes | |||
func (a *Attachment) GetSize() (int64, error) { | |||
f, err := os.Open(a.LocalPath()) |
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 think it would be better to use
info, err := os.Stat(a.LocalPath());
if err != nil {
return 0, err
}
return info.Size(), nil
DownloadURL: setting.AppURL + "attachments/" + a.UUID, | ||
DownloadCount: a.DownloadCount, | ||
} | ||
fileSize, err := a.GetSize() |
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.
If there is error please log it
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.
Good point, thanks
models/attachment.go
Outdated
@@ -142,6 +186,12 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) { | |||
return attachments, x.Where("comment_id=?", commentID).Find(&attachments) | |||
} | |||
|
|||
// GetAttachmentsByReleaseID returns all attachments of a release | |||
func GetAttachmentsByReleaseID(releaseId int64) ([]*Attachment, error) { |
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.
naming releaseId -> releaseID
Added error logging. Signed-off-by: Petrisor Lacatus <[email protected]>
Fix exit status 1 not handled @ getMergeCommit (#2087)
Signed-off-by: Petrisor Lacatus <[email protected]>
Please rebase on master |
Signed-off-by: Petrisor Lacatus <[email protected]>
…nd to get all the attachments associated with a given release Signed-off-by: Petrisor Lacatus <[email protected]>
as well getting a given attachment of a release Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
Added error logging. Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
Signed-off-by: Petrisor Lacatus <[email protected]>
# Conflicts: # models/release.go # routers/api/v1/repo/release.go # routers/repo/release.go
models/release.go
Outdated
@@ -246,13 +260,16 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond { | |||
if !opts.IncludeDrafts { | |||
cond = cond.And(builder.Eq{"is_draft": false}) | |||
} | |||
if !opts.IncludeDrafts { |
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.
There should be check for IncludePrereleases
Signed-off-by: Petrisor Lacatus <[email protected]>
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.
Error Checking and a question
DownloadCount: a.DownloadCount, | ||
} | ||
fileSize, err := a.GetSize() | ||
log.Warn("Error getting the file size for attachment %s. ", a.UUID, err) |
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 should if in a if err != nil
check.
I'd do this:
fileSize, err := a.GetSize()
if err != nil {
log.Warn(...)
}
// Effectively doing `Size = 0` on errors.
apiAttachment.Size = fileSize
return apiAttachment
ctx.Error(500, "LoadAttributes", err) | ||
return | ||
} | ||
ctx.JSON(200, releases[0].APIFormat()) |
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.
e we sure that [0]
is the latest one? (I don't see anything about sorting in the PR 🙂 )
I'll revisit this next week, as i've also identified some bugs internally. |
any update? |
I'll redo on top of the master |
Very simple initial fix for #711.
It's also my first interaction with GO so i'm sorry for stupid mistakes.
Includes changes to the endpoints:
GET /repos/:owner/:repo/releases[/:id]
- now includes assetsGET /repos/:owner/:repo/releases/:id/assets
GET /repos/:owner/:repo/releases/assets/:id
If the API for github must be followed, where attachments are "assets", with a lot of additional metadata then this PR can be skipped, but for my limited usecase this is all I need.
Depends on go-gitea/go-sdk#63