Skip to content

Commit f995bcc

Browse files
cez81lunny
authored andcommitted
Add repo mirror sync API endpoint (#1508)
* API: Add repo mirror sync * Correct error message * Change http status to 200
1 parent 2eeae84 commit f995bcc

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ func RegisterRoutes(m *macaron.Macaron) {
402402
Patch(bind(api.EditReleaseOption{}), repo.EditRelease).
403403
Delete(repo.DeleteRelease)
404404
})
405+
m.Post("/mirror-sync", repo.MirrorSync)
405406
m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
406407
m.Group("/pulls", func() {
407408
m.Combo("").Get(bind(api.ListPullRequestsOptions{}), repo.ListPullRequests).Post(reqRepoWriter(), bind(api.CreatePullRequestOption{}), repo.CreatePullRequest)

routers/api/v1/repo/repo.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,15 @@ func Delete(ctx *context.APIContext) {
269269
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
270270
ctx.Status(204)
271271
}
272+
273+
// MirrorSync adds a mirrored repository to the sync queue
274+
func MirrorSync(ctx *context.APIContext) {
275+
repo := ctx.Repo.Repository
276+
277+
if !ctx.Repo.IsWriter() {
278+
ctx.Error(403, "MirrorSync", "Must have write access")
279+
}
280+
281+
go models.MirrorQueue.Add(repo.ID)
282+
ctx.Status(200)
283+
}

0 commit comments

Comments
 (0)