@@ -3,10 +3,13 @@ package llnotes
33import (
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+
3184func (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 )
0 commit comments