From 7f2d783de36c981f661f4656af7e092b9d668be3 Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Tue, 9 Jul 2024 17:49:25 -0400 Subject: [PATCH] Do not require changelog entry for docs 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. --- bot/internal/bot/changelog.go | 17 +++++++ bot/internal/bot/changelog_test.go | 75 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/bot/internal/bot/changelog.go b/bot/internal/bot/changelog.go index bcbbd26d..2417290c 100644 --- a/bot/internal/bot/changelog.go +++ b/bot/internal/bot/changelog.go @@ -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) diff --git a/bot/internal/bot/changelog_test.go b/bot/internal/bot/changelog_test.go index c7a3b7af..f4052c69 100644 --- a/bot/internal/bot/changelog_test.go +++ b/bot/internal/bot/changelog_test.go @@ -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: "foo@bar.com", + 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