This pull request targets issue #6573.
It provides a new API endpoint: `/api/v1/repos/{org}/{repo}/commits?pageSize=<int>` with a default page size of 30 commits (the same as the UI).
This implementation currently only focuses on the main/master branch of the repository, and does not provide the ability to return commit history for other branches.
- Note: Since the logic for converting a git.Commit to api.Commit had to be used in `GetAllCommits` and `GetSingleCommit`, I decided to pull the code out into a helper function, ` gitCommitToAPICommit(commit, context)`.
* Add new methods
* Use Users.Create to replace previous hack
* Reduce side effect
* Do not clear tables when test failed
* test_users_Authenticate
* Rename constant
* test_users_Create
* test_users_GetByEmail
* test_users_GetByID
* test_users_GetByUsername
This PR groups the contents api endpoint with both `""` and `/*` as
valid URL patterns.
When `""` is the URL pattern, this means that no repo path has'nt been
provided, in which case the path would be the default repo path.
When `"/*"` is the URL pattern, then this would return the contents at
the specified path if it's valid.
Github API v3 is conformant to this behavior and have verified it
locally.
* support API `GET /repos/:owner/:repo/contents/:path`
This PR adds support to #5949:
`GET /repos/:owner/:repo/contents/:path`
Curl:
```bash
curl -H "Authorization: token REDACTED"
http://localhost:3000/api/v1/repos/root/testrepo/contents//master/README.md
-X GET | jq .
```
Curl Response:
```bash
{
"type": "blob",
"size": 12,
"name": "README.md",
"path": "README.md",
"sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/contents/README.md",
"git_url": "70fcb456d4",
"html_url": "70fcb456d4",
"download_url": "http://localhost:3000/api/v1/root/testrepo/raw/README.md",
"_links": {
"git": "70fcb456d4",
"self": "http://localhost:3000/api/v1/repos/root/testrepo/contents/README.md",
"html": "70fcb456d4"
},
"content": "IyB0ZXN0cmVwbwoK"
}
```
* rename - path.go to contents.go
* reorder imports
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* rename struct to repoContents and fix field order
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* rename variable
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* rename GetPathContents to GetContents
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* return on server error
Co-Authored-By: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
* resolve conflicts introduced via git web ui
* make constants as method variables
* handle dir type case last
* fix func and var names
* implement suggested changes in review
* refactor smaller funcs to be part of GetContent
* fix content type check for blob after refactoring
* changes based on suggestions
* read full file, return empty json array
* don't set submoduleURL
* set server err msg to method name
* set target to be blob data for symlinks
* Update contents.go
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>