Skip to content

Commit

Permalink
Added configurable skipping of release notes commits (#214)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nfx authored Jul 1, 2024
1 parent 84587a4 commit adde807
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
6 changes: 6 additions & 0 deletions go-libs/lite/lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ func (r *Root[T]) bindViperToFlags(v *viper.Viper, flags *pflag.FlagSet, prefix
for _, y := range x {
sliceValue.Append(fmt.Sprint(y))
}
case []string:
sliceValue, ok := f.Value.(pflag.SliceValue)
if !ok {
err = fmt.Errorf("%s: expected string slice, but got %s", propName, f.Value.String())
}
sliceValue.Replace(x)
default:
f.Value.Set(fmt.Sprintf("%v", x))
}
Expand Down
59 changes: 58 additions & 1 deletion go-libs/llnotes/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package llnotes
import (
"context"
"fmt"
"regexp"
"sort"
"strconv"
"strings"

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

var maybePrRE = regexp.MustCompile(`\(#(\d+)\)$`)

func (lln *llNotes) filterOutCommitsWithSkipLabels(ctx context.Context, in []github.RepositoryCommit) ([]github.RepositoryCommit, error) {
if len(lln.cfg.SkipLabels) == 0 {
logger.Debugf(ctx, "No skip labels configured. Keeping all commits.")
return in, nil
}
var out []github.RepositoryCommit
iterateCommits:
for _, commit := range in {
for _, skip := range lln.cfg.SkipCommits {
if commit.SHA == skip {
logger.Infof(ctx, "Skipping commit %s: %s", commit.SHA, commit.Commit.Message)
continue iterateCommits
}
}
if commit.Commit.Message == "" {
continue
}
title, _, ok := strings.Cut(commit.Commit.Message, "\n")
if !ok {
title = commit.Commit.Message
}
match := maybePrRE.FindStringSubmatch(title)
if len(match) == 0 {
logger.Debugf(ctx, "Keeping commit %s: no PR reference", commit.SHA)
out = append(out, commit)
continue
}
number, err := strconv.Atoi(match[1])
if err != nil {
return nil, fmt.Errorf("invalid PR number: %w", err)
}
pr, err := lln.gh.GetPullRequest(ctx, lln.org, lln.repo, number)
if err != nil {
return nil, fmt.Errorf("get PR: %w", err)
}
for _, label := range pr.Labels {
for _, skip := range lln.cfg.SkipLabels {
if label.Name == skip {
logger.Infof(ctx, "Skipping '%s': %s", title, skip)
continue iterateCommits
}
}
}
out = append(out, commit)
}
return out, nil
}

func (lln *llNotes) ReleaseNotesDiff(ctx context.Context, since, until string) ([]string, error) {
commits, err := listing.ToSlice(ctx, lln.gh.CompareCommits(ctx, lln.org, lln.repo, since, until))
raw, err := listing.ToSlice(ctx, lln.gh.CompareCommits(ctx, lln.org, lln.repo, since, until))
if err != nil {
return nil, fmt.Errorf("commits: %w", err)
}
Expand All @@ -51,6 +104,10 @@ func (lln *llNotes) ReleaseNotesDiff(ctx context.Context, since, until string) (
sed.Rule(`#(\d+)`, fmt.Sprintf("[#$1](https://github.com/%s/%s/issues/$1)", lln.org, lln.repo)),
sed.Rule(`\. \(`, ` (`),
}
commits, err := lln.filterOutCommitsWithSkipLabels(ctx, raw)
if err != nil {
return nil, fmt.Errorf("filter: %w", err)
}
notes, err := parallel.Tasks(ctx, lln.cfg.Workers, commits,
func(ctx context.Context, commit github.RepositoryCommit) (string, error) {
history, err := lln.Commit(ctx, &commit)
Expand Down
17 changes: 11 additions & 6 deletions go-libs/llnotes/talk.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
)

type Settings struct {
GitHub github.GitHubConfig
Databricks config.Config
Org, Repo string
Model string
MaxTokens int
Workers int
GitHub github.GitHubConfig
Databricks config.Config
Org, Repo string
Model string
MaxTokens int
Workers int
SkipLabels []string
SkipCommits []string
}

func New(cfg *Settings) (*llNotes, error) {
Expand All @@ -37,6 +39,9 @@ func New(cfg *Settings) (*llNotes, error) {
if cfg.Workers == 0 {
cfg.Workers = 15
}
if len(cfg.SkipLabels) == 0 {
cfg.SkipLabels = []string{"internal"}
}
return &llNotes{
http: httpclient.NewApiClient(httpclient.ClientConfig{}),
gh: github.NewClient(&cfg.GitHub),
Expand Down

0 comments on commit adde807

Please sign in to comment.