Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

[Feature] Configurable Teams #57

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,34 @@ package model

import (
"regexp"
"strings"

"github.com/BurntSushi/toml"
"github.com/ianschenck/envflag"
)

// Config represents a repo-specific configuration file.
type Config struct {
Approvals int `json:"approvals" toml:"approvals"`
Pattern string `json:"pattern" toml:"pattern"`
Team string `json:"team" toml:"team"`
SelfApprovalOff bool `json:"self_approval_off" toml:"self_approval_off"`
IgnoreMaintainersFile bool `json:"ignore_maintainers_file" toml:"ignore_maintainers_file"`
Approvals int `json:"approvals" toml:"approvals"`
Pattern string `json:"pattern" toml:"pattern"`
Teams []string `json:"team" toml:"teams"`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Teams []string `json:"team" toml:"teams"`
Teams []string `json:"teams" toml:"teams"`

SelfApprovalOff bool `json:"self_approval_off" toml:"self_approval_off"`
IgnoreMaintainersFile bool `json:"ignore_maintainers_file" toml:"ignore_maintainers_file"`
// deprecated
Team string `json:"team" toml:"team"`

re *regexp.Regexp
}

var (
approvals = envflag.Int("LGTM_APPROVALS", 2, "")
pattern = envflag.String("LGTM_PATTERN", "(?i)LGTM", "")
team = envflag.String("LGTM_TEAM", "MAINTAINERS", "")
teams = envflag.String("LGTM_TEAMS", "MAINTAINERS", "")
selfApprovalOff = envflag.Bool("LGTM_SELF_APPROVAL_OFF", false, "")
ignoreMaintainersFile = envflag.Bool("IGNORE_MAINTAINERS_FILE", false, "")

// deprecated
team = envflag.String("LGTM_TEAM", "", "")
)

// ParseConfig parses a projects .lgtm file
Expand All @@ -47,6 +53,15 @@ func ParseConfigStr(data string) (*Config, error) {
if len(c.Team) == 0 {
c.Team = *team
}
if len(c.Teams) == 0 {
if len(*teams) != 0 {
for _, t := range strings.Split(*teams, ",") {
c.Teams = append(c.Teams, strings.TrimSpace(t))
}
} else {
c.Teams = []string{c.Team}
}
}
if c.SelfApprovalOff == false {
c.SelfApprovalOff = *selfApprovalOff
}
Expand Down