feat: add repo create release
This commit is contained in:
parent
a1bc451d3e
commit
63e9d93f9b
|
@ -281,6 +281,44 @@ func (r restApi) handlerUpdateIssueComment(w http.ResponseWriter, request *http.
|
||||||
r.respond(w, http.StatusOK, commentResponse)
|
r.respond(w, http.StatusOK, commentResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r restApi) handlerCreateRelease(w http.ResponseWriter, request *http.Request) {
|
||||||
|
vars := mux.Vars(request)
|
||||||
|
owner := vars["owner"]
|
||||||
|
repo := vars["repo"]
|
||||||
|
|
||||||
|
client := r.getClientOrError(w)
|
||||||
|
|
||||||
|
if client == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ghRelease := github.RepositoryRelease{}
|
||||||
|
|
||||||
|
if err := r.parseJsonBody(request, &ghRelease); err != nil {
|
||||||
|
http.Error(w, "Failed to parse request body", http.StatusBadRequest)
|
||||||
|
r.logger.Error("Failed to parse request body", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
release := gitea.CreateReleaseOption{
|
||||||
|
TagName: ghRelease.GetTagName(),
|
||||||
|
Target: ghRelease.GetTargetCommitish(),
|
||||||
|
Title: ghRelease.GetName(),
|
||||||
|
Note: ghRelease.GetBody(),
|
||||||
|
IsDraft: ghRelease.GetDraft(),
|
||||||
|
IsPrerelease: ghRelease.GetPrerelease(),
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseResponse, r2, err := client.CreateRelease(owner, repo, release)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Failed to create release", http.StatusInternalServerError)
|
||||||
|
r.logger.Error("Failed to create release", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r.sendPagingHeaders(w, r2)
|
||||||
|
r.respond(w, http.StatusCreated, releaseResponse)
|
||||||
|
}
|
||||||
|
|
||||||
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{})
|
||||||
|
@ -305,6 +343,9 @@ func setupRestRoutes(params RouteParams) {
|
||||||
r.HandleFunc("/repos/{owner}/{repo}/issues/{issue_number}/comments", restApi.handleGetIssueComments).Methods("GET")
|
r.HandleFunc("/repos/{owner}/{repo}/issues/{issue_number}/comments", restApi.handleGetIssueComments).Methods("GET")
|
||||||
r.HandleFunc("/repos/{owner}/{repo}/issues/{issue_number}/comments", restApi.handlerCreateIssueComment).Methods("POST")
|
r.HandleFunc("/repos/{owner}/{repo}/issues/{issue_number}/comments", restApi.handlerCreateIssueComment).Methods("POST")
|
||||||
r.HandleFunc("/repos/{owner}/{repo}/issues/comments/{comment_id}", restApi.handlerUpdateIssueComment).Methods("PATCH")
|
r.HandleFunc("/repos/{owner}/{repo}/issues/comments/{comment_id}", restApi.handlerUpdateIssueComment).Methods("PATCH")
|
||||||
|
|
||||||
|
// Repo Release routes
|
||||||
|
r.HandleFunc("/repos/{owner}/{repo}/releases", restApi.handlerCreateRelease).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
restRouter := r.PathPrefix("/api").Subrouter()
|
restRouter := r.PathPrefix("/api").Subrouter()
|
||||||
|
|
Loading…
Reference in New Issue