forked from forgejo/forgejo
Add new API endpoints for push mirrors management (#19841)
- Add a new push mirror to specific repository - Sync now ( send all the changes to the configured push mirrors ) - Get list of all push mirrors of a repository - Get a push mirror by ID - Delete push mirror by ID Signed-off-by: Mohamed Sekour <mohamed.sekour@exfo.com> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
e819da0837
commit
0e61a74e5a
14 changed files with 787 additions and 44 deletions
|
@ -90,7 +90,7 @@ func SettingsCtxData(ctx *context.Context) {
|
|||
}
|
||||
ctx.Data["StatsIndexerStatus"] = status
|
||||
}
|
||||
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(ctx.Repo.Repository.ID)
|
||||
pushMirrors, _, err := repo_model.GetPushMirrorsByRepoID(ctx, ctx.Repo.Repository.ID, db.ListOptions{})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPushMirrorsByRepoID", err)
|
||||
return
|
||||
|
@ -284,7 +284,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
m, err := selectPushMirrorByForm(form, repo)
|
||||
m, err := selectPushMirrorByForm(ctx, form, repo)
|
||||
if err != nil {
|
||||
ctx.NotFound("", nil)
|
||||
return
|
||||
|
@ -305,7 +305,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
// as an error on the UI for this action
|
||||
ctx.Data["Err_RepoName"] = nil
|
||||
|
||||
m, err := selectPushMirrorByForm(form, repo)
|
||||
m, err := selectPushMirrorByForm(ctx, form, repo)
|
||||
if err != nil {
|
||||
ctx.NotFound("", nil)
|
||||
return
|
||||
|
@ -316,7 +316,7 @@ func SettingsPost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if err = repo_model.DeletePushMirrorByID(m.ID); err != nil {
|
||||
if err = repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{ID: m.ID, RepoID: m.RepoID}); err != nil {
|
||||
ctx.ServerError("DeletePushMirrorByID", err)
|
||||
return
|
||||
}
|
||||
|
@ -364,14 +364,14 @@ func SettingsPost(ctx *context.Context) {
|
|||
SyncOnCommit: form.PushMirrorSyncOnCommit,
|
||||
Interval: interval,
|
||||
}
|
||||
if err := repo_model.InsertPushMirror(m); err != nil {
|
||||
if err := repo_model.InsertPushMirror(ctx, m); err != nil {
|
||||
ctx.ServerError("InsertPushMirror", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := mirror_service.AddPushMirrorRemote(ctx, m, address); err != nil {
|
||||
if err := repo_model.DeletePushMirrorByID(m.ID); err != nil {
|
||||
log.Error("DeletePushMirrorByID %v", err)
|
||||
if err := repo_model.DeletePushMirrors(ctx, repo_model.PushMirrorOptions{ID: m.ID, RepoID: m.RepoID}); err != nil {
|
||||
log.Error("DeletePushMirrors %v", err)
|
||||
}
|
||||
ctx.ServerError("AddPushMirrorRemote", err)
|
||||
return
|
||||
|
@ -1222,13 +1222,13 @@ func SettingsDeleteAvatar(ctx *context.Context) {
|
|||
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
|
||||
}
|
||||
|
||||
func selectPushMirrorByForm(form *forms.RepoSettingForm, repo *repo_model.Repository) (*repo_model.PushMirror, error) {
|
||||
func selectPushMirrorByForm(ctx *context.Context, form *forms.RepoSettingForm, repo *repo_model.Repository) (*repo_model.PushMirror, error) {
|
||||
id, err := strconv.ParseInt(form.PushMirrorID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushMirrors, err := repo_model.GetPushMirrorsByRepoID(repo.ID)
|
||||
pushMirrors, _, err := repo_model.GetPushMirrorsByRepoID(ctx, repo.ID, db.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue