mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 10:17:02 +00:00
parent
929d00d696
commit
bb0423f509
10 changed files with 402 additions and 26 deletions
57
prbody.go
Normal file
57
prbody.go
Normal file
|
|
@ -0,0 +1,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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue