mirror of
https://github.com/harness/drone.git
synced 2025-05-20 10:59:56 +08:00
[maint] api for PR metadata added (#319)
This commit is contained in:
parent
821610a375
commit
fd08fa9775
41
internal/api/handler/pullreq/pr_metadata.go
Normal file
41
internal/api/handler/pullreq/pr_metadata.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package pullreq
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/harness/gitness/internal/api/controller/pullreq"
|
||||
"github.com/harness/gitness/internal/api/render"
|
||||
"github.com/harness/gitness/internal/api/request"
|
||||
)
|
||||
|
||||
// HandleMetadata returns a http.HandlerFunc that returns PR metadata.
|
||||
func HandleMetadata(pullreqCtrl *pullreq.Controller) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
session, _ := request.AuthSessionFrom(ctx)
|
||||
|
||||
repoRef, err := request.GetRepoRefFromPath(r)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
pullreqNumber, err := request.GetPullReqNumberFromPath(r)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
pr, err := pullreqCtrl.Find(ctx, session, repoRef, pullreqNumber)
|
||||
if err != nil {
|
||||
render.TranslatedUserError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
render.JSON(w, http.StatusOK, pr.Stats)
|
||||
}
|
||||
}
|
@ -441,7 +441,7 @@ func pullReqOperations(reflector *openapi3.Reflector) {
|
||||
opMetaData.WithTags("pullreq")
|
||||
opMetaData.WithMapOfAnything(map[string]interface{}{"operationId": "pullReqMetaData"})
|
||||
_ = reflector.SetRequest(&opMetaData, new(pullReqRequest), http.MethodGet)
|
||||
_ = reflector.SetStringResponse(&opMetaData, http.StatusOK, "text/plain")
|
||||
_ = reflector.SetJSONResponse(&opMetaData, new(types.PullReqStats), http.StatusOK)
|
||||
_ = reflector.SetJSONResponse(&opMetaData, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&opMetaData, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&opMetaData, new(usererror.Error), http.StatusForbidden)
|
||||
|
@ -270,6 +270,7 @@ func SetupPullReq(r chi.Router, pullreqCtrl *pullreq.Controller) {
|
||||
r.Post("/merge", handlerpullreq.HandleMerge(pullreqCtrl))
|
||||
r.Get("/diff", handlerpullreq.HandleRawDiff(pullreqCtrl))
|
||||
r.Get("/commits", handlerpullreq.HandleCommits(pullreqCtrl))
|
||||
r.Get("/metadata", handlerpullreq.HandleMetadata(pullreqCtrl))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user