Skip to content

Commit

Permalink
refactor and bump githosts-utils depdencency.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Feb 27, 2024
1 parent 2845006 commit 235eba6
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fmt:
goimports -w . && gofumpt -l -w .

lint:
golangci-lint run --disable lll --disable interfacer --disable gochecknoglobals --disable gochecknoinits --enable wsl --enable revive --enable gosec --enable exhaustruct --enable unused --enable gocritic --enable gofmt --enable goimports --enable misspell --enable unparam --enable goconst --enable wrapcheck
golangci-lint run --disable lll --disable interfacer --disable gochecknoglobals --disable gochecknoinits --enable wsl --enable revive --enable gosec --enable unused --enable gocritic --enable gofmt --enable goimports --enable misspell --enable unparam --enable goconst --enable wrapcheck
ci: lint test

BUILD_TAG := $(shell git describe --tags 2>/dev/null)
Expand Down
39 changes: 39 additions & 0 deletions bitbucket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"os"

"gitlab.com/tozd/go/errors"

"github.com/jonhadfield/githosts-utils"
)

func Bitbucket(backupDir string) *ProviderBackupResults {
logger.Println("backing up BitBucket repos")

bitbucketHost, err := githosts.NewBitBucketHost(githosts.NewBitBucketHostInput{
Caller: appName,
APIURL: os.Getenv(envBitBucketAPIURL),
DiffRemoteMethod: os.Getenv(envBitBucketCompare),
BackupDir: backupDir,
User: os.Getenv(envBitBucketUser),
Key: os.Getenv(envBitBucketKey),
Secret: os.Getenv(envBitBucketSecret),
BackupsToRetain: getBackupsToRetain(envBitBucketBackups),
LogLevel: getLogLevel(),
})
if err != nil {
return &ProviderBackupResults{
Provider: providerNameBitBucket,
Results: githosts.ProviderBackupResult{
BackupResults: []githosts.RepoBackupResults{},
Error: errors.Wrap(err, "failed to create BitBucket host"),
},
}
}

return &ProviderBackupResults{
Provider: providerNameBitBucket,
Results: bitbucketHost.Backup(),
}
}
37 changes: 37 additions & 0 deletions gitea.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"os"

"github.com/jonhadfield/githosts-utils"
"gitlab.com/tozd/go/errors"
)

func Gitea(backupDir string) *ProviderBackupResults {
logger.Println("backing up Gitea repos")

giteaHost, err := githosts.NewGiteaHost(githosts.NewGiteaHostInput{
Caller: appName,
APIURL: os.Getenv(envGiteaAPIURL),
DiffRemoteMethod: os.Getenv(envGiteaCompare),
BackupDir: backupDir,
Token: os.Getenv(envGiteaToken),
Orgs: getOrgsListFromEnvVar(envGiteaOrgs),
BackupsToRetain: getBackupsToRetain(envGiteaBackups),
LogLevel: getLogLevel(),
})
if err != nil {
return &ProviderBackupResults{
Provider: providerNameGitea,
Results: githosts.ProviderBackupResult{
BackupResults: []githosts.RepoBackupResults{},
Error: errors.Wrap(err, "failed to create Gitea host"),
},
}
}

return &ProviderBackupResults{
Provider: providerNameGitea,
Results: giteaHost.Backup(),
}
}
39 changes: 39 additions & 0 deletions github.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"os"

"github.com/jonhadfield/githosts-utils"

"gitlab.com/tozd/go/errors"
)

func GitHub(backupDir string) *ProviderBackupResults {
logger.Println("backing up GitHub repos")

githubHost, err := githosts.NewGitHubHost(githosts.NewGitHubHostInput{
Caller: appName,
APIURL: os.Getenv(envGitHubAPIURL),
DiffRemoteMethod: os.Getenv(envGitHubCompare),
BackupDir: backupDir,
Token: os.Getenv(envGitHubToken),
Orgs: getOrgsListFromEnvVar(envGitHubOrgs),
BackupsToRetain: getBackupsToRetain(envGitHubBackups),
SkipUserRepos: envTrue(envGitHubSkipUserRepos),
LogLevel: getLogLevel(),
})
if err != nil {
return &ProviderBackupResults{
Provider: providerNameGitHub,
Results: githosts.ProviderBackupResult{
BackupResults: []githosts.RepoBackupResults{},
Error: errors.Wrap(err, "failed to create GitHub host"),
},
}
}

return &ProviderBackupResults{
Provider: providerNameGitHub,
Results: githubHost.Backup(),
}
}
40 changes: 40 additions & 0 deletions gitlab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"os"

"gitlab.com/tozd/go/errors"

"github.com/jonhadfield/githosts-utils"
)

func Gitlab(backupDir string) *ProviderBackupResults {
logger.Println("backing up GitLab repos")

var gitlabHost *githosts.GitLabHost

gitlabHost, err := githosts.NewGitLabHost(githosts.NewGitLabHostInput{
Caller: appName,
APIURL: os.Getenv(envGitLabAPIURL),
DiffRemoteMethod: os.Getenv(envGitLabCompare),
BackupDir: backupDir,
Token: os.Getenv(envGitLabToken),
BackupsToRetain: getBackupsToRetain(envGitLabBackups),
ProjectMinAccessLevel: getProjectMinimumAccessLevel(),
LogLevel: getLogLevel(),
})
if err != nil {
return &ProviderBackupResults{
Provider: providerNameGitLab,
Results: githosts.ProviderBackupResult{
BackupResults: []githosts.RepoBackupResults{},
Error: errors.Wrap(err, "failed to create GitLab host"),
},
}
}

return &ProviderBackupResults{
Provider: providerNameGitLab,
Results: gitlabHost.Backup(),
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ toolchain go1.21.0
require (
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/jonhadfield/githosts-utils v0.0.0-20240214205906-bdeb9684d45c
github.com/jonhadfield/githosts-utils v0.0.0-20240227215907-fdbfc9a27143
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
gitlab.com/tozd/go/errors v0.8.1
gopkg.in/h2non/gock.v1 v1.1.2
)

Expand All @@ -20,7 +21,6 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/peterhellberg/link v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gitlab.com/tozd/go/errors v0.8.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxC
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/jonhadfield/githosts-utils v0.0.0-20240214205906-bdeb9684d45c h1:JVRdnCB5SsFyc4D8zhC5FVBJDvayIPL0MZEbau3TL+g=
github.com/jonhadfield/githosts-utils v0.0.0-20240214205906-bdeb9684d45c/go.mod h1:PFx5umZGByGGkaKyaw5E9az/IL8KiVjrDy9kymZQ6Oc=
github.com/jonhadfield/githosts-utils v0.0.0-20240227215907-fdbfc9a27143 h1:A8Kjq6LRh5HQiAGxkzQ99Nd1M4EyHS8eu3m3wurvpMg=
github.com/jonhadfield/githosts-utils v0.0.0-20240227215907-fdbfc9a27143/go.mod h1:2hre3/B2QsIOf6S69L3NCq1kkLu/7+TGFuIwNxDYIH4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
Loading

0 comments on commit 235eba6

Please sign in to comment.