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

Added bot command to enforce changelog requirements #159

Merged
merged 6 commits into from
Sep 26, 2023

Conversation

fheinecke
Copy link
Contributor

This allows for repos using the shared-workflows bot to enforce changelog requirements.

@fheinecke fheinecke requested review from a team September 1, 2023 22:23
Copy link
Contributor

@r0mant r0mant left a comment

Choose a reason for hiding this comment

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

@fheinecke Overall I like this, but left a few simplification suggestions.

bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/bot.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
@fheinecke fheinecke force-pushed the fred/enforce-changelog-check-1 branch from 1d7ef8d to a91854f Compare September 12, 2023 20:48
@fheinecke fheinecke requested a review from r0mant September 12, 2023 20:48
@fheinecke fheinecke force-pushed the fred/enforce-changelog-check-1 branch from a91854f to 7882335 Compare September 12, 2023 20:51
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
bot/internal/bot/changelog.go Outdated Show resolved Hide resolved
// This is not intended to be comprehensive, rather, it is intended to cover the majority of problems.
func (b *Bot) validateChangelogEntry(ctx context.Context, changelogEntry string) error {
if strings.TrimSpace(changelogEntry) == "" {
return b.logFailedCheck(ctx, "The changelog entry must contain one or more non-whitespace characters")
Copy link
Contributor

Choose a reason for hiding this comment

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

To make logic more clear, I would make the following changes:

  • Instead of returning b.logFailedCheck() from each branch here and in "getChangelogEntry", have them return a normal trace.BadParameter("xxx") error.
  • In CheckChangelog call b.logFailedCheck(ctx, err) when the respective function returns an error.

Basically, move logFailedCheck call up the stack. Otherwise it's very implicit that get/validate functions also leave comments on the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree here, on the grounds that validateChangelogEntry could potentially return an error that is not due to an invalid changelog. Currently this is not an issue, however, if a developer were to add another check that does something like checking to see if the changelog entry is already in the CHANGELOG.md file, then this could result in an error message being written to the PR body that is not due to an invalid changelog entry. More specifically, if a check was added that did something like err := os.ReadFile("CHANGELOG.md") then this error could potentially get logged as a changelog entry failure.

Maybe one of these would be a better solution to the issue:

  • I could add a comment to the validateChangelogEntry function that explicitly says that it logs errors to the PR
  • I could return an error type that is specific to a changelog entry problem, and only log to the PR if the error is of this type

What do you think?

If I were to go with the second route, would it be better to return and instance of this new error type, or return a trace.Wrap of this new error type? In other words, ValidationError("some message") or trace.Wrap(ValidationError("some message"), "some error occured")?

@fheinecke fheinecke merged commit 4e635b0 into main Sep 26, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants