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

Do not require changelog entry for docs #278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading