@@ -3,21 +3,24 @@ package git_backup
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/google/go-github/v43/github"
7
- "golang.org/x/oauth2"
8
6
"log"
9
7
"net/url"
8
+ "slices"
10
9
"strings"
10
+
11
+ "github.com/google/go-github/v43/github"
12
+ "golang.org/x/oauth2"
11
13
)
12
14
13
15
type 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"`
21
24
client * github.Client
22
25
}
23
26
@@ -39,16 +42,24 @@ func (c *GithubConfig) ListRepositories() ([]*Repository, error) {
39
42
if err != nil {
40
43
return nil , err
41
44
}
42
- out := make ([]* Repository , len (repos ))
43
- for i , repo := range repos {
45
+ out := make ([]* Repository , 0 , len (repos ))
46
+ for _ , repo := range repos {
44
47
gitUrl , err := url .Parse (* repo .CloneURL )
45
48
if err != nil {
46
49
return out , err
47
50
}
48
51
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
+ })
52
63
}
53
64
}
54
65
return out , nil
0 commit comments