-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fixes #7292 - API File Contents bug #7301
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 #7292 - API File Contents bug #7301
Conversation
Here are some example JSON Responses with the GET URL: No ref: http://localhost:3000/api/v1/repos/root/test/contents/README.md
With branch: http://localhost:3000/api/v1/repos/root/test/contents/README.md?ref=develop
Short commit ID: http://localhost:3000/api/v1/repos/root/test/contents/README.md?ref=b7b2
Long Commit: http://localhost:3000/api/v1/repos/root/test/contents/README.md?ref=b7b2828f27a39a1967e7762b0d4799fe69343652
Tag: http://localhost:3000/api/v1/repos/root/test/contents/README.md?ref=v1
A directory listing using the {dirpath} GET API Endpoint: http://localhost:3000/api/v1/repos/root/test/contents/test3
Entry is a symlink: http://localhost:3000/api/v1/repos/root/test/contents/test3/test1lnk.txt?ref=master
Entry is a submodule: http://localhost:3000/api/v1/repos/root/test/contents/lib/mymodule?ref=master
|
modules/git/repo.go
Outdated
} | ||
|
||
// GetRefType gets the type of the ref based on the string | ||
func (repo *Repository) GetRefType(ref string) RepoRefType { |
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.
Could we return ObjectType on https://github.com/go-gitea/gitea/blob/master/modules/git/repo_object.go#L14 ?
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.
Looking into it. I actually realized I did not have this at all responding like GitHub, especially when it comes to being 4 different types of objects (dir, file, symlink, submodule) that could be returned, as well well as a list of entries. So this is being redone.
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.
Added ObjectBranch and now use those as a way to get the string of a ref. Also moved my GetRefType() into this file.
Codecov Report
@@ Coverage Diff @@
## master #7301 +/- ##
=========================================
Coverage ? 41.25%
=========================================
Files ? 464
Lines ? 63107
Branches ? 0
=========================================
Hits ? 26035
Misses ? 33666
Partials ? 3406
Continue to review full report at Codecov.
|
A few of bugs fixed with the File Content API response, one from issue #7292, but also the COMPLETE functionality that GitHub has for the GET contents API endpoint. Here are bug fixes:
html_url
field hadblob/<ref>/<file>
in the URL. This is how GitHub does it, but Gitea doessrc/<ref type>/<ref>/<file>
, so now the code determines the ref type give and gives the properhtml_url
(as noted in API Repo Get File Content Endpoint returns non-working "blob" HTML_URL #7292)encoding
andcontent
field to the response (see GitHub's file content response: https://developer.github.com/v3/repos/contents/#response-if-content-is-a-file)?ref=[branch|tag|commit]
will work, and the URLs given in the response will properly preserve this.Again, please see how this is closer to what GitHub does: https://developer.github.com/v3/repos/contents/#response-if-content-is-a-file, https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory, https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink and https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
(only difference is that I leave the
target:
,submodule_git_url:
,content:
andencoding:
properties still in the response asnull
even if not used as having a different response objects for each entry type would have been a headache and not work with swagger.)Also note, these changes to this API endpoint shouldn't affect anyone as they haven't been released yet (see my PR for the original endpoint code: #6314 - milestone 1.9.0)
Below in another comment I give some examples. Compare with the old response: https://try.gitea.io/api/v1/repos/richmahn/test/contents/README