99)
1010
1111func ShouldRemoveContent (ctx context.Context , client * githubv4.Client , username , owner , repo string ) (bool , error ) {
12- isPrivate , err := IsPrivateRepo (ctx , client , owner , repo )
12+ isPrivate , hasPushAccess , err := repoAccessInfo (ctx , client , username , owner , repo )
1313 if err != nil {
1414 return false , err
1515 }
@@ -18,21 +18,18 @@ func ShouldRemoveContent(ctx context.Context, client *githubv4.Client, username,
1818 if isPrivate {
1919 return false , nil
2020 }
21- hasPushAccess , err := HasPushAccess (ctx , client , username , owner , repo )
22- if err != nil {
23- return false , err
24- }
2521
2622 return ! hasPushAccess , nil
2723}
2824
29- func HasPushAccess (ctx context.Context , client * githubv4.Client , username , owner , repo string ) (bool , error ) {
25+ func repoAccessInfo (ctx context.Context , client * githubv4.Client , username , owner , repo string ) (bool , bool , error ) {
3026 if client == nil {
31- return false , fmt .Errorf ("nil GraphQL client" )
27+ return false , false , fmt .Errorf ("nil GraphQL client" )
3228 }
3329
3430 var query struct {
3531 Repository struct {
32+ IsPrivate githubv4.Boolean
3633 Collaborators struct {
3734 Edges []struct {
3835 Permission githubv4.String
@@ -52,7 +49,7 @@ func HasPushAccess(ctx context.Context, client *githubv4.Client, username, owner
5249
5350 err := client .Query (ctx , & query , variables )
5451 if err != nil {
55- return false , fmt .Errorf ("failed to query user permissions : %w" , err )
52+ return false , false , fmt .Errorf ("failed to query repository access info : %w" , err )
5653 }
5754
5855 // Check if the user has push access
@@ -67,30 +64,5 @@ func HasPushAccess(ctx context.Context, client *githubv4.Client, username, owner
6764 }
6865 }
6966
70- return hasPush , nil
71- }
72-
73- // IsPrivateRepo checks if a repository is private using GraphQL
74- func IsPrivateRepo (ctx context.Context , client * githubv4.Client , owner , repo string ) (bool , error ) {
75- if client == nil {
76- return false , fmt .Errorf ("nil GraphQL client" )
77- }
78-
79- var query struct {
80- Repository struct {
81- IsPrivate githubv4.Boolean
82- } `graphql:"repository(owner: $owner, name: $name)"`
83- }
84-
85- variables := map [string ]interface {}{
86- "owner" : githubv4 .String (owner ),
87- "name" : githubv4 .String (repo ),
88- }
89-
90- err := client .Query (ctx , & query , variables )
91- if err != nil {
92- return false , fmt .Errorf ("failed to query repository visibility: %w" , err )
93- }
94-
95- return bool (query .Repository .IsPrivate ), nil
67+ return bool (query .Repository .IsPrivate ), hasPush , nil
9668}
0 commit comments