Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixes 4762 - Content API for Creating, Updating, Deleting Files #6314
This is the implementation of #4762 -
Dependent on go-gitea/go-sdk#152 for input/output structures. Clone that package into
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
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: