Skip to content

Commit

Permalink
Merge pull request #56 from Chia-Network/internal-team-ignored-users
Browse files Browse the repository at this point in the history
Add an internal team ignored users list to config
  • Loading branch information
Starttoaster authored Oct 11, 2024
2 parents 55b8c0c + 9df595b commit ec42999
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
13 changes: 7 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion internal/github/checkPendingCI.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/github/checkStalePRs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/github/checkUnsigned.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 14 additions & 2 deletions internal/github/teamMemberList.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/label/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions k8s/label-prs.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions k8s/notify-pending-prs.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions k8s/notify-stale-prs.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions k8s/notify-unsigned.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec42999

Please sign in to comment.