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

Conversation

7 participants
@jonasfranz
Copy link
Member

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
Add Attachment API
* 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 referenced this pull request Feb 8, 2018

Merged

Add Attachment API #90

1 of 1 task complete
Add unit tests for new attachment functions
Fix comments

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

This comment has been minimized.

Copy link
Member

lafriks commented Feb 9, 2018

Go lint fails with error

@tboerger tboerger added the lgtm/need 2 label Feb 9, 2018

root and others added some commits Feb 9, 2018

root
Update vendor.json
Signed-off-by: Jonas Franz <info@jonasfranz.software>
remove version of sdk
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Fix unit tests
Add missing license header

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

This comment has been minimized.

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.

jonasfranz added some commits Feb 9, 2018

Add CreateReleaseAttachment
Add EditReleaseAttachment
Add DeleteReleaseAttachment

Signed-off-by: Jonas Franz <info@jonasfranz.software>
Add filename query parameter for choosing another name for an attachment
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"

This comment has been minimized.

@lunny

lunny Feb 10, 2018

Member

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)

This comment has been minimized.

@lunny

lunny Feb 10, 2018

Member

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

This comment has been minimized.

@jonasfranz

jonasfranz Feb 10, 2018

Member

What do you propose alternatively?

This comment has been minimized.

@lunny

lunny Feb 15, 2018

Member

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

jonasfranz added some commits Feb 10, 2018

Fix order of imports
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Restricting updatable attachment columns
Signed-off-by: Jonas Franz <info@jonasfranz.software>
gofmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
@lunny

lunny approved these changes Feb 26, 2018

jonasfranz added some commits Mar 2, 2018

Updating go-sdk and regenerating swagger
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Merge remote-tracking branch 'origin/711-releases-api' into 711-relea…
…ses-api

# Conflicts:
#	vendor/code.gitea.io/sdk/gitea/attachment.go
#	vendor/vendor.json
Add missing file of go-sdk
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Change origin of code.gitea.io/sdk to code.gitea.io/sdk
Update code.gitea.io/sdk

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

This comment has been minimized.

Copy link
Member

jonasfranz commented Mar 2, 2018

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

jonasfranz added some commits Mar 2, 2018

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

This comment has been minimized.

@thehowl

thehowl Mar 3, 2018

Member

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

This comment has been minimized.

@jonasfranz

jonasfranz Mar 3, 2018

Member

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

@thehowl
Copy link
Member

thehowl left a comment

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)

This comment has been minimized.

@thehowl

This comment has been minimized.

@jonasfranz

jonasfranz Mar 4, 2018

Member

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())

This comment has been minimized.

@thehowl

This comment has been minimized.

@jonasfranz

jonasfranz Mar 3, 2018

Member

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": {

This comment has been minimized.

@thehowl

thehowl Mar 3, 2018

Member

And swagger.json needs to be regenerated.

jonasfranz added some commits Mar 4, 2018

Update swagger
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 == "" {

This comment has been minimized.

@appleboy

appleboy Mar 5, 2018

Member

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
}

jonasfranz added some commits Mar 5, 2018

@tboerger tboerger added lgtm/done and removed lgtm/need 1 labels Mar 5, 2018

@appleboy

This comment has been minimized.

Copy link
Member

appleboy commented Mar 5, 2018

@thehowl need your approval.

@thehowl

thehowl approved these changes Mar 5, 2018

@appleboy appleboy merged commit 9a5e628 into go-gitea:master Mar 6, 2018

3 checks passed

Codacy/PR Quality Review Good work! A positive pull request.
Details
approvals/lgtm this commit looks good
continuous-integration/drone/pr the build was successful
Details

@jonasfranz jonasfranz deleted the jonasfranz:711-releases-api branch Mar 6, 2018

@techknowlogick techknowlogick referenced this pull request Mar 19, 2018

Open

Issue API and Attachments #3690

0 of 4 tasks complete
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea"
"errors"

This comment has been minimized.

@lunny

lunny Mar 28, 2018

Member

wrong import order

This comment has been minimized.

@jonasfranz

jonasfranz Mar 28, 2018

Member

This PR is already merged.

This comment has been minimized.

@lunny

lunny Mar 29, 2018

Member

maybe another PR to fix that.

@sapk sapk referenced this pull request Apr 17, 2018

Open

GET vs POST swagger.json #3501

@lafriks lafriks added the changelog label Jul 3, 2018

aswild added a commit to aswild/gitea that referenced this pull request Jul 6, 2018

Merge tag 'v1.5.0-rc1' into wild/v1.5
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment