Skip to content

Commit

Permalink
lint: remove duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Jul 9, 2023
1 parent 1f998bf commit 3aa6aa2
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
3 changes: 2 additions & 1 deletion bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
bitbucketEnvVarKey = "BITBUCKET_KEY"
bitbucketEnvVarSecret = "BITBUCKET_SECRET"
bitbucketEnvVarUser = "BITBUCKET_USER"
bitbucketDomain = "bitbucket.com"
)

type NewBitBucketHostInput struct {
Expand Down Expand Up @@ -147,7 +148,7 @@ func (bb BitbucketHost) describeRepos() (dRO describeReposOutput) {
Name: r.Name,
HTTPSUrl: "https://bitbucket.org/" + r.FullName + ".git",
PathWithNameSpace: r.FullName,
Domain: "bitbucket.com",
Domain: bitbucketDomain,
}

repos = append(repos, repo)
Expand Down
8 changes: 4 additions & 4 deletions bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func TestPublicBitbucketRepositoryRefsCompare(t *testing.T) {
require.NoError(t, err)

bbHost.Backup()
expectedPathOne := filepath.Join(bbHost.BackupDir, "bitbucket.com", "go-soba", "repo0")
expectedPathOne := filepath.Join(bbHost.BackupDir, bitbucketDomain, "go-soba", "repo0")
require.DirExists(t, expectedPathOne)
dirOneEntries, err := dirContents(expectedPathOne)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo0\.\d{14}\.bundle$`), dirOneEntries[0].Name())

expectedPathTwo := filepath.Join(bbHost.BackupDir, "bitbucket.com", "teamsoba", "teamsobarepoone")
expectedPathTwo := filepath.Join(bbHost.BackupDir, bitbucketDomain, "teamsoba", "teamsobarepoone")
require.DirExists(t, expectedPathTwo)
dirTwoEntries, err := dirContents(expectedPathTwo)
require.NoError(t, err)
Expand Down Expand Up @@ -106,13 +106,13 @@ func TestPublicBitbucketRepositoryCloneCompare(t *testing.T) {

bbHost.Backup()

expectedPathOne := filepath.Join(bbHost.BackupDir, "bitbucket.com", "go-soba", "repo0")
expectedPathOne := filepath.Join(bbHost.BackupDir, bitbucketDomain, "go-soba", "repo0")
require.DirExists(t, expectedPathOne)
dirOneEntries, err := dirContents(expectedPathOne)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo0\.\d{14}\.bundle$`), dirOneEntries[0].Name())

expectedPathTwo := filepath.Join(bbHost.BackupDir, "bitbucket.com", "teamsoba", "teamsobarepoone")
expectedPathTwo := filepath.Join(bbHost.BackupDir, bitbucketDomain, "teamsoba", "teamsobarepoone")
require.DirExists(t, expectedPathTwo)
dirTwoEntries, err := dirContents(expectedPathTwo)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestRenameInvalidBundle(t *testing.T) {
resetBackups()

backupDir := os.Getenv(envVarGitBackupDir)
dfDir := path.Join(backupDir, "github.com", "go-soba", "repo0")
dfDir := path.Join(backupDir, gitHubDomain, "go-soba", "repo0")
require.NoError(t, os.MkdirAll(dfDir, 0o755))
dfName := "repo0.20200401111111.bundle"
dfPath := path.Join(dfDir, dfName)
Expand Down
4 changes: 2 additions & 2 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestPruneBackups(t *testing.T) {
}
}()

dfDir := path.Join(backupDir, "github.com", "go-soba", "repo0")
dfDir := path.Join(backupDir, gitHubDomain, "go-soba", "repo0")
assert.NoError(t, os.MkdirAll(dfDir, 0o755), fmt.Sprintf("failed to create dummy files dir: %s", dfDir))

dummyFiles := []string{"repo0.20200401111111.bundle", "repo0.20200201010111.bundle", "repo0.20200501010111.bundle", "repo0.20200401011111.bundle", "repo0.20200601011111.bundle"}
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestPruneBackupsWithNonBundleFiles(t *testing.T) {
}
}()

dfDir := path.Join(backupDir, "github.com", "go-soba", "repo0")
dfDir := path.Join(backupDir, gitHubDomain, "go-soba", "repo0")
assert.NoError(t, os.MkdirAll(dfDir, 0o755), fmt.Sprintf("failed to create dummy files dir: %s", dfDir))

dummyFiles := []string{"repo0.20200401111111.bundle", "repo0.20200201010111.bundle", "repo0.20200501010111.bundle", "repo0.20200401011111.bundle", "repo0.20200601011111.bundle", "repo0.20200601011111.bundle.lock"}
Expand Down
5 changes: 3 additions & 2 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const (
gitHubCallSize = 100
githubEnvVarCallSize = "GITHUB_CALL_SIZE"
gitHubDomain = "github.com"
)

type NewGitHubHostInput struct {
Expand Down Expand Up @@ -221,7 +222,7 @@ func (gh *GitHubHost) describeGithubUserRepos() []repository {
SSHUrl: repo.Node.SSHURL,
HTTPSUrl: repo.Node.URL,
PathWithNameSpace: repo.Node.NameWithOwner,
Domain: "github.com",
Domain: gitHubDomain,
})
}

