-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add push to remote mirror repository #15157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
4e0e107
Added push mirror model.
KN4CK3R 5797f96
Integrated push mirror into queue.
KN4CK3R 00bf264
Moved methods into own file.
KN4CK3R 000cf56
Added basic implementation.
KN4CK3R 5e701eb
Mirror wiki too.
KN4CK3R ecbbc67
Removed duplicated method.
KN4CK3R f6f4dba
Get url for different remotes.
KN4CK3R 2365760
Added migration.
KN4CK3R aff13d6
Unified remote url access.
KN4CK3R ff4b4ab
Add/Remove push mirror remotes.
KN4CK3R 382be07
Prevent hangs with missing credentials.
KN4CK3R bf22cd1
Moved code between files.
KN4CK3R 5604087
Lint
KN4CK3R 84a9bd8
Changed sanitizer interface.
KN4CK3R ca14354
Added push mirror backend methods.
KN4CK3R a9b1961
Fix
KN4CK3R ca2c530
Only update the mirror remote.
KN4CK3R 84d1352
Limit refs on push.
KN4CK3R 806408a
Added UI part.
KN4CK3R 4eed55d
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R 79201d7
Added missing table.
KN4CK3R b78b83e
Delete mirror if repository gets removed.
KN4CK3R 96dab54
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R 07ad389
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R bafeba1
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R c0d3c78
Changed signature. Handle object errors.
KN4CK3R 20de69c
Added upload method.
KN4CK3R 92e2573
Added "upload" unit tests.
KN4CK3R 0d9c384
Added transfer adapter unit tests.
KN4CK3R 5746665
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R 3bc2300
Send correct headers.
KN4CK3R c4ff5d2
Added pushing of LFS objects.
KN4CK3R 0012f34
Go 1.14
KN4CK3R bacae71
Added more logging.
KN4CK3R 0b3e91a
Simpler body handling.
KN4CK3R f2cbd62
Process files in batches to reduce HTTP calls.
KN4CK3R 3688138
Merge branch 'master' into feature-push-mirror
6543 656c347
Fixed unit tests.
KN4CK3R a6088cb
Added created timestamp.
KN4CK3R 1923b51
Fixed name.
KN4CK3R 1eb9c74
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
KN4CK3R 5739008
Fixed invalid column name.
KN4CK3R 980548a
Changed name to prevent xorm auto setting.
KN4CK3R 310fdb9
Remove table header im empty.
KN4CK3R 33d0244
Strip exit code from error message.
KN4CK3R ffaf55c
Added docs page about mirroring.
KN4CK3R 180a61c
Fixed date.
KN4CK3R 835f228
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R b83497b
Use new method.
KN4CK3R 2a01584
Use jsoniter.
KN4CK3R d92a8ba
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 882e958
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 902a730
Fixed merge errors.
KN4CK3R 68e0c00
Use syncPullMirror in test.
KN4CK3R ac879f8
Fixed merge error.
KN4CK3R 65f47da
Moved test to integrations.
KN4CK3R 2bc6102
Added push mirror test.
KN4CK3R d7a3719
Removed NextUpdateUnix.
KN4CK3R dad9adf
and here
KN4CK3R c876f05
Merge branch 'main' into feature-push-mirror
6543 687302a
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R c950877
Merge branch 'main' into feature-push-mirror
6543 c76cdc6
Merge branch 'main' into feature-push-mirror
6543 ec872c0
Merge branch 'main' into feature-push-mirror
6543 4e39abb
Apply suggestions from code review
6543 e482136
Merge branch 'main' into feature-push-mirror
6543 19d7911
Fixed sql error.
KN4CK3R 444b96c
Added test.
KN4CK3R 27b30d6
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R 567dccc
untouch models/migrations/v182.go
6543 c305bca
Merge branch 'main' into feature-push-mirror
6543 9a66e72
Merge branch 'master' into feature-push-mirror
6543 2c05692
`xorm:"text"`
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2021 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 models | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
var ( | ||
// ErrPushMirrorNotExist mirror does not exist error | ||
ErrPushMirrorNotExist = errors.New("PushMirror does not exist") | ||
) | ||
|
||
// PushMirror represents mirror information of a repository. | ||
type PushMirror struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"INDEX"` | ||
Repo *Repository `xorm:"-"` | ||
RemoteName string | ||
|
||
Interval time.Duration | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX"` | ||
NextUpdateUnix timeutil.TimeStamp `xorm:"INDEX"` | ||
LastError string | ||
KN4CK3R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// BeforeInsert will be invoked by XORM before inserting a record | ||
func (m *PushMirror) BeforeInsert() { | ||
if m != nil { | ||
m.UpdatedUnix = timeutil.TimeStampNow() | ||
m.NextUpdateUnix = timeutil.TimeStampNow() | ||
} | ||
} | ||
|
||
// AfterLoad is invoked from XORM after setting the values of all fields of this object. | ||
func (m *PushMirror) AfterLoad(session *xorm.Session) { | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if m == nil { | ||
return | ||
} | ||
|
||
var err error | ||
m.Repo, err = getRepositoryByID(session, m.RepoID) | ||
if err != nil { | ||
log.Error("getRepositoryByID[%d]: %v", m.ID, err) | ||
} | ||
} | ||
|
||
// InsertPushMirror inserts a push-mirror to database | ||
func InsertPushMirror(m *PushMirror) error { | ||
_, err := x.Insert(m) | ||
return err | ||
} | ||
|
||
// UpdatePushMirror updates the push-mirror | ||
func UpdatePushMirror(m *PushMirror) error { | ||
_, err := x.ID(m.ID).AllCols().Update(m) | ||
return err | ||
} | ||
|
||
// DeletePushMirrorByID deletes a push-mirrors by ID | ||
func DeletePushMirrorByID(ID int64) error { | ||
_, err := x.Delete(&PushMirror{ID: ID}) | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
|
||
// DeletePushMirrorsByRepoID deletes all push-mirrors by repoID | ||
func DeletePushMirrorsByRepoID(repoID int64) error { | ||
_, err := x.Delete(&PushMirror{RepoID: repoID}) | ||
return err | ||
} | ||
|
||
// GetPushMirrorByID returns push-mirror information. | ||
func GetPushMirrorByID(ID int64) (*PushMirror, error) { | ||
m := &PushMirror{ID: ID} | ||
has, err := x.Get(m) | ||
6543 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, err | ||
} else if !has { | ||
return nil, ErrPushMirrorNotExist | ||
} | ||
return m, nil | ||
} | ||
|
||
// GetPushMirrorsByRepoID returns push-mirror informations of a repository. | ||
func GetPushMirrorsByRepoID(repoID int64) ([]*PushMirror, error) { | ||
mirrors := make([]*PushMirror, 0, 10) | ||
return mirrors, x.Where("repo_id=?", repoID).Find(&mirrors) | ||
} | ||
|
||
// PushMirrorsIterate iterates all push-mirror repositories. | ||
func PushMirrorsIterate(f func(idx int, bean interface{}) error) error { | ||
return x. | ||
Where("next_update_unix<=?", time.Now().Unix()). | ||
And("next_update_unix!=0"). | ||
Iterate(new(PushMirror), f) | ||
} | ||
|
||
// ScheduleNextUpdate calculates and sets next update time. | ||
func (m *PushMirror) ScheduleNextUpdate() { | ||
if m.Interval != 0 { | ||
m.NextUpdateUnix = timeutil.TimeStampNow().AddDuration(m.Interval) | ||
} else { | ||
m.NextUpdateUnix = 0 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.