Skip to content

Commit 076d550

Browse files
authored
fix bug when skipping archived repos (#169)
1 parent d4a3719 commit 076d550

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

mocks/mocks.go

+10
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ var (
1616
repoName2 = "terratest"
1717
repoName3 = "fetch"
1818
repoName4 = "terraform-kubernetes-helm"
19+
repoName5 = "terraform-google-load-balancer"
1920
)
2021

2122
var (
2223
repoURL1 = "https://github.com/gruntwork-io/terragrunt"
2324
repoURL2 = "https://github.com/gruntwork-io/terratest"
2425
repoURL3 = "https://github.com/gruntwork-io/fetch"
2526
repoURL4 = "https://github.com/gruntwork-io/terraform-kubernetes-helm"
27+
repoURL5 = "https://github.com/gruntwork-io/terraform-google-load-balancer"
2628
)
2729

2830
var archivedFlag = true
@@ -57,6 +59,14 @@ var MockGithubRepositories = []*github.Repository{
5759
HTMLURL: &repoURL4,
5860
Archived: &archivedFlag,
5961
},
62+
{
63+
Owner: &github.User{
64+
Login: &ownerName,
65+
},
66+
Name: &repoName5,
67+
HTMLURL: &repoURL5,
68+
Archived: &archivedFlag,
69+
},
6070
}
6171

6272
// This mocks the PullRequest service in go-github that is used in production to call the associated GitHub endpoint

repository/fetch-repos.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,22 @@ func getReposByOrg(config *config.GitXargsConfig) ([]*github.Repository, error)
9191
}
9292

9393
// github.RepositoryListByOrgOptions doesn't seem to be able to filter out archived repos
94-
// So re-slice the repos list if --skip-archived-repos is passed and the repository is in archived/read-only state
95-
for i, repo := range repos {
96-
if config.SkipArchivedRepos && repo.GetArchived() {
97-
logger.WithFields(logrus.Fields{
98-
"Name": repo.GetFullName(),
99-
}).Debug("Skipping archived repository")
100-
101-
// Track repos to skip because of archived status for our final run report
102-
config.Stats.TrackSingle(stats.ReposArchivedSkipped, repo)
103-
104-
reposToAdd = append(repos[:i], repos[i+1:]...)
105-
} else {
106-
reposToAdd = repos
94+
// So filter the repos list if --skip-archived-repos is passed and the repository is in archived/read-only state
95+
if config.SkipArchivedRepos {
96+
for _, repo := range repos {
97+
if repo.GetArchived() {
98+
logger.WithFields(logrus.Fields{
99+
"Name": repo.GetFullName(),
100+
}).Debug("Skipping archived repository")
101+
102+
// Track repos to skip because of archived status for our final run report
103+
config.Stats.TrackSingle(stats.ReposArchivedSkipped, repo)
104+
} else {
105+
reposToAdd = append(reposToAdd, repo)
106+
}
107107
}
108+
} else {
109+
reposToAdd = repos
108110
}
109111

110112
allRepos = append(allRepos, reposToAdd...)

repository/fetch-repos_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ func TestSkipArchivedRepos(t *testing.T) {
6363

6464
githubRepos, reposByOrgLookupErr := getReposByOrg(config)
6565

66-
assert.Equal(t, len(githubRepos), len(mocks.MockGithubRepositories)-1)
66+
assert.Equal(t, len(githubRepos), len(mocks.MockGithubRepositories)-2)
6767
assert.NoError(t, reposByOrgLookupErr)
6868
}

0 commit comments

Comments
 (0)