Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] generate issue templates with githubgen #28655

Merged
merged 5 commits into from
Nov 21, 2023

Conversation

atoulme
Copy link
Contributor

@atoulme atoulme commented Oct 27, 2023

Remove a bash script, use go code instead.

@andrzej-stencel
Copy link
Member

andrzej-stencel commented Oct 27, 2023

I appreciate moving from Bash to Golang. I just wish the Golang code was easier to read. This tool's code was already quite messy before and with this change, it's getting more messy and hard to follow.

From what I can understand, with this change running the githubgen tool has the following effect depending on the command line options:

$ ./githubgen -dependabot
generateDependabot

$ ./githubgen -issue-templates
generateIssueTemplates

$ ./githubgen
generateCodeownersFiles
generateDependabot

The options are inconsistent. Not passing the -dependabot option still executes the dependabot generator, but not passing the -issues-templates option does not execute the issue template generator. The code for those options is borderline hilarious 😄, including the unnecessary if statements:

	if !dependabotOnly && !issueTemplatesOnly {
		if err = generateCodeownersFiles(foldersList, allCodeowners, allowlistFilePath, components, maxLength); err != nil {
			return err
		}
	}

	if !issueTemplatesOnly {
		if err = generateDependabot(dependabotData); err != nil {
			return err
		}
		return nil
	}

	if err = generateIssueTemplates(foldersList); err != nil {
		return err
	}
	if issueTemplatesOnly {
		return nil
	}

	return nil

We could disregard this with "this is just a tool", but reading and reviewing this code is painful or amusing depending on reviewer's approach 😉, and definitely takes more time than it could. More importantly, messy code makes it easier to introduce bugs.

I propose a little rework of the tool for consistent behavior - either run all generators when no options are passed, or only run the generators explicitly specified with options, not running any generators if no option is specified. Having consistency in behavior should also make the code more comprehensible.

Here's example pseudo-code for the first approach:

func run(...) {
  ...
  var generatorsToRun []string
  if dependabotOnly {
    generatorsToRun := []string{generateDependabot}
  ) else if issueTemplatesOnly {
    generatorsToRun := []string{generateIssueTemplates}
  } else {
    generatorsToRun := []string{
      generateDependabot,
      generateIssueTemplates,
      generateCodeownersFiles,
    }
  }

  for generator := range generatorsToRun {
    err := generator()
    if err != nil {
      return err
    }
  } 
}

@atoulme
Copy link
Contributor Author

atoulme commented Oct 27, 2023

Yes. It’s painful. Especially some of the weird contortions the code has to follow to match the existing rules. We can make things a bit nicer, however note that the generators all depend on the same one time parsing. There is some state to pass around.

@atoulme
Copy link
Contributor Author

atoulme commented Oct 27, 2023

I am rereading your comment, and I agree - most of my code is the stuff of comedy, and I should not code past 7pm.
Give me a sec and I'll amend.

@atoulme
Copy link
Contributor Author

atoulme commented Oct 30, 2023

@astencel-sumo did you want to review this PR again?

@andrzej-stencel
Copy link
Member

Awesome! this is so much better to read! 😍 Thank you Antoine.

Just one fix is needed as the tool currently fails on the codeowners generator:

$ GITHUB_TOKEN=redacted githubgen codeowners
panic: strings: negative Repeat count

goroutine 1 [running]:
strings.Repeat({0x7e3000?, 0xc00026c5f0?}, 0x7e15b8?)
        /usr/local/go/src/strings/strings.go:554 +0x318
main.codeownersGenerator.generate({}, 0xc0001e6000)
        /home/andrzej/sumo/opentelemetry-collector-contrib/cmd/githubgen/codeowners.go:146 +0xa3d
main.run({0x7e15c8, 0x1}, {0x763965, 0x1b}, {0xc00002e2e0, 0x1, 0x58?})
        /home/andrzej/sumo/opentelemetry-collector-contrib/cmd/githubgen/main.go:174 +0x60a
main.main()
        /home/andrzej/sumo/opentelemetry-collector-contrib/cmd/githubgen/main.go:50 +0x3e9

atoulme and others added 2 commits October 31, 2023 06:35
Co-authored-by: Andrzej Stencel <astencel@sumologic.com>
Co-authored-by: Andrzej Stencel <astencel@sumologic.com>
Copy link
Member

@andrzej-stencel andrzej-stencel left a comment

Choose a reason for hiding this comment

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

Thank you Antoine!

Here's the output I'm getting now:

$ GITHUB_TOKEN=redacted githubgen
The following modules were not added to Dependabot to keep within limits of 220
  - "/cmd/configschema"
  - "/cmd/githubgen"
  - "/cmd/mdatagen"
  - "/cmd/opampsupervisor"
  - "/extension/encoding/jaegerencodingextension"
  - "/extension/encoding/jsonlogencodingextension"
  - "/extension/encoding/textencodingextension"
  - "/extension/encoding/zipkinencodingextension"
  - "/extension/opampextension"
  - "/receiver/splunkenterprisereceiver"
2023/10/31 15:54:53 codeowners are not members: cparkins
$ echo $?
1

Seems that cperkins needs to be added to /cmd/githubgen/allowlist.txt if I'm not mistaken. Not sure if this is something that should be fixed as part of this change or separately.

@atoulme
Copy link
Contributor Author

atoulme commented Oct 31, 2023

It needs to be fixed separately. Unfortunately, we still don't have a PAT to run this check as part of CI. Feel free to upvote open-telemetry/community#1659

@atoulme
Copy link
Contributor Author

atoulme commented Nov 1, 2023

#28855 is open to fix this issue.

@andrzej-stencel
Copy link
Member

I guess this can be merged now?

@mx-psi
Copy link
Member

mx-psi commented Nov 14, 2023

@atoulme can you confirm this is good to merge now?

@atoulme
Copy link
Contributor Author

atoulme commented Nov 21, 2023

yes, good to merge, thanks!

@atoulme atoulme added the ready to merge Code review completed; ready to merge by maintainers label Nov 21, 2023
@mx-psi mx-psi merged commit 4ea95dc into open-telemetry:main Nov 21, 2023
88 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 21, 2023
RoryCrispin pushed a commit to ClickHouse/opentelemetry-collector-contrib that referenced this pull request Nov 24, 2023
Remove a bash script, use go code instead.

---------

Co-authored-by: Andrzej Stencel <astencel@sumologic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd/githubgen ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants