@@ -3,10 +3,13 @@ package llnotes
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "regexp"
6
7
"sort"
8
+ "strconv"
7
9
"strings"
8
10
9
11
"github.com/databricks/databricks-sdk-go/listing"
12
+ "github.com/databricks/databricks-sdk-go/logger"
10
13
"github.com/databrickslabs/sandbox/go-libs/github"
11
14
"github.com/databrickslabs/sandbox/go-libs/parallel"
12
15
"github.com/databrickslabs/sandbox/go-libs/sed"
@@ -28,8 +31,58 @@ func (lln *llNotes) UpcomingRelease(ctx context.Context) ([]string, error) {
28
31
return lln .ReleaseNotesDiff (ctx , latestTag , repo .DefaultBranch )
29
32
}
30
33
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
+
31
84
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 ))
33
86
if err != nil {
34
87
return nil , fmt .Errorf ("commits: %w" , err )
35
88
}
@@ -51,6 +104,10 @@ func (lln *llNotes) ReleaseNotesDiff(ctx context.Context, since, until string) (
51
104
sed .Rule (`#(\d+)` , fmt .Sprintf ("[#$1](https://github.com/%s/%s/issues/$1)" , lln .org , lln .repo )),
52
105
sed .Rule (`\. \(` , ` (` ),
53
106
}
107
+ commits , err := lln .filterOutCommitsWithSkipLabels (ctx , raw )
108
+ if err != nil {
109
+ return nil , fmt .Errorf ("filter: %w" , err )
110
+ }
54
111
notes , err := parallel .Tasks (ctx , lln .cfg .Workers , commits ,
55
112
func (ctx context.Context , commit github.RepositoryCommit ) (string , error ) {
56
113
history , err := lln .Commit (ctx , & commit )
0 commit comments