1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

feat(api): implement branch/commit comparison API (#30349)

- Add new `Compare` struct to represent comparison between two commits
- Introduce new API endpoint `/compare/*` to get commit comparison
information
- Create new file `repo_compare.go` with the `Compare` struct definition
- Add new file `compare.go` in `routers/api/v1/repo` to handle
comparison logic
- Add new file `compare.go` in `routers/common` to define `CompareInfo`
struct
- Refactor `ParseCompareInfo` function to use `common.CompareInfo`
struct
- Update Swagger documentation to include the new API endpoint for
commit comparison
- Remove duplicate `CompareInfo` struct from
`routers/web/repo/compare.go`
- Adjust base path in Swagger template to be relative (`/api/v1`)

GitHub API
https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Bo-Yi Wu
2024-04-16 11:45:04 +08:00
committed by GitHub
parent 3b045ee165
commit c70e442ce4
8 changed files with 250 additions and 14 deletions

View File

@@ -5340,6 +5340,51 @@
}
}
},
"/repos/{owner}/{repo}/compare/{basehead}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Get",
"commit",
"comparison"
],
"summary": "Get commit comparison information",
"operationId": "information",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "string",
"description": "compare two branches or commits",
"name": "basehead",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/Compare"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/contents": {
"get": {
"produces": [
@@ -18717,6 +18762,25 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"Compare": {
"type": "object",
"title": "Compare represents a comparison between two commits.",
"properties": {
"commits": {
"type": "array",
"items": {
"$ref": "#/definitions/Commit"
},
"x-go-name": "Commits"
},
"total_commits": {
"type": "integer",
"format": "int64",
"x-go-name": "TotalCommits"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"ContentsResponse": {
"description": "ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content",
"type": "object",
@@ -24678,6 +24742,12 @@
}
}
},
"Compare": {
"description": "",
"schema": {
"$ref": "#/definitions/Compare"
}
},
"ContentsListResponse": {
"description": "ContentsListResponse",
"schema": {