mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-07 14:22:06 +00:00
enhance(api): add GitHub-compatible /repos/{owner}/{repo}/commits/{ref} endpoint (#38770)
Gitea currently exposes the endpoint:
`GET /repos/{owner}/{repo}/git/commits/{sha}`
to retrieve a single commit. However, GitHub provides the equivalent
endpoint as:
`GET /repos/{owner}/{repo}/commits/{ref}`
Applications integrating with both GitHub and Gitea must implement
platform-specific logic to use different endpoints, reducing API
compatibility.
Fixes #38225
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
@@ -1484,7 +1484,11 @@ func Routes() *web.Router {
|
||||
Post(reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
|
||||
}, reqRepoReader(unit.TypeCode))
|
||||
m.Group("/commits", func() {
|
||||
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
|
||||
m.Group("", func() {
|
||||
m.Get("", repo.GetAllCommits)
|
||||
m.Get("/{sha}", repo.GetSingleCommit) // GitHub-compatible endpoint
|
||||
m.Get("/{sha}.{diffType:diff|patch}", repo.DownloadCommitDiffOrPatch)
|
||||
}, context.ReferencesGitRepo(true))
|
||||
m.PathGroup("/*", func(g *web.RouterPathGroup) {
|
||||
// Mis-configured reverse proxy might decode the `%2F` to slash ahead, so we need to support both formats (escaped, unescaped) here.
|
||||
// It also matches GitHub's behavior
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
func GetSingleCommit(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/git/commits/{sha} repository repoGetSingleCommit
|
||||
// ---
|
||||
// summary: Get a single commit from a repository
|
||||
// summary: Get a single commit from a repository, it has a GitHub-compatible alias "/repos/{owner}/{repo}/commits/{ref}"
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
|
||||
Reference in New Issue
Block a user