@@ -3,21 +3,24 @@ package git_backup
33import (
44 "context"
55 "fmt"
6- "github.com/google/go-github/v43/github"
7- "golang.org/x/oauth2"
86 "log"
97 "net/url"
8+ "slices"
109 "strings"
10+
11+ "github.com/google/go-github/v43/github"
12+ "golang.org/x/oauth2"
1113)
1214
1315type GithubConfig struct {
14- JobName string `yaml:"job_name"`
15- AccessToken string `yaml:"access_token"`
16- URL string `yaml:"url,omitempty"`
17- Starred * bool `yaml:"starred,omitempty"`
18- OrgMember * bool `yaml:"org_member,omitempty"`
19- Collaborator * bool `yaml:"collaborator,omitempty"`
20- Owned * bool `yaml:"owned,omitempty"`
16+ JobName string `yaml:"job_name"`
17+ AccessToken string `yaml:"access_token"`
18+ URL string `yaml:"url,omitempty"`
19+ Starred * bool `yaml:"starred,omitempty"`
20+ OrgMember * bool `yaml:"org_member,omitempty"`
21+ Collaborator * bool `yaml:"collaborator,omitempty"`
22+ Owned * bool `yaml:"owned,omitempty"`
23+ Exclude []string `yaml:"exclude,omitempty"`
2124 client * github.Client
2225}
2326
@@ -39,16 +42,24 @@ func (c *GithubConfig) ListRepositories() ([]*Repository, error) {
3942 if err != nil {
4043 return nil , err
4144 }
42- out := make ([]* Repository , len (repos ))
43- for i , repo := range repos {
45+ out := make ([]* Repository , 0 , len (repos ))
46+ for _ , repo := range repos {
4447 gitUrl , err := url .Parse (* repo .CloneURL )
4548 if err != nil {
4649 return out , err
4750 }
4851 gitUrl .User = url .UserPassword ("github" , c .AccessToken )
49- out [i ] = & Repository {
50- FullName : * repo .FullName ,
51- GitURL : * gitUrl ,
52+
53+ isExcluded := slices .ContainsFunc (c .Exclude , func (s string ) bool {
54+ return strings .EqualFold (s , * repo .FullName )
55+ })
56+ if isExcluded {
57+ log .Printf ("Skipping excluded repository: %s" , * repo .FullName )
58+ } else {
59+ out = append (out , & Repository {
60+ FullName : * repo .FullName ,
61+ GitURL : * gitUrl ,
62+ })
5263 }
5364 }
5465 return out , nil
0 commit comments