summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/repo_form.go21
-rw-r--r--modules/convert/repository.go8
-rw-r--r--modules/migrations/base/options.go1
-rw-r--r--modules/migrations/gitea_uploader.go1
-rw-r--r--modules/repository/repo.go25
-rw-r--r--modules/structs/repo.go22
6 files changed, 57 insertions, 21 deletions
diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go
index 24c2478fa4..87f2a53510 100644
--- a/modules/auth/repo_form.go
+++ b/modules/auth/repo_form.go
@@ -68,16 +68,17 @@ type MigrateRepoForm struct {
// required: true
UID int64 `json:"uid" binding:"Required"`
// required: true
- RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
- Mirror bool `json:"mirror"`
- Private bool `json:"private"`
- Description string `json:"description" binding:"MaxSize(255)"`
- Wiki bool `json:"wiki"`
- Milestones bool `json:"milestones"`
- Labels bool `json:"labels"`
- Issues bool `json:"issues"`
- PullRequests bool `json:"pull_requests"`
- Releases bool `json:"releases"`
+ RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
+ Mirror bool `json:"mirror"`
+ Private bool `json:"private"`
+ Description string `json:"description" binding:"MaxSize(255)"`
+ Wiki bool `json:"wiki"`
+ Milestones bool `json:"milestones"`
+ Labels bool `json:"labels"`
+ Issues bool `json:"issues"`
+ PullRequests bool `json:"pull_requests"`
+ Releases bool `json:"releases"`
+ MirrorInterval string `json:"mirror_interval"`
}
// Validate validates the fields
diff --git a/modules/convert/repository.go b/modules/convert/repository.go
index 0f470144b4..813201ca68 100644
--- a/modules/convert/repository.go
+++ b/modules/convert/repository.go
@@ -91,6 +91,13 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: true})
+ mirrorInterval := ""
+ if repo.IsMirror {
+ if err := repo.GetMirror(); err == nil {
+ mirrorInterval = repo.Mirror.Interval.String()
+ }
+ }
+
return &api.Repository{
ID: repo.ID,
Owner: ToUser(repo.Owner, mode != models.AccessModeNone, mode >= models.AccessModeAdmin),
@@ -134,5 +141,6 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
AllowSquash: allowSquash,
AvatarURL: repo.AvatarLink(),
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
+ MirrorInterval: mirrorInterval,
}
}
diff --git a/modules/migrations/base/options.go b/modules/migrations/base/options.go
index 3c9b2c22fc..168f9848c8 100644
--- a/modules/migrations/base/options.go
+++ b/modules/migrations/base/options.go
@@ -33,4 +33,5 @@ type MigrateOptions struct {
PullRequests bool
ReleaseAssets bool
MigrateToRepoID int64
+ MirrorInterval string `json:"mirror_interval"`
}
diff --git a/modules/migrations/gitea_uploader.go b/modules/migrations/gitea_uploader.go
index 6118b3b5c1..2c79bd4b0f 100644
--- a/modules/migrations/gitea_uploader.go
+++ b/modules/migrations/gitea_uploader.go
@@ -142,6 +142,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
Private: repo.IsPrivate,
Wiki: opts.Wiki,
Releases: opts.Releases, // if didn't get releases, then sync them from tags
+ MirrorInterval: opts.MirrorInterval,
})
g.repo = r
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 8ecb43ede6..ede714673a 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -127,12 +127,33 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models.
}
if opts.Mirror {
- if err = models.InsertMirror(&models.Mirror{
+ mirrorModel := models.Mirror{
RepoID: repo.ID,
Interval: setting.Mirror.DefaultInterval,
EnablePrune: true,
NextUpdateUnix: timeutil.TimeStampNow().AddDuration(setting.Mirror.DefaultInterval),
- }); err != nil {
+ }
+
+ if opts.MirrorInterval != "" {
+ parsedInterval, err := time.ParseDuration(opts.MirrorInterval)
+ if err != nil {
+ log.Error("Failed to set Interval: %v", err)
+ return repo, err
+ }
+ if parsedInterval == 0 {
+ mirrorModel.Interval = 0
+ mirrorModel.NextUpdateUnix = 0
+ } else if parsedInterval < setting.Mirror.MinInterval {
+ err := fmt.Errorf("Interval %s is set below Minimum Interval of %s", parsedInterval, setting.Mirror.MinInterval)
+ log.Error("Interval: %s is too frequent", opts.MirrorInterval)
+ return repo, err
+ } else {
+ mirrorModel.Interval = parsedInterval
+ mirrorModel.NextUpdateUnix = timeutil.TimeStampNow().AddDuration(parsedInterval)
+ }
+ }
+
+ if err = models.InsertMirror(&mirrorModel); err != nil {
return repo, fmt.Errorf("InsertOne: %v", err)
}
diff --git a/modules/structs/repo.go b/modules/structs/repo.go
index c12f8e1c18..309273d2fa 100644
--- a/modules/structs/repo.go
+++ b/modules/structs/repo.go
@@ -91,6 +91,7 @@ type Repository struct {
AllowSquash bool `json:"allow_squash_merge"`
AvatarURL string `json:"avatar_url"`
Internal bool `json:"internal"`
+ MirrorInterval string `json:"mirror_interval"`
}
// CreateRepoOption options when creating repository
@@ -168,6 +169,8 @@ type EditRepoOption struct {
AllowSquash *bool `json:"allow_squash_merge,omitempty"`
// set to `true` to archive this repository.
Archived *bool `json:"archived,omitempty"`
+ // set to a string like `8h30m0s` to set the mirror interval time
+ MirrorInterval *string `json:"mirror_interval,omitempty"`
}
// CreateBranchRepoOption options when creating a branch in a repository
@@ -249,15 +252,16 @@ type MigrateRepoOptions struct {
AuthPassword string `json:"auth_password"`
AuthToken string `json:"auth_token"`
- Mirror bool `json:"mirror"`
- Private bool `json:"private"`
- Description string `json:"description" binding:"MaxSize(255)"`
- Wiki bool `json:"wiki"`
- Milestones bool `json:"milestones"`
- Labels bool `json:"labels"`
- Issues bool `json:"issues"`
- PullRequests bool `json:"pull_requests"`
- Releases bool `json:"releases"`
+ Mirror bool `json:"mirror"`
+ Private bool `json:"private"`
+ Description string `json:"description" binding:"MaxSize(255)"`
+ Wiki bool `json:"wiki"`
+ Milestones bool `json:"milestones"`
+ Labels bool `json:"labels"`
+ Issues bool `json:"issues"`
+ PullRequests bool `json:"pull_requests"`
+ Releases bool `json:"releases"`
+ MirrorInterval string `json:"mirror_interval"`
}
// TokenAuth represents whether a service type supports token-based auth