-
Notifications
You must be signed in to change notification settings - Fork 1
/
prbody.go
57 lines (45 loc) · 1.24 KB
/
prbody.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package rp
import (
"strings"
"github.com/apricote/releaser-pleaser/internal/git"
"github.com/apricote/releaser-pleaser/internal/markdown"
)
func parsePRBodyForCommitOverrides(commits []git.Commit) ([]git.Commit, error) {
result := make([]git.Commit, 0, len(commits))
for _, commit := range commits {
singleResult, err := parseSinglePRBodyForCommitOverrides(commit)
if err != nil {
return nil, err
}
result = append(result, singleResult...)
}
return result, nil
}
func parseSinglePRBodyForCommitOverrides(commit git.Commit) ([]git.Commit, error) {
if commit.PullRequest == nil {
return []git.Commit{commit}, nil
}
source := []byte(commit.PullRequest.Description)
var overridesText string
var found bool
err := markdown.WalkAST(source, markdown.GetCodeBlockText(source, "rp-commits", &overridesText, &found))
if err != nil {
return nil, err
}
if !found {
return []git.Commit{commit}, nil
}
lines := strings.Split(overridesText, "\n")
result := make([]git.Commit, 0, len(lines))
for _, line := range lines {
// Only consider lines with text
line = strings.TrimSpace(line)
if line == "" {
continue
}
newCommit := commit
newCommit.Message = line
result = append(result, newCommit)
}
return result, nil
}