feat: add pull request create
This commit is contained in:
parent
63e9d93f9b
commit
bf9e062644
|
@ -319,6 +319,42 @@ func (r restApi) handlerCreateRelease(w http.ResponseWriter, request *http.Reque
|
||||||
r.respond(w, http.StatusCreated, releaseResponse)
|
r.respond(w, http.StatusCreated, releaseResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r restApi) handlerCreatePullRequest(w http.ResponseWriter, request *http.Request) {
|
||||||
|
vars := mux.Vars(request)
|
||||||
|
owner := vars["owner"]
|
||||||
|
repo := vars["repo"]
|
||||||
|
|
||||||
|
client := r.getClientOrError(w)
|
||||||
|
|
||||||
|
if client == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ghPullRequest := github.NewPullRequest{}
|
||||||
|
|
||||||
|
if err := r.parseJsonBody(request, &ghPullRequest); err != nil {
|
||||||
|
http.Error(w, "Failed to parse request body", http.StatusBadRequest)
|
||||||
|
r.logger.Error("Failed to parse request body", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
pullRequest := gitea.CreatePullRequestOption{
|
||||||
|
Title: ghPullRequest.GetTitle(),
|
||||||
|
Head: ghPullRequest.GetHead(),
|
||||||
|
Base: ghPullRequest.GetBase(),
|
||||||
|
Body: ghPullRequest.GetBody(),
|
||||||
|
}
|
||||||
|
|
||||||
|
pullRequestResponse, r2, err := client.CreatePullRequest(owner, repo, pullRequest)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Failed to create pull request", http.StatusInternalServerError)
|
||||||
|
r.logger.Error("Failed to create pull request", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r.sendPagingHeaders(w, r2)
|
||||||
|
r.respond(w, http.StatusCreated, pullRequestResponse)
|
||||||
|
}
|
||||||
|
|
||||||
func (r restApi) parseJsonBody(request *http.Request, obj interface{}) error {
|
func (r restApi) parseJsonBody(request *http.Request, obj interface{}) error {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
obj = make(map[string]interface{})
|
obj = make(map[string]interface{})
|
||||||
|
@ -346,6 +382,9 @@ func setupRestRoutes(params RouteParams) {
|
||||||
|
|
||||||
// Repo Release routes
|
// Repo Release routes
|
||||||
r.HandleFunc("/repos/{owner}/{repo}/releases", restApi.handlerCreateRelease).Methods("POST")
|
r.HandleFunc("/repos/{owner}/{repo}/releases", restApi.handlerCreateRelease).Methods("POST")
|
||||||
|
|
||||||
|
// Pull Request routes
|
||||||
|
r.HandleFunc("/repos/{owner}/{repo}/pulls", restApi.handlerCreatePullRequest).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
restRouter := r.PathPrefix("/api").Subrouter()
|
restRouter := r.PathPrefix("/api").Subrouter()
|
||||||
|
|
Loading…
Reference in New Issue