Skip to content
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

Add Attachment API #3478

Merged
merged 35 commits into from
Mar 6, 2018
Merged

Add Attachment API #3478

merged 35 commits into from
Mar 6, 2018

Conversation

jonasfranz
Copy link
Member

@jonasfranz jonasfranz commented Feb 8, 2018

Fixes #711

Blocked by go-gitea/go-sdk#90

API endpoints:

  • GET repos/:owner/:repo/releases (add attachments)
  • GET repos/:owner/:repo/releases/:id (add attachments)
  • GET repos/:owner/:repo/releases/:id/assets
  • GET repos/:owner/:repo/releases/:id/assets/:attachment_id
  • POST repos/:owner/:repo/releases/:id/assets
  • PATCH repos/:owner/:repo/releases/:id/assets/:attachment_id
  • DELETE repos/:owner/:repo/releases/:id/assets/:attachment_id

Example response

[
   {
      "id":1,
      "tag_name":"test",
      "target_commitish":"master",
      "name":"",
      "body":"test",
      "url":"http://localhost:3000/api/v1/jonas/re/releases/1",
      "tarball_url":"http://localhost:3000/jonas/re/archive/test.tar.gz",
      "zipball_url":"http://localhost:3000/jonas/re/archive/test.zip",
      "draft":false,
      "prerelease":false,
      "created_at":"2018-02-08T21:17:42+01:00",
      "published_at":"2018-02-08T21:17:42+01:00",
      "author":{
         "id":1,
         "login":"jonas",
         "full_name":"",
         "email":"admin@admin.admin",
         "avatar_url":"https://secure.gravatar.com/avatar/839531d0faa3e6efb8d874dd74a8e530?d=identicon",
         "username":"jonas"
      },
      "assets":[
         {
            "id":1,
            "name":"device manager.PNG",
            "size":9453,
            "download_count":1,
            "created_at":"2018-02-08T21:17:39+01:00",
            "uuid":"b780ab51-c0f2-4c6e-b16c-12fe07636d52",
            "browser_download_url":"http://localhost:3000/attachments/b780ab51-c0f2-4c6e-b16c-12fe07636d52"
         }
      ]
   }
]

TODO

  • Unit tests

* repos/:owner/:repo/releases (add attachments)
* repos/:owner/:repo/releases/:id (add attachments)
* repos/:owner/:repo/releases/:id/attachments
* repos/:owner/:repo/releases/:id/attachments/:attachment_id

Signed-off-by: Jonas Franz <info@jonasfranz.de>
@jonasfranz jonasfranz mentioned this pull request Feb 8, 2018
1 task
Fix comments

Signed-off-by: Jonas Franz <info@jonasfranz.software>
@lafriks
Copy link
Member

lafriks commented Feb 9, 2018

Go lint fails with error

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 9, 2018
root and others added 5 commits February 9, 2018 09:08
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Add missing license header

Signed-off-by: Jonas Franz <info@jonasfranz.software>
@codecov-io
Copy link

codecov-io commented Feb 9, 2018

Codecov Report

Merging #3478 into master will decrease coverage by 0.23%.
The diff coverage is 9.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3478      +/-   ##
==========================================
- Coverage   36.15%   35.91%   -0.24%     
==========================================
  Files         285      286       +1     
  Lines       40928    41257     +329     
