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

Fixes 4762 - Content API for Creating, Updating, Deleting Files #6314

Open
wants to merge 65 commits into
base: master
from

Conversation

5 participants
@richmahn
Copy link
Contributor

richmahn commented Mar 12, 2019

This is the implementation of #4762 - contents API to create, update and delete files, as well as the git/blobs API so git links in these API additions as well as the existing git/trees API work.

Dependent on go-gitea/go-sdk#152 for input/output structures. Clone that package into ./vendor/code.gitea.io/sdk of your local copy of gitea for testing and check out the richmahn:feature-4762-api-content-create-update-delete branch.

This PR makes it so BOTH the web interface and these new API routes use the same code when managing file content. Reviewing should be aware of how Create/Update/Delete worked for the web interface works. The function calls from the web routes and the api routes will first massage the input data as it can be different fore each (Example: web interface knows a file has changed in the repo since the edit was made by the last commit ID, where the API goes by the SHA of the file; or the API expects content in base64 encoding and thus must decode it where the web interface does not). Then those functions will call the file_handling module and respond with either a FileResponse (SDK) object or an error. The web & api route functions then decide how to work with the response or error accordingly.

For testing, best to check out this branch richmahn:feature-4762-api-content-create-update-delete for both the main gitea repo and the SDK package (see 2nd paragraph above). Compile and run on your local machine. Then go to your Swagger page to see the new API (starting at: http://localhost:3000/api/swagger#/repository/repoGetContents)

The new APIs are these:

Some things to keep in mind when reviewing and testing: permissions, error messages, response data (both API and web client), and Swagger documentation - feedback welcome.

Note about the API: Even for GET calls using public repos, unlike Github, we require the user be authenticated. So even if you click on a link in the response from one call, such as a blob or tree link, you will need to make that call with authentication (token in header or in URL). For example, I use Postman in testing and I always have to set up the header information if I want to see the results.

A reminder also that most of our API doesn't have much documentation nor much detail (such as there not being a description for an API call, just each parameter). Like most all Gitea API, best to see the corresponding API docs for GitHub:

https://developer.github.com/v3/repos/contents/#get-contents
https://developer.github.com/v3/git/blobs/#get-a-blob

richmahn added some commits Feb 13, 2019

@richmahn

This comment has been minimized.

Copy link
Contributor Author

richmahn commented Mar 12, 2019

This of course is going to fail the build until we get the SDK PR merged and into master and then the master branch merged into this: go-gitea/go-sdk#152

richmahn added some commits Mar 13, 2019

@lunny lunny added this to the 1.9.0 milestone Mar 13, 2019

@lunny lunny added the kind/api label Mar 13, 2019

Show resolved Hide resolved modules/file_handling/content.go Outdated
Show resolved Hide resolved modules/file_handling/file.go Outdated
@richmahn

This comment has been minimized.

Copy link
Contributor Author

richmahn commented Mar 13, 2019

@lunny Fixed those requests you made.

@adelowo

This comment has been minimized.

Copy link
Member

adelowo commented Mar 13, 2019

THIS IS LIT.

richmahn added some commits Mar 14, 2019

@lunny

This comment has been minimized.

Copy link
Member

lunny commented Mar 16, 2019

CI still failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.