diff --git a/internal/config/config.go b/internal/config/config.go index 81b755a..4415724 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,12 +2,13 @@ package config // Config defines the config for all aspects of the bot type Config struct { - GithubToken string `yaml:"github_token"` - InternalTeam string `yaml:"internal_team"` - SkipUsers []string `yaml:"skip_users"` - SkipUsersMap map[string]bool - LabelConfig `yaml:",inline"` - CheckRepos []CheckRepo `yaml:"check_repos"` + GithubToken string `yaml:"github_token"` + InternalTeam string `yaml:"internal_team"` + InternalTeamIgnoredUsers []string `yaml:"internal_team_ignored_users"` + SkipUsers []string `yaml:"skip_users"` + SkipUsersMap map[string]bool + LabelConfig `yaml:",inline"` + CheckRepos []CheckRepo `yaml:"check_repos"` } // LabelConfig is the configuration options specific to labeling PRs diff --git a/internal/github/checkPendingCI.go b/internal/github/checkPendingCI.go index 91cc54e..b70b143 100644 --- a/internal/github/checkPendingCI.go +++ b/internal/github/checkPendingCI.go @@ -21,7 +21,10 @@ type PendingPR struct { // CheckForPendingCI returns a list of PR URLs that are ready for CI to run but haven't started yet. func CheckForPendingCI(ctx context.Context, githubClient *github.Client, cfg *config.Config) ([]PendingPR, error) { - teamMembers, _ := GetTeamMemberList(githubClient, cfg.InternalTeam) + teamMembers, err := GetTeamMemberList(githubClient, cfg.InternalTeam, cfg.InternalTeamIgnoredUsers) + if err != nil { + return nil, err + } var pendingPRs []PendingPR for _, fullRepo := range cfg.CheckRepos { diff --git a/internal/github/checkStalePRs.go b/internal/github/checkStalePRs.go index 8923045..a53810f 100644 --- a/internal/github/checkStalePRs.go +++ b/internal/github/checkStalePRs.go @@ -23,7 +23,7 @@ type StalePR struct { func CheckStalePRs(ctx context.Context, githubClient *github.Client, cfg *config.Config) ([]StalePR, error) { var stalePRs []StalePR cutoffDate := time.Now().Add(-7 * 24 * time.Hour) // 7 days ago - teamMembers, err := GetTeamMemberList(githubClient, cfg.InternalTeam) + teamMembers, err := GetTeamMemberList(githubClient, cfg.InternalTeam, cfg.InternalTeamIgnoredUsers) if err != nil { return nil, err } diff --git a/internal/github/checkUnsigned.go b/internal/github/checkUnsigned.go index 63ddf25..1daf12e 100644 --- a/internal/github/checkUnsigned.go +++ b/internal/github/checkUnsigned.go @@ -23,7 +23,7 @@ type UnsignedPRs struct { // CheckUnsignedCommits will return a list of PR URLs that have not been updated in the last 7 days by internal team members. func CheckUnsignedCommits(ctx context.Context, githubClient *github.Client, cfg *config.Config) ([]UnsignedPRs, error) { var unsignedPRs []UnsignedPRs - teamMembers, err := GetTeamMemberList(githubClient, cfg.InternalTeam) + teamMembers, err := GetTeamMemberList(githubClient, cfg.InternalTeam, cfg.InternalTeamIgnoredUsers) if err != nil { return nil, err } diff --git a/internal/github/teamMemberList.go b/internal/github/teamMemberList.go index cf1bf9a..0de2d57 100644 --- a/internal/github/teamMemberList.go +++ b/internal/github/teamMemberList.go @@ -9,7 +9,7 @@ import ( ) // GetTeamMemberList obtains a list of teammembers -func GetTeamMemberList(githubClient *github.Client, internalTeam string) (map[string]bool, error) { +func GetTeamMemberList(githubClient *github.Client, internalTeam string, internalTeamIgnoredMembers []string) (map[string]bool, error) { teamMembers := make(map[string]bool) teamParts := strings.Split(internalTeam, "/") @@ -33,7 +33,19 @@ func GetTeamMemberList(githubClient *github.Client, internalTeam string) (map[st } for _, member := range members { - teamMembers[*member.Login] = true + if member.Login != nil { + shouldIgnoreMember := false + for _, ignoredMember := range internalTeamIgnoredMembers { + if strings.EqualFold(ignoredMember, *member.Login) { + shouldIgnoreMember = true + break + } + } + + if !shouldIgnoreMember { + teamMembers[*member.Login] = true + } + } } if resp.NextPage == 0 { diff --git a/internal/label/pullrequests.go b/internal/label/pullrequests.go index 4d6e578..4cf7f29 100644 --- a/internal/label/pullrequests.go +++ b/internal/label/pullrequests.go @@ -14,7 +14,7 @@ import ( // PullRequests applies internal or community labels to pull requests func PullRequests(githubClient *github.Client, cfg *config.Config) error { - teamMembers, err := github2.GetTeamMemberList(githubClient, cfg.InternalTeam) + teamMembers, err := github2.GetTeamMemberList(githubClient, cfg.InternalTeam, cfg.InternalTeamIgnoredUsers) if err != nil { return fmt.Errorf("error getting team members: %w", err) // Properly handle and return error if team member list fetch fails } diff --git a/k8s/label-prs.yml.j2 b/k8s/label-prs.yml.j2 index 3811462..0802363 100644 --- a/k8s/label-prs.yml.j2 +++ b/k8s/label-prs.yml.j2 @@ -15,6 +15,7 @@ secretFile: config.yml: | github_token: "{{ BOT_GITHUB_TOKEN }}" internal_team: "{{ INTERNAL_TEAM_NAME }}" + internal_team_ignored_users: [] label_internal: "" label_external: "community-pr" check_repos: diff --git a/k8s/notify-pending-prs.yml.j2 b/k8s/notify-pending-prs.yml.j2 index ff4bf33..c2bef00 100644 --- a/k8s/notify-pending-prs.yml.j2 +++ b/k8s/notify-pending-prs.yml.j2 @@ -15,6 +15,7 @@ secretFile: config.yml: | github_token: "{{ BOT_GITHUB_TOKEN }}" internal_team: "{{ INTERNAL_TEAM_NAME }}" + internal_team_ignored_users: [] check_repos: - name: "Chia-Network/chia-blockchain" minimum_number: 17788 diff --git a/k8s/notify-stale-prs.yml.j2 b/k8s/notify-stale-prs.yml.j2 index 0386227..ebe7e31 100644 --- a/k8s/notify-stale-prs.yml.j2 +++ b/k8s/notify-stale-prs.yml.j2 @@ -15,6 +15,8 @@ secretFile: config.yml: | github_token: "{{ BOT_GITHUB_TOKEN }}" internal_team: "{{ INTERNAL_TEAM_NAME }}" + internal_team_ignored_users: + - "ChiaAutomation" check_repos: - name: "Chia-Network/chia-blockchain" minimum_number: 17788 diff --git a/k8s/notify-unsigned.yml.j2 b/k8s/notify-unsigned.yml.j2 index fbf3a1e..ef8dac9 100644 --- a/k8s/notify-unsigned.yml.j2 +++ b/k8s/notify-unsigned.yml.j2 @@ -15,6 +15,7 @@ secretFile: config.yml: | github_token: "{{ BOT_GITHUB_TOKEN }}" internal_team: "{{ INTERNAL_TEAM_NAME }}" + internal_team_ignored_users: [] check_repos: - name: "Chia-Network/chia-blockchain" minimum_number: 17788