mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-30 05:07:06 +08:00
49f9d43afe
Support synchronizing with the push mirrors whenever new commits are pushed or synced from pull mirror. Related Issues: #18220 Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package repo
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unit"
|
|
"code.gitea.io/gitea/modules/context"
|
|
mirror_module "code.gitea.io/gitea/modules/mirror"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
)
|
|
|
|
// MirrorSync adds a mirrored repository to the sync queue
|
|
func MirrorSync(ctx *context.APIContext) {
|
|
// swagger:operation POST /repos/{owner}/{repo}/mirror-sync repository repoMirrorSync
|
|
// ---
|
|
// summary: Sync a mirrored repository
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: owner
|
|
// in: path
|
|
// description: owner of the repo to sync
|
|
// type: string
|
|
// required: true
|
|
// - name: repo
|
|
// in: path
|
|
// description: name of the repo to sync
|
|
// type: string
|
|
// required: true
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/empty"
|
|
// "403":
|
|
// "$ref": "#/responses/forbidden"
|
|
|
|
repo := ctx.Repo.Repository
|
|
|
|
if !ctx.Repo.CanWrite(unit.TypeCode) {
|
|
ctx.Error(http.StatusForbidden, "MirrorSync", "Must have write access")
|
|
}
|
|
|
|
if !setting.Mirror.Enabled {
|
|
ctx.Error(http.StatusBadRequest, "MirrorSync", "Mirror feature is disabled")
|
|
return
|
|
}
|
|
|
|
if _, err := repo_model.GetMirrorByRepoID(ctx, repo.ID); err != nil {
|
|
if errors.Is(err, repo_model.ErrMirrorNotExist) {
|
|
ctx.Error(http.StatusBadRequest, "MirrorSync", "Repository is not a mirror")
|
|
return
|
|
}
|
|
ctx.Error(http.StatusInternalServerError, "MirrorSync", err)
|
|
return
|
|
}
|
|
|
|
mirror_module.AddPullMirrorToQueue(repo.ID)
|
|
|
|
ctx.Status(http.StatusOK)
|
|
}
|