Skip to content

Commit

Permalink
Do not require changes for docs
Browse files Browse the repository at this point in the history
Docs-only changes do not require a changelog entry, as we reserve the
changelog for changes to the product. Edit the changelog workflow to
ignore docs-only changes.
  • Loading branch information
ptgott committed Oct 11, 2024
1 parent caf31a3 commit ca59a6c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bot/internal/bot/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func (b *Bot) CheckChangelog(ctx context.Context) error {
return nil
}

files, err := b.c.GitHub.ListFiles(
ctx,
b.c.Environment.Organization,
b.c.Environment.Repository,
b.c.Environment.Number,
)
if err != nil {
return trace.Wrap(err, "failed to retrieve pull request files for https://github.com/%s/%s/pull/%d", b.c.Environment.Organization, b.c.Environment.Repository, b.c.Environment.Number)

}

c := classifyChanges(b.c, files)
if c.Docs && !c.Code {
log.Print("PR contains only docs changes. No need for a changelog entry.")
return nil
}

changelogEntries := b.getChangelogEntries(pull.UnsafeBody)
if len(changelogEntries) == 0 {
return trace.BadParameter("Changelog entry not found in the PR body. Please add a %q label to the PR, or changelog lines starting with `%s` followed by the changelog entries for the PR.", NoChangelogLabel, ChangelogPrefix)
Expand Down
75 changes: 75 additions & 0 deletions bot/internal/bot/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,81 @@ func TestChangelog(t *testing.T) {
})
}

func TestMissingNoChangelogLabel(t *testing.T) {
tests := []struct {
description string
files github.PullRequestFiles
expectPass bool
}{
{
description: "empty file set",
files: github.PullRequestFiles{},
expectPass: false,
},
{
description: "code and docs",
files: github.PullRequestFiles{
{
Name: "lib/service/service.go",
},
{
Name: "docs/pages/index.mdx",
},
},
expectPass: false,
},
{
description: "code only",
files: github.PullRequestFiles{
{
Name: "lib/service/service.go",
},
},
expectPass: false,
},
{
description: "docs only",
files: github.PullRequestFiles{
{
Name: "docs/pages/index.mdx",
},
},
expectPass: true,
},
}

for _, c := range tests {
t.Run(c.description, func(t *testing.T) {
b := &Bot{
c: &Config{
Environment: &env.Environment{
// Assumes the Teleport repository,
// where we keep our documentation
// content.
Organization: "gravitaional",
Repository: "teleport",
Number: 0,
Author: "9",
UnsafeBase: "branch/v8",
UnsafeHead: "fix",
},
GitHub: &fakeGithub{
comments: []github.Comment{
{
Author: "[email protected]",
Body: "PR comment body",
},
},
files: c.files,
},
},
}
err := b.CheckChangelog(context.Background())
require.Equal(t, c.expectPass, err == nil)
})
}
}

func TestGetChangelogEntry(t *testing.T) {
tests := []struct {
desc string
Expand Down

0 comments on commit ca59a6c

Please sign in to comment.