mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Fix sync fork for consistency (#33147)
Fixes #33145 An integration test could be added. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -1190,6 +1190,7 @@ func Routes() *web.Router {
|
||||
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)
|
||||
m.Combo("/forks").Get(repo.ListForks).
|
||||
Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
|
||||
m.Post("/merge-upstream", reqToken(), mustNotBeArchived, reqRepoWriter(unit.TypeCode), bind(api.MergeUpstreamRequest{}), repo.MergeUpstream)
|
||||
m.Group("/branches", func() {
|
||||
m.Get("", repo.ListBranches)
|
||||
m.Get("/*", repo.GetBranch)
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
@@ -1186,3 +1187,47 @@ func UpdateBranchProtectionPriories(ctx *context.APIContext) {
|
||||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func MergeUpstream(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/merge-upstream repository repoMergeUpstream
|
||||
// ---
|
||||
// summary: Merge a branch from upstream
|
||||
// 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: body
|
||||
// in: body
|
||||
// schema:
|
||||
// "$ref": "#/definitions/MergeUpstreamRequest"
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/MergeUpstreamResponse"
|
||||
// "400":
|
||||
// "$ref": "#/responses/error"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.MergeUpstreamRequest)
|
||||
mergeStyle, err := repo_service.MergeUpstream(ctx, ctx.Doer, ctx.Repo.Repository, form.Branch)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.Error(http.StatusBadRequest, "MergeUpstream", err)
|
||||
return
|
||||
} else if errors.Is(err, util.ErrNotExist) {
|
||||
ctx.Error(http.StatusNotFound, "MergeUpstream", err)
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, "MergeUpstream", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &api.MergeUpstreamResponse{MergeStyle: mergeStyle})
|
||||
}
|
||||
|
@@ -448,3 +448,15 @@ type swaggerCompare struct {
|
||||
// in:body
|
||||
Body api.Compare `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response MergeUpstreamRequest
|
||||
type swaggerMergeUpstreamRequest struct {
|
||||
// in:body
|
||||
Body api.MergeUpstreamRequest `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response MergeUpstreamResponse
|
||||
type swaggerMergeUpstreamResponse struct {
|
||||
// in:body
|
||||
Body api.MergeUpstreamResponse `json:"body"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user