Skip to content

Commit 50dc9c6

Browse files
JakobDevHenry Goodman
authored and
Henry Goodman
committed
Don't run push mirrors for archived repos (go-gitea#27140)
Fixes https://codeberg.org/forgejo/forgejo/issues/612 At the moment push mirrors are still run if a repo is archived. This PR fixes this.
1 parent c7e6ca8 commit 50dc9c6

File tree

5 files changed

+191
-181
lines changed

5 files changed

+191
-181
lines changed

models/repo/pushmirror.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ func GetPushMirrorsSyncedOnCommit(ctx context.Context, repoID int64) ([]*PushMir
121121
// PushMirrorsIterate iterates all push-mirror repositories.
122122
func PushMirrorsIterate(ctx context.Context, limit int, f func(idx int, bean any) error) error {
123123
sess := db.GetEngine(ctx).
124-
Where("last_update + (`interval` / ?) <= ?", time.Second, time.Now().Unix()).
125-
And("`interval` != 0").
124+
Table("push_mirror").
125+
Join("INNER", "`repository`", "`repository`.id = `push_mirror`.repo_id").
126+
Where("`push_mirror`.last_update + (`push_mirror`.`interval` / ?) <= ?", time.Second, time.Now().Unix()).
127+
And("`push_mirror`.`interval` != 0").
128+
And("`repository`.is_archived = ?", false).
126129
OrderBy("last_update ASC")
127130
if limit > 0 {
128131
sess = sess.Limit(limit)

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,7 @@ settings.archive.error = An error occurred while trying to archive the repo. See
23872387
settings.archive.error_ismirror = You cannot archive a mirrored repo.
23882388
settings.archive.branchsettings_unavailable = Branch settings are not available if the repo is archived.
23892389
settings.archive.tagsettings_unavailable = Tag settings are not available if the repo is archived.
2390+
settings.archive.mirrors_unavailable = Mirrors are not available if the repo is archived.
23902391
settings.unarchive.button = Unarchive repo
23912392
settings.unarchive.header = Unarchive this repo
23922393
settings.unarchive.text = Unarchiving the repo will restore its ability to receive commits and pushes, as well as new issues and pull-requests.

routers/api/v1/api.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1181,13 +1181,13 @@ func Routes() *web.Route {
11811181
Delete(reqToken(), reqRepoWriter(unit.TypeReleases), repo.DeleteReleaseByTag)
11821182
})
11831183
}, reqRepoReader(unit.TypeReleases))
1184-
m.Post("/mirror-sync", reqToken(), reqRepoWriter(unit.TypeCode), repo.MirrorSync)
1185-
m.Post("/push_mirrors-sync", reqAdmin(), reqToken(), repo.PushMirrorSync)
1184+
m.Post("/mirror-sync", reqToken(), reqRepoWriter(unit.TypeCode), mustNotBeArchived, repo.MirrorSync)
1185+
m.Post("/push_mirrors-sync", reqAdmin(), reqToken(), mustNotBeArchived, repo.PushMirrorSync)
11861186
m.Group("/push_mirrors", func() {
11871187
m.Combo("").Get(repo.ListPushMirrors).
1188-
Post(bind(api.CreatePushMirrorOption{}), repo.AddPushMirror)
1188+
Post(mustNotBeArchived, bind(api.CreatePushMirrorOption{}), repo.AddPushMirror)
11891189
m.Combo("/{name}").
1190-
Delete(repo.DeletePushMirrorByRemoteName).
1190+
Delete(mustNotBeArchived, repo.DeletePushMirrorByRemoteName).
11911191
Get(repo.GetPushMirrorByName)
11921192
}, reqAdmin(), reqToken())
11931193

routers/web/repo/setting/setting.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func SettingsPost(ctx *context.Context) {
185185
ctx.Redirect(repo.Link() + "/settings")
186186

187187
case "mirror":
188-
if !setting.Mirror.Enabled || !repo.IsMirror {
188+
if !setting.Mirror.Enabled || !repo.IsMirror || repo.IsArchived {
189189
ctx.NotFound("", nil)
190190
return
191191
}
@@ -278,7 +278,7 @@ func SettingsPost(ctx *context.Context) {
278278
ctx.Redirect(repo.Link() + "/settings")
279279

280280
case "mirror-sync":
281-
if !setting.Mirror.Enabled || !repo.IsMirror {
281+
if !setting.Mirror.Enabled || !repo.IsMirror || repo.IsArchived {
282282
ctx.NotFound("", nil)
283283
return
284284
}
@@ -306,7 +306,7 @@ func SettingsPost(ctx *context.Context) {
306306
ctx.Redirect(repo.Link() + "/settings")
307307

308308
case "push-mirror-update":
309-
if !setting.Mirror.Enabled {
309+
if !setting.Mirror.Enabled || repo.IsArchived {
310310
ctx.NotFound("", nil)
311311
return
312312
}
@@ -343,7 +343,7 @@ func SettingsPost(ctx *context.Context) {
343343
ctx.Redirect(repo.Link() + "/settings")
344344

345345
case "push-mirror-remove":
346-
if !setting.Mirror.Enabled {
346+
if !setting.Mirror.Enabled || repo.IsArchived {
347347
ctx.NotFound("", nil)
348348
return
349349
}
@@ -372,7 +372,7 @@ func SettingsPost(ctx *context.Context) {
372372
ctx.Redirect(repo.Link() + "/settings")
373373

374374
case "push-mirror-add":
375-
if setting.Mirror.DisableNewPush {
375+
if setting.Mirror.DisableNewPush || repo.IsArchived {
376376
ctx.NotFound("", nil)
377377
return
378378
}

0 commit comments

Comments
 (0)