Skip to content

Commit 7e8d5cf

Browse files
committed
Merge endpoints
1 parent b31c831 commit 7e8d5cf

File tree

3 files changed

+15
-91
lines changed

3 files changed

+15
-91
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
937937
m.Group("/git", func() {
938938
m.Group("/commits", func() {
939939
m.Get("/{sha}", repo.GetSingleCommit)
940-
m.Get("/{sha}.diff",
941-
repo.DownloadCommitDiff)
942-
m.Get("/{sha}.patch",
943-
repo.DownloadCommitPatch)
940+
m.Get("/{sha}.{diffType:diff|patch}", repo.DownloadCommitDiffOrPatch)
944941
})
945942
m.Get("/refs", repo.GetGitAllRefs)
946943
m.Get("/refs/*", repo.GetGitRefs)

routers/api/v1/repo/commits.go

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ func GetAllCommits(ctx *context.APIContext) {
214214
ctx.JSON(http.StatusOK, &apiCommits)
215215
}
216216

217-
// DownloadCommitDiff render a commit's raw diff
218-
func DownloadCommitDiff(ctx *context.APIContext) {
219-
// swagger:operation GET /repos/{owner}/{repo}/git/commits/{sha}.diff repository repoDownloadCommitDiff
217+
// DownloadCommitDiffOrPatch render a commit's raw diff or patch
218+
func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
219+
// swagger:operation GET /repos/{owner}/{repo}/git/commits/{sha}.{diffType} repository repoDownloadCommitDiffOrPatch
220220
// ---
221-
// summary: Get a commit diff
221+
// summary: Get a commit's diff or patch
222222
// produces:
223223
// - text/plain
224224
// parameters:
@@ -237,52 +237,22 @@ func DownloadCommitDiff(ctx *context.APIContext) {
237237
// description: SHA of the commit to get
238238
// type: string
239239
// required: true
240+
// - name: diffType
241+
// in: path
242+
// description: whether the output is diff or patch
243+
// type: string
244+
// enum: [diff, patch]
245+
// required: true
240246
// responses:
241247
// "200":
242248
// "$ref": "#/responses/string"
243249
// "404":
244250
// "$ref": "#/responses/notFound"
245-
DownloadCommitDiffOrPatch(ctx, "diff")
246-
}
247-
248-
// DownloadCommitPatch render a commit's raw patch
249-
func DownloadCommitPatch(ctx *context.APIContext) {
250-
// swagger:operation GET /repos/{owner}/{repo}/git/commits/{sha}.patch repository repoDownloadCommitPatch
251-
// ---
252-
// summary: Get a commit patch
253-
// produces:
254-
// - text/plain
255-
// parameters:
256-
// - name: owner
257-
// in: path
258-
// description: owner of the repo
259-
// type: string
260-
// required: true
261-
// - name: repo
262-
// in: path
263-
// description: name of the repo
264-
// type: string
265-
// required: true
266-
// - name: sha
267-
// in: path
268-
// description: SHA of the commit to get
269-
// type: string
270-
// required: true
271-
// responses:
272-
// "200":
273-
// "$ref": "#/responses/string"
274-
// "404":
275-
// "$ref": "#/responses/notFound"
276-
DownloadCommitDiffOrPatch(ctx, "patch")
277-
}
278-
279-
// DownloadCommitDiffOrPatch render a commit's raw diff
280-
func DownloadCommitDiffOrPatch(ctx *context.APIContext, diffType string) {
281251
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
282252
if err := git.GetRawDiff(
283253
repoPath,
284254
ctx.Params(":sha"),
285-
git.RawDiffType(diffType),
255+
git.RawDiffType(ctx.Params(":type")),
286256
ctx.Resp,
287257
); err != nil {
288258
if git.IsErrNotExist(err) {

templates/swagger/v1_json.tmpl

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,59 +3581,16 @@
35813581
}
35823582
}
35833583
},
3584-
"/repos/{owner}/{repo}/git/commits/{sha}.diff": {
3584+
"/repos/{owner}/{repo}/git/commits/{sha}.{diffType}": {
35853585
"get": {
35863586
"produces": [
35873587
"text/plain"
35883588
],
35893589
"tags": [
35903590
"repository"
35913591
],
3592-
"summary": "Get a commit diff",
3593-
"operationId": "repoDownloadCommitDiff",
3594-
"parameters": [
3595-
{
3596-
"type": "string",
3597-
"description": "owner of the repo",
3598-
"name": "owner",
3599-
"in": "path",
3600-
"required": true
3601-
},
3602-
{
3603-
"type": "string",
3604-
"description": "name of the repo",
3605-
"name": "repo",
3606-
"in": "path",
3607-
"required": true
3608-
},
3609-
{
3610-
"type": "string",
3611-
"description": "SHA of the commit to get",
3612-
"name": "sha",
3613-
"in": "path",
3614-
"required": true
3615-
}
3616-
],
3617-
"responses": {
3618-
"200": {
3619-
"$ref": "#/responses/string"
3620-
},
3621-
"404": {
3622-
"$ref": "#/responses/notFound"
3623-
}
3624-
}
3625-
}
3626-
},
3627-
"/repos/{owner}/{repo}/git/commits/{sha}.patch": {
3628-
"get": {
3629-
"produces": [
3630-
"text/plain"
3631-
],
3632-
"tags": [
3633-
"repository"
3634-
],
3635-
"summary": "Get a commit patch",
3636-
"operationId": "repoDownloadCommitPatch",
3592+
"summary": "Get a commit's diff or patch",
3593+
"operationId": "repoDownloadCommitDiffOrPatch",
36373594
"parameters": [
36383595
{
36393596
"type": "string",

0 commit comments

Comments
 (0)