mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-01 14:25:11 +08:00
parent
1ef74004a2
commit
737c947287
|
@ -1274,6 +1274,8 @@ func Routes() *web.Route {
|
||||||
m.Group("/{ref}", func() {
|
m.Group("/{ref}", func() {
|
||||||
m.Get("/status", repo.GetCombinedCommitStatusByRef)
|
m.Get("/status", repo.GetCombinedCommitStatusByRef)
|
||||||
m.Get("/statuses", repo.GetCommitStatusesByRef)
|
m.Get("/statuses", repo.GetCommitStatusesByRef)
|
||||||
|
}, context.ReferencesGitRepo())
|
||||||
|
m.Group("/{sha}", func() {
|
||||||
m.Get("/pull", repo.GetCommitPullRequest)
|
m.Get("/pull", repo.GetCommitPullRequest)
|
||||||
}, context.ReferencesGitRepo())
|
}, context.ReferencesGitRepo())
|
||||||
}, reqRepoReader(unit.TypeCode))
|
}, reqRepoReader(unit.TypeCode))
|
||||||
|
|
|
@ -325,11 +325,11 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCommitPullRequest returns the pull request of the commit
|
// GetCommitPullRequest returns the merged pull request of the commit
|
||||||
func GetCommitPullRequest(ctx *context.APIContext) {
|
func GetCommitPullRequest(ctx *context.APIContext) {
|
||||||
// swagger:operation GET /repos/{owner}/{repo}/commits/{sha}/pull repository repoGetCommitPullRequest
|
// swagger:operation GET /repos/{owner}/{repo}/commits/{sha}/pull repository repoGetCommitPullRequest
|
||||||
// ---
|
// ---
|
||||||
// summary: Get the pull request of the commit
|
// summary: Get the merged pull request of the commit
|
||||||
// produces:
|
// produces:
|
||||||
// - application/json
|
// - application/json
|
||||||
// parameters:
|
// parameters:
|
||||||
|
@ -354,7 +354,7 @@ func GetCommitPullRequest(ctx *context.APIContext) {
|
||||||
// "404":
|
// "404":
|
||||||
// "$ref": "#/responses/notFound"
|
// "$ref": "#/responses/notFound"
|
||||||
|
|
||||||
pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.Params(":sha"))
|
pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.Params("sha"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if issues_model.IsErrPullRequestNotExist(err) {
|
if issues_model.IsErrPullRequestNotExist(err) {
|
||||||
ctx.Error(http.StatusNotFound, "GetPullRequestByMergedCommit", err)
|
ctx.Error(http.StatusNotFound, "GetPullRequestByMergedCommit", err)
|
||||||
|
|
2
templates/swagger/v1_json.tmpl
generated
2
templates/swagger/v1_json.tmpl
generated
|
@ -5386,7 +5386,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"repository"
|
"repository"
|
||||||
],
|
],
|
||||||
"summary": "Get the pull request of the commit",
|
"summary": "Get the merged pull request of the commit",
|
||||||
"operationId": "repoGetCommitPullRequest",
|
"operationId": "repoGetCommitPullRequest",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -334,3 +334,19 @@ func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAPICommitPullRequest(t *testing.T) {
|
||||||
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||||
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
|
|
||||||
|
ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository)
|
||||||
|
|
||||||
|
mergedCommitSHA := "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3"
|
||||||
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token)
|
||||||
|
ctx.Session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
invalidCommitSHA := "abcd1234abcd1234abcd1234abcd1234abcd1234"
|
||||||
|
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token)
|
||||||
|
ctx.Session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user