Skip to content

Commit c551629

Browse files
authored
Fix backing up starred GitHub repos when starred is false (#5)
* Only list starred GitHub repositories if starred is true * Fix repo count
1 parent 18d0eed commit c551629

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
backup/
22
git-backup.yml
33
.idea/
4-
git-backup
4+
git-backup

cmd/git-backup/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func main() {
5353
os.Exit(100)
5454
}
5555
}
56+
repoCount++
5657
}
57-
repoCount++
5858
}
5959
log.Printf("Backed up %d repositories in %s, encountered %d errors", repoCount, time.Now().Sub(backupStart), errors)
6060

github.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,21 @@ func (c *GithubConfig) getAllRepos() ([]*github.Repository, error) {
107107
return all, err
108108
}
109109

110-
for repos, response, apiErr := c.getStarredRepos(1); true; repos, response, apiErr = c.getStarredRepos(response.NextPage) {
111-
if apiErr != nil {
112-
err = apiErr
113-
break
114-
} else {
115-
all = append(all, repos...)
116-
}
117-
118-
if len(repos) == 0 || response.NextPage == 0 {
119-
break
110+
if *c.Starred {
111+
for repos, response, apiErr := c.getStarredRepos(1); true; repos, response, apiErr = c.getStarredRepos(response.NextPage) {
112+
if apiErr != nil {
113+
err = apiErr
114+
break
115+
} else {
116+
all = append(all, repos...)
117+
}
118+
119+
if len(repos) == 0 || response.NextPage == 0 {
120+
break
121+
}
120122
}
121123
}
124+
122125
return all, err
123126
}
124127

0 commit comments

Comments
 (0)