Expand Down Expand Up @@ -316,7 +317,7 @@ func (gh *GitHubHost) describeGithubOrgRepos(orgName string) []repository {
SSHUrl: repo.Node.SSHURL,
HTTPSUrl: repo.Node.URL,
PathWithNameSpace: repo.Node.NameWithOwner,
Domain: "github.com",
Domain: gitHubDomain,
})
}

Expand Down
16 changes: 8 additions & 8 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ func TestPublicGitHubRepositoryBackup(t *testing.T) {

ghHost.Backup()

expectedPathOne := filepath.Join(backupDIR, "github.com", "go-soba", "repo0")
expectedPathOne := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo0")
require.DirExists(t, expectedPathOne)
dirOneEntries, err := dirContents(expectedPathOne)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo0\.\d{14}\.bundle$`), dirOneEntries[0].Name())

expectedPathTwo := filepath.Join(backupDIR, "github.com", "go-soba", "repo1")
expectedPathTwo := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo1")
require.DirExists(t, expectedPathTwo)
dirTwoEntries, err := dirContents(expectedPathTwo)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo1\.\d{14}\.bundle$`), dirTwoEntries[0].Name())

expectedPathThree := filepath.Join(backupDIR, "github.com", "go-soba", "repo2")
expectedPathThree := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo2")
require.NoDirExists(t, expectedPathThree)
}

Expand Down Expand Up @@ -124,19 +124,19 @@ func TestSinglePublicGitHubOrgRepoBackups(t *testing.T) {

ghHost.Backup()

expectedPathOne := filepath.Join(backupDIR, "github.com", "go-soba", "repo0")
expectedPathOne := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo0")
require.DirExists(t, expectedPathOne)
dirOneEntries, err := dirContents(expectedPathOne)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo0\.\d{14}\.bundle$`), dirOneEntries[0].Name())

expectedPathTwo := filepath.Join(backupDIR, "github.com", "go-soba", "repo1")
expectedPathTwo := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo1")
require.DirExists(t, expectedPathTwo)
dirTwoEntries, err := dirContents(expectedPathTwo)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo1\.\d{14}\.bundle$`), dirTwoEntries[0].Name())

expectedPathThree := filepath.Join(backupDIR, "github.com", "Nudelmesse", "public1")
expectedPathThree := filepath.Join(backupDIR, gitHubDomain, "Nudelmesse", "public1")
require.DirExists(t, expectedPathThree)
dirThreeEntries, err := dirContents(expectedPathThree)
require.NoError(t, err)
Expand Down Expand Up @@ -198,13 +198,13 @@ func TestPublicGitHubOrgRepoBackups(t *testing.T) {

ghHost.Backup()

expectedPathOne := filepath.Join(backupDIR, "github.com", "go-soba", "repo0")
expectedPathOne := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo0")
require.DirExists(t, expectedPathOne)
dirOneEntries, err := dirContents(expectedPathOne)
require.NoError(t, err)
require.Regexp(t, regexp.MustCompile(`^repo0\.\d{14}\.bundle$`), dirOneEntries[0].Name())

expectedPathTwo := filepath.Join(backupDIR, "github.com", "go-soba", "repo1")
expectedPathTwo := filepath.Join(backupDIR, gitHubDomain, "go-soba", "repo1")
require.DirExists(t, expectedPathTwo)
dirTwoEntries, err := dirContents(expectedPathTwo)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
// GitLabDefaultMinimumProjectAccessLevel https://docs.gitlab.com/ee/user/permissions.html#roles
GitLabDefaultMinimumProjectAccessLevel = 20
gitLabDomain = "gitlab.com"
)

type gitlabUser struct {
Expand Down Expand Up @@ -221,7 +222,7 @@ func (gl *GitLabHost) getAllProjectRepositories(client http.Client) (repos []rep
PathWithNameSpace: project.PathWithNameSpace,
HTTPSUrl: project.HTTPSURL,
SSHUrl: project.SSHURL,
Domain: "gitlab.com",
Domain: gitLabDomain,
}

repos = append(repos, repo)
Expand Down
8 changes: 4 additions & 4 deletions gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestPublicGitLabRepositoryBackupCloneMethod(t *testing.T) {
require.NoError(t, err)

gl.Backup()
expectedSubProjectOnePath := filepath.Join(backupDIR, "gitlab.com", "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, "gitlab.com", "soba-test", "soba-sub", "soba-sub-project-two")
expectedSubProjectOnePath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-two")
require.DirExists(t, expectedSubProjectOnePath)
require.DirExists(t, expectedSubProjectTwoPath)
projectOneEntries, err := dirContents(expectedSubProjectOnePath)
Expand Down Expand Up @@ -68,8 +68,8 @@ func TestPublicGitLabRepositoryBackupRefsMethod(t *testing.T) {
require.NoError(t, err)

gl.Backup()
expectedSubProjectOnePath := filepath.Join(backupDIR, "gitlab.com", "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, "gitlab.com", "soba-test", "soba-sub", "soba-sub-project-two")
expectedSubProjectOnePath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-one")
expectedSubProjectTwoPath := filepath.Join(backupDIR, gitLabDomain, "soba-test", "soba-sub", "soba-sub-project-two")
require.DirExists(t, expectedSubProjectOnePath)
require.DirExists(t, expectedSubProjectTwoPath)
projectOneEntries, err := dirContents(expectedSubProjectOnePath)
Expand Down

0 comments on commit 3aa6aa2

Please sign in to comment.