==========================================
+ Hits        14797    14818      +21     
- Misses      23957    24259     +302     
- Partials     2174     2180       +6
Impacted Files Coverage Δ
routers/api/v1/repo/release_attachment.go 0% <0%> (ø)
routers/api/v1/repo/release.go 43.84% <100%> (ø) ⬆️
routers/api/v1/api.go 75.82% <100%> (+0.4%) ⬆️
models/attachment.go 46.76% <40.47%> (-2.73%) ⬇️
models/release.go 45.7% <50%> (-0.1%) ⬇️
modules/process/manager.go 76.81% <0%> (-4.35%) ⬇️
models/repo_list.go 65.62% <0%> (-1.57%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69ea5e4...3812137. Read the comment docs.

Add EditReleaseAttachment
Add DeleteReleaseAttachment

Signed-off-by: Jonas Franz <info@jonasfranz.software>
Signed-off-by: Jonas Franz <info@jonasfranz.software>
@@ -15,6 +15,8 @@ import (

"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"
"github.com/go-xorm/xorm"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line needed.

// Use uuid only if id is not set and uuid is set
sess = e.Where("uuid = ?", atta.UUID)
}
_, err := sess.AllCols().Update(atta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea to update all the columns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you propose alternatively?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sess.Cols("col1", "col2"...).Update()
Only update needed columns.

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2018
@lunny lunny added type/feature Completely new functionality. Can only be merged if feature freeze is not active. modifies/api This PR adds API routes or modifies them labels Feb 26, 2018
…ses-api

# Conflicts:
#	vendor/code.gitea.io/sdk/gitea/attachment.go
#	vendor/vendor.json
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Update code.gitea.io/sdk

Signed-off-by: Jonas Franz <info@jonasfranz.software>
@jonasfranz
Copy link
Member Author

@appleboy I've fixed this bug in go-gitea/go-sdk#96

m.Combo("").Get(repo.GetRelease).
Patch(reqToken(), reqRepoWriter(), context.ReferencesGitRepo(), bind(api.EditReleaseOption{}), repo.EditRelease).
Delete(reqToken(), reqRepoWriter(), repo.DeleteRelease)
m.Group("/assets", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documented as /attachments but it's actually /assets. which is it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is documented as assets as shown in the go sdk and the PR description.

Copy link
Contributor

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it should become assets everywhere else as well.


// DownloadURL returns the download url of the attached file
func (a *Attachment) DownloadURL() string {
return fmt.Sprintf("%sattachments/%s", setting.AppURL, a.UUID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated since it is used to generade the download link and not for API usage.

UUID: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
ID: 1,
}
assert.Equal(t, "https://try.gitea.io/attachments/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attach.DownloadURL())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is required because assets is only used at the release API. And the attachment API uses attachment and a change would be breaking.

@@ -3351,6 +3420,247 @@
}
}
},
"/repos/{owner}/{repo}/releases/{id}/attachments": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And swagger.json needs to be regenerated.

Signed-off-by: Jonas Franz <info@jonasfranz.software>

func updateAttachment(e Engine, atta *Attachment) error {
var sess *xorm.Session
if atta.ID != 0 || atta.UUID == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change to atta.ID != 0 && atta.UUID == ""

or

if atta.ID != 0 {
  ....
} else if atta.UUID != "" {
  ....
} else {
  // return err if missing id and uuid
}

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 5, 2018
@appleboy
Copy link
Member

appleboy commented Mar 5, 2018

@thehowl need your approval.

@appleboy appleboy merged commit 9a5e628 into go-gitea:master Mar 6, 2018
@jonasfranz jonasfranz deleted the 711-releases-api branch March 6, 2018 07:13
@techknowlogick techknowlogick mentioned this pull request Mar 19, 2018
4 tasks
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea"
"errors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong import order

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is already merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe another PR to fix that.

@sapk sapk mentioned this pull request Apr 17, 2018
@lafriks lafriks added the type/changelog Adds the changelog for a new Gitea version label Jul 3, 2018
aswild added a commit to aswild/gitea that referenced this pull request Jul 6, 2018
* SECURITY
  * Limit uploaded avatar image-size to 4096x3072 by default (go-gitea#4353)
  * Do not allow to reuse TOTP passcode (go-gitea#3878)
* FEATURE
  * Add cli commands to regen hooks & keys (go-gitea#3979)
  * Add support for FIDO U2F (go-gitea#3971)
  * Added user language setting (go-gitea#3875)
  * LDAP Public SSH Keys synchronization (go-gitea#1844)
  * Add topic support (go-gitea#3711)
  * Multiple assignees (go-gitea#3705)
  * Add protected branch whitelists for merging (go-gitea#3689)
  * Global code search support (go-gitea#3664)
  * Add label descriptions (go-gitea#3662)
  * Add issue search via API (go-gitea#3612)
  * Add repository setting to enable/disable health checks (go-gitea#3607)
  * Emoji Autocomplete (go-gitea#3433)
  * Implements generator cli for secrets (go-gitea#3531)
* ENHANCEMENT
  * Add more webhooks support and refactor webhook templates directory (go-gitea#3929)
  * Add new option to allow only OAuth2/OpenID user registration (go-gitea#3910)
  * Add option to use paged LDAP search when synchronizing users (go-gitea#3895)
  * Symlink icons (go-gitea#1416)
  * Improve release page UI (go-gitea#3693)
  * Add admin dashboard option to run health checks (go-gitea#3606)
  * Add branch link in branch list (go-gitea#3576)
  * Reduce sql query times in retrieveFeeds (go-gitea#3547)
  * Option to enable or disable swagger endpoints (go-gitea#3502)
  * Add missing licenses (go-gitea#3497)
  * Reduce repo indexer disk usage (go-gitea#3452)
  * Enable caching on assets and avatars (go-gitea#3376)
  * Add repository search ordered by stars/forks. Forks column in admin repo list (go-gitea#3969)
  * Add Environment Variables to Docker template (go-gitea#4012)
  * LFS: make HTTP auth period configurable (go-gitea#4035)
  * Add config path as an optionial flag when changing pass via CLI (go-gitea#4184)
  * Refactor User Settings sections (go-gitea#3900)
  * Allow square brackets in external issue patterns (go-gitea#3408)
  * Add Attachment API (go-gitea#3478)
  * Add EnableTimetracking option to app settings (go-gitea#3719)
  * Add config option to enable or disable log executed SQL (go-gitea#3726)
  * Shows total tracked time in issue and milestone list (go-gitea#3341)
* TRANSLATION
  * Improve English grammar and consistency (go-gitea#3614)
* DEPLOYMENT
  * Allow Gitea to run as different USER in Docker (go-gitea#3961)
  * Provide compressed release binaries (go-gitea#3991)
  * Sign release binaries (go-gitea#4188)
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
@delvh delvh removed the type/changelog Adds the changelog for a new Gitea version label Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Release API does not expose attachments
8 participants