@ -10,6 +10,7 @@ import (
"net/http"
"strconv"
issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@ -323,3 +324,53 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
return
}
}
// GetCommitPullRequest returns the pull request of the commit
func GetCommitPullRequest ( ctx * context . APIContext ) {
// swagger:operation GET /repos/{owner}/{repo}/commits/{sha}/pull repository repoGetCommitPullRequest
// ---
// summary: Get the pull request of the commit
// produces:
// - application/json
// 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: sha
// in: path
// description: SHA of the commit to get
// type: string
// required: true
// responses:
// "200":
// "$ref": "#/responses/PullRequest"
// "404":
// "$ref": "#/responses/notFound"
pr , err := issues_model . GetPullRequestByMergedCommit ( ctx , ctx . Repo . Repository . ID , ctx . Params ( ":sha" ) )
if err != nil {
if issues_model . IsErrPullRequestNotExist ( err ) {
ctx . Error ( http . StatusNotFound , "GetPullRequestByMergedCommit" , err )
} else {
ctx . Error ( http . StatusInternalServerError , "GetPullRequestByIndex" , err )
}
return
}
if err = pr . LoadBaseRepo ( ctx ) ; err != nil {
ctx . Error ( http . StatusInternalServerError , "LoadBaseRepo" , err )
return
}
if err = pr . LoadHeadRepo ( ctx ) ; err != nil {
ctx . Error ( http . StatusInternalServerError , "LoadHeadRepo" , err )
return
}
ctx . JSON ( http . StatusOK , convert . ToAPIPullRequest ( ctx , pr , ctx . Doer ) )
}