Skip to content

Commit

Permalink
Bot: Label docs-only changes no-changelog
Browse files Browse the repository at this point in the history
Docs-only changes usually do not require a changelog entry.
Automatically add the `no-changelog` label for docs-only changes so docs
authors do not receive unnecessary notifications about missing
`no-changelog` labels and workflow failures for docs-only pull requests.
  • Loading branch information
ptgott committed Oct 9, 2024
1 parent 1dcec77 commit fd6d357
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions bot/internal/bot/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func (b *Bot) labels(ctx context.Context, files []github.PullRequestFile) ([]str
labels = append(labels, string(prSize(files)))
}

if !requiresChangelog(files) {
log.Println("Label: Adding no-changelog.")
labels = append(labels, "no-changelog")
}

// The branch name is unsafe, but here we are simply adding a label.
if b.c.Environment.Repository != env.CloudRepo && isReleaseBranch(b.c.Environment.UnsafeBase) {
log.Println("Label: Found backport branch.")
Expand Down Expand Up @@ -102,6 +107,17 @@ func deduplicate(s []string) []string {
return out
}

// requiresChangelog indicates whether, based on the files in a pull request,
// the PR should have the "no-changelog" label.
func requiresChangelog(files []github.PullRequestFile) bool {
for _, f := range files {
if !strings.HasPrefix(f.Name, "docs/") {
return true
}
}
return false
}

var prefixes = map[string]map[string][]string{
env.TeleportRepo: {
"bpf/": {"bpf"},
Expand Down
4 changes: 2 additions & 2 deletions bot/internal/bot/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestLabel(t *testing.T) {
Deletions: 10,
},
},
labels: []string{"documentation", string(small)},
labels: []string{"documentation", "no-changelog", string(small)},
},
{
desc: "helm",
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestLabel(t *testing.T) {
Deletions: 1000,
},
},
labels: []string{"backport", "documentation", string(xlarge)},
labels: []string{"backport", "documentation", "no-changelog", string(xlarge)},
},
{
desc: "web only",
Expand Down

0 comments on commit fd6d357

Please sign in to comment.