mirror of
https://github.com/cooperspencer/gickup.git
synced 2025-05-11 17:55:34 +02:00
added visibility, new create org options and wiki support (#128)
* added visibility, new create org options and wiki support * added gogs * log error instead of fatal
This commit is contained in:
parent
156f6f52e4
commit
2ec9d55f82
5 changed files with 106 additions and 33 deletions
|
@ -163,13 +163,18 @@ destination:
|
|||
# token_file: token.txt # alternatively, specify token in a file
|
||||
user: some-nome # can be a user or an organization, it must exist on the system
|
||||
url: http(s)://url-to-gitea
|
||||
createorg: true # creates organization if it doesn't exist already
|
||||
createorg: true # creates an organization if it doesn't exist already, if no user is set it creates an organization with the name of the original author
|
||||
visibility:
|
||||
repositories: private # private, public, default: private
|
||||
organizations: private # private, limited, public, default: private
|
||||
gogs:
|
||||
- token: some-token
|
||||
# token_file: token.txt # alternatively, specify token in a file
|
||||
user: some-nome # can be a user or an organization, it must exist on the system
|
||||
url: http(s)://url-to-gogs
|
||||
createorg: true # creates organization if it doesn't exist already
|
||||
createorg: true # creates an organization if it doesn't exist already, if no user is set it creates an organization with the name of the original author
|
||||
visibility:
|
||||
repositories: private # private, public, default: private
|
||||
gitlab:
|
||||
- token: some-token
|
||||
# token_file: token.txt # alternatively, specify token in a file
|
||||
|
|
|
@ -6,8 +6,34 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func getOrgVisibility(visibility string) gitea.VisibleType {
|
||||
switch visibility {
|
||||
case "public":
|
||||
return gitea.VisibleTypePublic
|
||||
case "private":
|
||||
return gitea.VisibleTypePrivate
|
||||
case "limited":
|
||||
return gitea.VisibleTypeLimited
|
||||
default:
|
||||
return gitea.VisibleTypePrivate
|
||||
}
|
||||
}
|
||||
|
||||
func getRepoVisibility(visibility string) bool {
|
||||
switch visibility {
|
||||
case "public":
|
||||
return false
|
||||
case "private":
|
||||
return true
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Backup TODO.
|
||||
func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
||||
orgvisibilty := getOrgVisibility(d.Visibility.Organizations)
|
||||
repovisibility := getRepoVisibility(d.Visibility.Repositories)
|
||||
if d.URL == "" {
|
||||
d.URL = "https://gitea.com/"
|
||||
}
|
||||
|
@ -30,13 +56,17 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
Msg(err.Error())
|
||||
}
|
||||
|
||||
if d.User == "" && d.CreateOrg {
|
||||
d.User = r.Owner
|
||||
}
|
||||
|
||||
if d.User != "" {
|
||||
user, _, err = giteaclient.GetUserInfo(d.User)
|
||||
if err != nil {
|
||||
if d.CreateOrg {
|
||||
_, _, err = giteaclient.CreateOrg(gitea.CreateOrgOption{
|
||||
org, _, err := giteaclient.CreateOrg(gitea.CreateOrgOption{
|
||||
Name: d.User,
|
||||
Visibility: gitea.VisibleTypePrivate,
|
||||
Visibility: orgvisibilty,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
|
@ -44,6 +74,8 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
Str("url", d.URL).
|
||||
Msg(err.Error())
|
||||
}
|
||||
user.ID = org.ID
|
||||
user.UserName = org.UserName
|
||||
} else {
|
||||
log.Fatal().
|
||||
Str("stage", "gitea").
|
||||
|
@ -66,6 +98,8 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
Mirror: true,
|
||||
CloneAddr: r.URL,
|
||||
AuthToken: r.Token,
|
||||
Wiki: r.Origin.Wiki,
|
||||
Private: repovisibility,
|
||||
}
|
||||
|
||||
if r.Token == "" {
|
||||
|
@ -76,15 +110,18 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
CloneAddr: r.URL,
|
||||
AuthUsername: r.Origin.User,
|
||||
AuthPassword: r.Origin.Password,
|
||||
Wiki: r.Origin.Wiki,
|
||||
Private: repovisibility,
|
||||
}
|
||||
}
|
||||
|
||||
_, _, err := giteaclient.MigrateRepo(opts)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
log.Error().
|
||||
Str("stage", "gitea").
|
||||
Str("url", d.URL).
|
||||
Msg(err.Error())
|
||||
Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().
|
||||
|
@ -102,10 +139,11 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
|
||||
_, err := giteaclient.MirrorSync(user.UserName, repo.Name)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
log.Error().
|
||||
Str("stage", "gitea").
|
||||
Str("url", d.URL).
|
||||
Msg(err.Error())
|
||||
Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().
|
||||
|
|
26
gogs/gogs.go
26
gogs/gogs.go
|
@ -6,8 +6,20 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func getRepoVisibility(visibility string) bool {
|
||||
switch visibility {
|
||||
case "public":
|
||||
return false
|
||||
case "private":
|
||||
return true
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Backup TODO.
|
||||
func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
||||
repovisibility := getRepoVisibility(d.Visibility.Repositories)
|
||||
log.Info().
|
||||
Str("stage", "gogs").
|
||||
Str("url", d.URL).
|
||||
|
@ -23,6 +35,10 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
Msg(err.Error())
|
||||
}
|
||||
|
||||
if d.User == "" && d.CreateOrg {
|
||||
d.User = r.Owner
|
||||
}
|
||||
|
||||
if d.User != "" {
|
||||
user, err = gogsclient.GetUserInfo(d.User)
|
||||
if err != nil {
|
||||
|
@ -59,6 +75,7 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
Mirror: true,
|
||||
CloneAddr: r.URL,
|
||||
AuthUsername: r.Token,
|
||||
Private: repovisibility,
|
||||
}
|
||||
|
||||
if r.Token == "" {
|
||||
|
@ -69,15 +86,16 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
CloneAddr: r.URL,
|
||||
AuthUsername: r.Origin.User,
|
||||
AuthPassword: r.Origin.Password,
|
||||
Private: repovisibility,
|
||||
}
|
||||
}
|
||||
|
||||
_, err := gogsclient.MigrateRepo(opts)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
log.Error().
|
||||
Str("stage", "gogs").
|
||||
Str("url", d.URL).
|
||||
Msg(err.Error())
|
||||
Err(err)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -91,10 +109,10 @@ func Backup(r types.Repo, d types.GenRepo, dry bool) {
|
|||
|
||||
err := gogsclient.MirrorSync(user.UserName, repo.Name)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
log.Error().
|
||||
Str("stage", "gogs").
|
||||
Str("url", d.URL).
|
||||
Msg(err.Error())
|
||||
Err(err)
|
||||
}
|
||||
|
||||
log.Info().
|
||||
|
|
18
main.go
18
main.go
|
@ -158,18 +158,24 @@ func backup(repos []types.Repo, conf *types.Conf) {
|
|||
}
|
||||
|
||||
for _, d := range conf.Destination.Gitea {
|
||||
gitea.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gitea").Inc()
|
||||
if !strings.HasSuffix(r.Name, ".wiki") {
|
||||
gitea.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gitea").Inc()
|
||||
}
|
||||
}
|
||||
|
||||
for _, d := range conf.Destination.Gogs {
|
||||
gogs.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gogs").Inc()
|
||||
if !strings.HasSuffix(r.Name, ".wiki") {
|
||||
gogs.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gogs").Inc()
|
||||
}
|
||||
}
|
||||
|
||||
for _, d := range conf.Destination.Gitlab {
|
||||
gitlab.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gitlab").Inc()
|
||||
if !strings.HasSuffix(r.Name, ".wiki") {
|
||||
gitlab.Backup(r, d, cli.Dry)
|
||||
prometheus.DestinationBackupsComplete.WithLabelValues("gitlab").Inc()
|
||||
}
|
||||
}
|
||||
|
||||
prometheus.SourceBackupsComplete.WithLabelValues(r.Name).Inc()
|
||||
|
|
|
@ -185,21 +185,27 @@ func (source Source) Count() int {
|
|||
|
||||
// GenRepo Generell Repo.
|
||||
type GenRepo struct {
|
||||
Token string `yaml:"token"`
|
||||
TokenFile string `yaml:"token_file"`
|
||||
User string `yaml:"user"`
|
||||
SSH bool `yaml:"ssh"`
|
||||
SSHKey string `yaml:"sshkey"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
URL string `yaml:"url"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
ExcludeOrgs []string `yaml:"excludeorgs"`
|
||||
Include []string `yaml:"include"`
|
||||
IncludeOrgs []string `yaml:"includeorgs"`
|
||||
Wiki bool `yaml:"wiki"`
|
||||
Starred bool `yaml:"starred"`
|
||||
CreateOrg bool `yaml:"createorg"`
|
||||
Token string `yaml:"token"`
|
||||
TokenFile string `yaml:"token_file"`
|
||||
User string `yaml:"user"`
|
||||
SSH bool `yaml:"ssh"`
|
||||
SSHKey string `yaml:"sshkey"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
URL string `yaml:"url"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
ExcludeOrgs []string `yaml:"excludeorgs"`
|
||||
Include []string `yaml:"include"`
|
||||
IncludeOrgs []string `yaml:"includeorgs"`
|
||||
Wiki bool `yaml:"wiki"`
|
||||
Starred bool `yaml:"starred"`
|
||||
CreateOrg bool `yaml:"createorg"`
|
||||
Visibility Visibility `yaml:"visibility"`
|
||||
}
|
||||
|
||||
type Visibility struct {
|
||||
Repositories string `yaml:"repositories"`
|
||||
Organizations string `yaml:"organizations"`
|
||||
}
|
||||
|
||||
// GetToken TODO.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue