mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 15:24:08 +01:00
Merge endpoints for pull diff/patch (#17104)
this merges the two API endpoints for the PR diff/patch in to one
This commit is contained in:
parent
10108b184e
commit
0fa153f421
3 changed files with 50 additions and 109 deletions
|
@ -897,8 +897,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
|
||||||
m.Group("/{index}", func() {
|
m.Group("/{index}", func() {
|
||||||
m.Combo("").Get(repo.GetPullRequest).
|
m.Combo("").Get(repo.GetPullRequest).
|
||||||
Patch(reqToken(), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
|
Patch(reqToken(), bind(api.EditPullRequestOption{}), repo.EditPullRequest)
|
||||||
m.Get(".diff", repo.DownloadPullDiff)
|
m.Get(".{diffType:diff|patch}", repo.DownloadPullDiffOrPatch)
|
||||||
m.Get(".patch", repo.DownloadPullPatch)
|
|
||||||
m.Post("/update", reqToken(), repo.UpdatePullRequest)
|
m.Post("/update", reqToken(), repo.UpdatePullRequest)
|
||||||
m.Get("/commits", repo.GetPullRequestCommits)
|
m.Get("/commits", repo.GetPullRequestCommits)
|
||||||
m.Combo("/merge").Get(repo.IsPullRequestMerged).
|
m.Combo("/merge").Get(repo.IsPullRequestMerged).
|
||||||
|
|
|
@ -174,72 +174,41 @@ func GetPullRequest(ctx *context.APIContext) {
|
||||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr))
|
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadPullDiff render a pull's raw diff
|
|
||||||
func DownloadPullDiff(ctx *context.APIContext) {
|
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.diff repository repoDownloadPullDiff
|
|
||||||
// ---
|
|
||||||
// summary: Get a pull request diff
|
|
||||||
// produces:
|
|
||||||
// - text/plain
|
|
||||||
// parameters:
|
|
||||||
// - name: owner
|
|
||||||
// in: path
|
|
||||||
// description: owner of the repo
|
|
||||||
// type: string
|
|
||||||
// required: true
|
|
||||||
// - name: repo
|
|
||||||
// in: path
|
|
||||||
// description: name of the repo
|
|
||||||
// type: string
|
|
||||||
// required: true
|
|
||||||
// - name: index
|
|
||||||
// in: path
|
|
||||||
// description: index of the pull request to get
|
|
||||||
// type: integer
|
|
||||||
// format: int64
|
|
||||||
// required: true
|
|
||||||
// responses:
|
|
||||||
// "200":
|
|
||||||
// "$ref": "#/responses/string"
|
|
||||||
// "404":
|
|
||||||
// "$ref": "#/responses/notFound"
|
|
||||||
DownloadPullDiffOrPatch(ctx, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DownloadPullPatch render a pull's raw patch
|
|
||||||
func DownloadPullPatch(ctx *context.APIContext) {
|
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.patch repository repoDownloadPullPatch
|
|
||||||
// ---
|
|
||||||
// summary: Get a pull request patch file
|
|
||||||
// produces:
|
|
||||||
// - text/plain
|
|
||||||
// parameters:
|
|
||||||
// - name: owner
|
|
||||||
// in: path
|
|
||||||
// description: owner of the repo
|
|
||||||
// type: string
|
|
||||||
// required: true
|
|
||||||
// - name: repo
|
|
||||||
// in: path
|
|
||||||
// description: name of the repo
|
|
||||||
// type: string
|
|
||||||
// required: true
|
|
||||||
// - name: index
|
|
||||||
// in: path
|
|
||||||
// description: index of the pull request to get
|
|
||||||
// type: integer
|
|
||||||
// format: int64
|
|
||||||
// required: true
|
|
||||||
// responses:
|
|
||||||
// "200":
|
|
||||||
// "$ref": "#/responses/string"
|
|
||||||
// "404":
|
|
||||||
// "$ref": "#/responses/notFound"
|
|
||||||
DownloadPullDiffOrPatch(ctx, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
// DownloadPullDiffOrPatch render a pull's raw diff or patch
|
||||||
func DownloadPullDiffOrPatch(ctx *context.APIContext, patch bool) {
|
func DownloadPullDiffOrPatch(ctx *context.APIContext) {
|
||||||
|
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}.{diffType} repository repoDownloadPullDiffOrPatch
|
||||||
|
// ---
|
||||||
|
// summary: Get a pull request diff or patch
|
||||||
|
// produces:
|
||||||
|
// - text/plain
|
||||||
|
// parameters:
|
||||||
|
// - name: owner
|
||||||
|
// in: path
|
||||||
|
// description: owner of the repo
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// - name: repo
|
||||||
|
// in: path
|
||||||
|
// description: name of the repo
|
||||||
|
// type: string
|
||||||
|
// required: true
|
||||||
|
// - name: index
|
||||||
|
// in: path
|
||||||
|
// description: index of the pull request to get
|
||||||
|
// type: integer
|
||||||
|
// format: int64
|
||||||
|
// required: true
|
||||||
|
// - name: diffType
|
||||||
|
// in: path
|
||||||
|
// description: whether the output is diff or patch
|
||||||
|
// type: string
|
||||||
|
// enum: [diff, patch]
|
||||||
|
// required: true
|
||||||
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// "$ref": "#/responses/string"
|
||||||
|
// "404":
|
||||||
|
// "$ref": "#/responses/notFound"
|
||||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrPullRequestNotExist(err) {
|
if models.IsErrPullRequestNotExist(err) {
|
||||||
|
@ -249,6 +218,12 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext, patch bool) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var patch bool
|
||||||
|
if ctx.Params(":diffType") == "diff" {
|
||||||
|
patch = false
|
||||||
|
} else {
|
||||||
|
patch = true
|
||||||
|
}
|
||||||
|
|
||||||
if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch); err != nil {
|
if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch); err != nil {
|
||||||
ctx.InternalServerError(err)
|
ctx.InternalServerError(err)
|
||||||
|
|
|
@ -7357,7 +7357,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/repos/{owner}/{repo}/pulls/{index}.diff": {
|
"/repos/{owner}/{repo}/pulls/{index}.{diffType}": {
|
||||||
"get": {
|
"get": {
|
||||||
"produces": [
|
"produces": [
|
||||||
"text/plain"
|
"text/plain"
|
||||||
|
@ -7365,8 +7365,8 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"repository"
|
"repository"
|
||||||
],
|
],
|
||||||
"summary": "Get a pull request diff",
|
"summary": "Get a pull request diff or patch",
|
||||||
"operationId": "repoDownloadPullDiff",
|
"operationId": "repoDownloadPullDiffOrPatch",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -7389,48 +7389,15 @@
|
||||||
"name": "index",
|
"name": "index",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"$ref": "#/responses/string"
|
|
||||||
},
|
},
|
||||||
"404": {
|
|
||||||
"$ref": "#/responses/notFound"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/repos/{owner}/{repo}/pulls/{index}.patch": {
|
|
||||||
"get": {
|
|
||||||
"produces": [
|
|
||||||
"text/plain"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"repository"
|
|
||||||
],
|
|
||||||
"summary": "Get a pull request patch file",
|
|
||||||
"operationId": "repoDownloadPullPatch",
|
|
||||||
"parameters": [
|
|
||||||
{
|
{
|
||||||
|
"enum": [
|
||||||
|
"diff",
|
||||||
|
"patch"
|
||||||
|
],
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "owner of the repo",
|
"description": "whether the output is diff or patch",
|
||||||
"name": "owner",
|
"name": "diffType",
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "name of the repo",
|
|
||||||
"name": "repo",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "integer",
|
|
||||||
"format": "int64",
|
|
||||||
"description": "index of the pull request to get",
|
|
||||||
"name": "index",
|
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue