Skip to content

Commit

Permalink
add default code owner flag and use it
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Wiesinger <[email protected]>
  • Loading branch information
mowies committed Jan 7, 2025
1 parent 5a1d7e3 commit b0d04a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions githubgen/codeowners.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const codeownersHeader = `# Code generated by githubgen. DO NOT EDIT.
# https://help.github.com/en/articles/about-code-owners
#
* @open-telemetry/collector-contrib-approvers
* %s
`

const distributionCodeownersHeader = `
Expand Down Expand Up @@ -129,7 +129,7 @@ func (cg *codeownersGenerator) Generate(data datatype.GithubData) error {
return fmt.Errorf("unused members in allowlist: %s", strings.Join(unused, ", "))
}

codeowners := fmt.Sprintf(codeownersHeader, data.RepoName)
codeowners := fmt.Sprintf(codeownersHeader, data.RepoName, data.DefaultCodeOwner)
deprecatedList := "## DEPRECATED components\n"
unmaintainedList := "\n## UNMAINTAINED components\n"

Expand All @@ -141,7 +141,7 @@ LOOP:
for stability := range m.Status.Stability {
if stability == unmaintainedStatus {
unmaintainedList += key + "/\n"
unmaintainedCodeowners += fmt.Sprintf("%s/%s @open-telemetry/collector-contrib-approvers \n", key, strings.Repeat(" ", data.MaxLength-len(key)))
unmaintainedCodeowners += fmt.Sprintf("%s/%s %s \n", key, strings.Repeat(" ", data.MaxLength-len(key)), data.DefaultCodeOwner)
continue LOOP
}
if stability == "deprecated" && (m.Status.Codeowners == nil || len(m.Status.Codeowners.Active) == 0) {
Expand All @@ -161,7 +161,7 @@ LOOP:
owners += " "
owners += "@" + owner
}
codeowners += fmt.Sprintf("%s/%s @open-telemetry/collector-contrib-approvers%s\n", key, strings.Repeat(" ", data.MaxLength-len(key)), owners)
codeowners += fmt.Sprintf("%s/%s %s%s\n", key, strings.Repeat(" ", data.MaxLength-len(key)), data.DefaultCodeOwner, owners)
}
}

Expand All @@ -178,7 +178,7 @@ LOOP:
for _, m := range dist.Maintainers {
maintainers = append(maintainers, fmt.Sprintf("@%s", m))
}
codeowners += fmt.Sprintf("reports/distributions/%s.yaml%s @open-telemetry/collector-contrib-approvers %s\n", dist.Name, strings.Repeat(" ", longestName-len(dist.Name)), strings.Join(maintainers, " "))
codeowners += fmt.Sprintf("reports/distributions/%s.yaml%s %s %s\n", dist.Name, strings.Repeat(" ", longestName-len(dist.Name)), data.DefaultCodeOwner, strings.Join(maintainers, " "))
}

err = os.WriteFile(filepath.Join(".github", "CODEOWNERS"), []byte(codeowners+unmaintainedCodeowners), 0o600)
Expand Down
1 change: 1 addition & 0 deletions githubgen/datatype/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type GithubData struct {
Components map[string]Metadata
Distributions []DistributionData
RepoName string
DefaultCodeOwner string
}

type Codeowners struct {
Expand Down
6 changes: 4 additions & 2 deletions githubgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func main() {
allowlistFilePath := flag.String("allowlist", "cmd/githubgen/allowlist.txt", "path to a file containing an allowlist of members outside the OpenTelemetry organization")
skipGithubCheck := flag.Bool("skipgithub", false, "skip checking GitHub membership check for CODEOWNERS datatype.Generator")
repoName := flag.String("repo-name", "", "name of the repository (e.g. \"OpenTelemetry Collector Contrib\")")
defaultCodeOwner := flag.String("default-codeowners", "", "GitHub user or team name that will be used as default codeowner")

flag.Parse()
var generators []datatype.Generator
Expand All @@ -56,7 +57,7 @@ func main() {
log.Fatal(err)
}

if err = run(*folder, *allowlistFilePath, *repoName, generators, distributions); err != nil {
if err = run(*folder, *allowlistFilePath, *repoName, generators, distributions, *defaultCodeOwner); err != nil {
log.Fatal(err)
}
}
Expand All @@ -80,7 +81,7 @@ func loadMetadata(filePath string) (datatype.Metadata, error) {
return md, nil
}

func run(folder string, allowlistFilePath string, repoName string, generators []datatype.Generator, distros []datatype.DistributionData) error {
func run(folder string, allowlistFilePath string, repoName string, generators []datatype.Generator, distros []datatype.DistributionData, defaultCodeOwner string) error {
components := map[string]datatype.Metadata{}
var foldersList []string
maxLength := 0
Expand Down Expand Up @@ -132,6 +133,7 @@ func run(folder string, allowlistFilePath string, repoName string, generators []
Components: components,
Distributions: distros,
RepoName: repoName,
DefaultCodeOwner: defaultCodeOwner,
}

for _, g := range generators {
Expand Down

0 comments on commit b0d04a9

Please sign in to comment.