Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit adde807

Browse files
authoredJul 1, 2024
Added configurable skipping of release notes commits (#214)
* by default, if `internal` label is attached to a PR, it won't appear in the release notes * it's also now possible to skip individual commit SHA's
1 parent 84587a4 commit adde807

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed
 

‎go-libs/lite/lite.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ func (r *Root[T]) bindViperToFlags(v *viper.Viper, flags *pflag.FlagSet, prefix
221221
for _, y := range x {
222222
sliceValue.Append(fmt.Sprint(y))
223223
}
224+
case []string:
225+
sliceValue, ok := f.Value.(pflag.SliceValue)
226+
if !ok {
227+
err = fmt.Errorf("%s: expected string slice, but got %s", propName, f.Value.String())
228+
}
229+
sliceValue.Replace(x)
224230
default:
225231
f.Value.Set(fmt.Sprintf("%v", x))
226232
}

‎go-libs/llnotes/release_notes.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package llnotes
33
import (
44
"context"
55
"fmt"
6+
"regexp"
67
"sort"
8+
"strconv"
79
"strings"
810

911
"github.com/databricks/databricks-sdk-go/listing"
12+
"github.com/databricks/databricks-sdk-go/logger"
1013
"github.com/databrickslabs/sandbox/go-libs/github"
1114
"github.com/databrickslabs/sandbox/go-libs/parallel"
1215
"github.com/databrickslabs/sandbox/go-libs/sed"
@@ -28,8 +31,58 @@ func (lln *llNotes) UpcomingRelease(ctx context.Context) ([]string, error) {
2831
return lln.ReleaseNotesDiff(ctx, latestTag, repo.DefaultBranch)
2932
}
3033

34+
var maybePrRE = regexp.MustCompile(`\(#(\d+)\)$`)
35+
36+
func (lln *llNotes) filterOutCommitsWithSkipLabels(ctx context.Context, in []github.RepositoryCommit) ([]github.RepositoryCommit, error) {
37+
if len(lln.cfg.SkipLabels) == 0 {
38+
logger.Debugf(ctx, "No skip labels configured. Keeping all commits.")
39+
return in, nil
40+
}
41+
var out []github.RepositoryCommit
42+
iterateCommits:
43+
for _, commit := range in {
44+
for _, skip := range lln.cfg.SkipCommits {
45+
if commit.SHA == skip {
46+
logger.Infof(ctx, "Skipping commit %s: %s", commit.SHA, commit.Commit.Message)
47+
continue iterateCommits
48+
}
49+
}
50+
if commit.Commit.Message == "" {
51+
continue
52+
}
53+
title, _, ok := strings.Cut(commit.Commit.Message, "\n")
54+
if !ok {
55+
title = commit.Commit.Message
56+
}
57+
match := maybePrRE.FindStringSubmatch(title)
58+
if len(match) == 0 {
59+
logger.Debugf(ctx, "Keeping commit %s: no PR reference", commit.SHA)
60+
out = append(out, commit)
61+
continue
62+
}
63+
number, err := strconv.Atoi(match[1])
64+
if err != nil {
65+
return nil, fmt.Errorf("invalid PR number: %w", err)
66+
}
67+
pr, err := lln.gh.GetPullRequest(ctx, lln.org, lln.repo, number)
68+
if err != nil {
69+
return nil, fmt.Errorf("get PR: %w", err)
70+
}
71+
for _, label := range pr.Labels {
72+
for _, skip := range lln.cfg.SkipLabels {
73+
if label.Name == skip {
74+
logger.Infof(ctx, "Skipping '%s': %s", title, skip)
75+
continue iterateCommits
76+
}
77+
}
78+
}
79+
out = append(out, commit)
80+
}
81+
return out, nil
82+
}
83+
3184
func (lln *llNotes) ReleaseNotesDiff(ctx context.Context, since, until string) ([]string, error) {
32-
commits, err := listing.ToSlice(ctx, lln.gh.CompareCommits(ctx, lln.org, lln.repo, since, until))
85+
raw, err := listing.ToSlice(ctx, lln.gh.CompareCommits(ctx, lln.org, lln.repo, since, until))
3386
if err != nil {
3487
return nil, fmt.Errorf("commits: %w", err)
3588
}
@@ -51,6 +104,10 @@ func (lln *llNotes) ReleaseNotesDiff(ctx context.Context, since, until string) (
51104
sed.Rule(`#(\d+)`, fmt.Sprintf("[#$1](https://github.com/%s/%s/issues/$1)", lln.org, lln.repo)),
52105
sed.Rule(`\. \(`, ` (`),
53106
}
107+
commits, err := lln.filterOutCommitsWithSkipLabels(ctx, raw)
108+
if err != nil {
109+
return nil, fmt.Errorf("filter: %w", err)
110+
}
54111
notes, err := parallel.Tasks(ctx, lln.cfg.Workers, commits,
55112
func(ctx context.Context, commit github.RepositoryCommit) (string, error) {
56113
history, err := lln.Commit(ctx, &commit)

‎go-libs/llnotes/talk.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
)
1515

1616
type Settings struct {
17-
GitHub github.GitHubConfig
18-
Databricks config.Config
19-
Org, Repo string
20-
Model string
21-
MaxTokens int
22-
Workers int
17+
GitHub github.GitHubConfig
18+
Databricks config.Config
19+
Org, Repo string
20+
Model string
21+
MaxTokens int
22+
Workers int
23+
SkipLabels []string
24+
SkipCommits []string
2325
}
2426

2527
func New(cfg *Settings) (*llNotes, error) {
@@ -37,6 +39,9 @@ func New(cfg *Settings) (*llNotes, error) {
3739
if cfg.Workers == 0 {
3840
cfg.Workers = 15
3941
}
42+
if len(cfg.SkipLabels) == 0 {
43+
cfg.SkipLabels = []string{"internal"}
44+
}
4045
return &llNotes{
4146
http: httpclient.NewApiClient(httpclient.ClientConfig{}),
4247
gh: github.NewClient(&cfg.GitHub),

0 commit comments

Comments
 (0)
Please sign in to comment.