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

Conversation

richmahn
Copy link
Contributor

@richmahn 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

@GiteaBot GiteaBot 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 Apr 14, 2019
@techknowlogick
Copy link
Member

@lunny changes have been made. Please review.

models/unit_tests.go Outdated Show resolved Hide resolved
models/error.go Outdated Show resolved Hide resolved
modules/gitdata/blob.go Outdated Show resolved Hide resolved
modules/gitdata/blob.go Outdated Show resolved Hide resolved
modules/gitdata/blob.go Outdated Show resolved Hide resolved
lunny
lunny previously requested changes Apr 17, 2019
@@ -6,6 +6,7 @@ package integrations

import (
"bytes"
"code.gitea.io/gitea/modules/base"
Copy link
Member

Choose a reason for hiding this comment

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

import wrong place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dang it, these things keep changing. Going to figure out how to set this in my IDE.

@@ -5,6 +5,7 @@
package migrations

import (
"code.gitea.io/gitea/modules/base"
Copy link
Member

Choose a reason for hiding this comment

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

as above

@lunny
Copy link
Member

lunny commented Apr 17, 2019

And please resolve file conflicted. Otherwise LGTM.

@techknowlogick techknowlogick dismissed lunny’s stale review April 17, 2019 16:06

conflicts resolved

@techknowlogick techknowlogick merged commit 2262811 into go-gitea:master Apr 17, 2019
@lafriks lafriks added the type/changelog Adds the changelog for a new Gitea version label Apr 18, 2019
@bobemoe bobemoe mentioned this pull request Jun 13, 2019
5 tasks
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants