Skip to content

Commit 0fa153f

Browse files
authored
Merge endpoints for pull diff/patch (#17104)
this merges the two API endpoints for the PR diff/patch in to one
1 parent 10108b1 commit 0fa153f

File tree

3 files changed

+23
-82
lines changed

3 files changed

+23
-82
lines changed

routers/api/v1/api.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
897897
m.Group("/{index}", func() {
898898
m.Combo("").Get(repo.GetPullRequest).
899899
Patch(reqToken(), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
900-
m.Get(".diff", repo.DownloadPullDiff)
901-
m.Get(".patch", repo.DownloadPullPatch)
900+
m.Get(".{diffType:diff|patch}", repo.DownloadPullDiffOrPatch)
902901
m.Post("/update", reqToken(), repo.UpdatePullRequest)
903902
m.Get("/commits", repo.GetPullRequestCommits)
904903
m.Combo("/merge").Get(repo.IsPullRequestMerged).

routers/api/v1/repo/pull.go

+13-38
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func GetPullRequest(ctx *context.APIContext) {
174174
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr))
175175
}
176176

177-
// DownloadPullDiff render a pull's raw diff
178-
func DownloadPullDiff(ctx *context.APIContext) {
179-
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.diff repository repoDownloadPullDiff
177+
// DownloadPullDiffOrPatch render a pull's raw diff or patch
178+
func DownloadPullDiffOrPatch(ctx *context.APIContext) {
179+
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.{diffType} repository repoDownloadPullDiffOrPatch
180180
// ---
181-
// summary: Get a pull request diff
181+
// summary: Get a pull request diff or patch
182182
// produces:
183183
// - text/plain
184184
// parameters:
@@ -198,48 +198,17 @@ func DownloadPullDiff(ctx *context.APIContext) {
198198
// type: integer
199199
// format: int64
200200
// required: true
201-
// responses:
202-
// "200":
203-
// "$ref": "#/responses/string"
204-
// "404":
205-
// "$ref": "#/responses/notFound"
206-
DownloadPullDiffOrPatch(ctx, false)
207-
}
208-
209-
// DownloadPullPatch render a pull's raw patch
210-
func DownloadPullPatch(ctx *context.APIContext) {
211-
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.patch repository repoDownloadPullPatch
212-
// ---
213-
// summary: Get a pull request patch file
214-
// produces:
215-
// - text/plain
216-
// parameters:
217-
// - name: owner
218-
// in: path
219-
// description: owner of the repo
220-
// type: string
221-
// required: true
222-
// - name: repo
201+
// - name: diffType
223202
// in: path
224-
// description: name of the repo
203+
// description: whether the output is diff or patch
225204
// type: string
226-
// required: true
227-
// - name: index
228-
// in: path
229-
// description: index of the pull request to get
230-
// type: integer
231-
// format: int64
205+
// enum: [diff, patch]
232206
// required: true
233207
// responses:
234208
// "200":
235209
// "$ref": "#/responses/string"
236210
// "404":
237211
// "$ref": "#/responses/notFound"
238-
DownloadPullDiffOrPatch(ctx, true)
239-
}
240-
241-
// DownloadPullDiffOrPatch render a pull's raw diff or patch
242-
func DownloadPullDiffOrPatch(ctx *context.APIContext, patch bool) {
243212
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
244213
if err != nil {
245214
if models.IsErrPullRequestNotExist(err) {
@@ -249,6 +218,12 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext, patch bool) {
249218
}
250219
return
251220
}
221+
var patch bool
222+
if ctx.Params(":diffType") == "diff" {
223+
patch = false
224+
} else {
225+
patch = true
226+
}
252227

253228
if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch); err != nil {
254229
ctx.InternalServerError(err)

templates/swagger/v1_json.tmpl

+9-42
Original file line numberDiff line numberDiff line change
@@ -7357,16 +7357,16 @@
73577357
}
73587358
}
73597359
},
7360-
"/repos/{owner}/{repo}/pulls/{index}.diff": {
7360+
"/repos/{owner}/{repo}/pulls/{index}.{diffType}": {
73617361
"get": {
73627362
"produces": [
73637363
"text/plain"
73647364
],
73657365
"tags": [
73667366
"repository"
73677367
],
7368-
"summary": "Get a pull request diff",
7369-
"operationId": "repoDownloadPullDiff",
7368+
"summary": "Get a pull request diff or patch",
7369+
"operationId": "repoDownloadPullDiffOrPatch",
73707370
"parameters": [
73717371
{
73727372
"type": "string",
@@ -7389,48 +7389,15 @@
73897389
"name": "index",
73907390
"in": "path",
73917391
"required": true
7392-
}
7393-
],
7394-
"responses": {
7395-
"200": {
7396-
"$ref": "#/responses/string"
7397-
},
7398-
"404": {
7399-
"$ref": "#/responses/notFound"
7400-
}
7401-
}
7402-
}
7403-
},
7404-
"/repos/{owner}/{repo}/pulls/{index}.patch": {
7405-
"get": {
7406-
"produces": [
7407-
"text/plain"
7408-
],
7409-
"tags": [
7410-
"repository"
7411-
],
7412-
"summary": "Get a pull request patch file",
7413-
"operationId": "repoDownloadPullPatch",
7414-
"parameters": [
7415-
{
7416-
"type": "string",
7417-
"description": "owner of the repo",
7418-
"name": "owner",
7419-
"in": "path",
7420-
"required": true
74217392
},
74227393
{
7394+
"enum": [
7395+
"diff",
7396+
"patch"
7397+
],
74237398
"type": "string",
7424-
"description": "name of the repo",
7425-
"name": "repo",
7426-
"in": "path",
7427-
"required": true
7428-
},
7429-
{
7430-
"type": "integer",
7431-
"format": "int64",
7432-
"description": "index of the pull request to get",
7433-
"name": "index",
7399+
"description": "whether the output is diff or patch",
7400+
"name": "diffType",
74347401
"in": "path",
74357402
"required": true
74367403
}

0 commit comments

Comments
 (0)