-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodeowners.go
More file actions
39 lines (33 loc) · 986 Bytes
/
codeowners.go
File metadata and controls
39 lines (33 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"github.com/google/go-github/v71/github"
)
var defaultCodeOwnerPaths = []string{
"CODEOWNERS",
".github/CODEOWNERS",
"docs/CODEOWNERS",
}
// FetchCodeOwners attempts to retrieve the CODEOWNERS file for the repository.
// If the file cannot be found or is inaccessible due to permissions, the function
// returns nil and logs the reason so policy evaluation can proceed with an empty value.
func (l *GithubReposPlugin) FetchCodeOwners(ctx context.Context, repo *github.Repository) (*github.RepositoryContent, error) {
owner := repo.GetOwner().GetLogin()
name := repo.GetName()
for _, path := range defaultCodeOwnerPaths {
file, _, resp, err := l.githubClient.Repositories.GetContents(ctx, owner, name, path, nil)
if err != nil {
if resp != nil && resp.StatusCode == 404 {
continue
}
if isPermissionError(err) {
return nil, nil
}
return nil, err
}
if file != nil {
return file, nil
}
}
return nil, nil
}