-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fixes 4762 - Content API for Creating, Updating, Deleting Files #6314
Conversation
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
…content-create-update-delete
@lunny changes have been made. Please review. |
integrations/integration_test.go
Outdated
@@ -6,6 +6,7 @@ package integrations | |||
|
|||
import ( | |||
"bytes" | |||
"code.gitea.io/gitea/modules/base" |
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.
import wrong place
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.
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" |
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.
as above
And please resolve file conflicted. Otherwise LGTM. |
This is the implementation of #4762 -
contents
API to create, update and delete files, as well as thegit/blobs
API so git links in these API additions as well as the existinggit/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 therichmahn: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