-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_github_worker.go
73 lines (61 loc) · 1.94 KB
/
create_github_worker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"fmt"
"github.com/nextlinux/chronicle/chronicle/release"
"github.com/nextlinux/chronicle/chronicle/release/change"
"github.com/nextlinux/chronicle/chronicle/release/releasers/github"
"github.com/nextlinux/chronicle/internal/git"
"github.com/nextlinux/chronicle/internal/log"
)
func createChangelogFromGithub() (*release.Release, *release.Description, error) {
ghConfig := appConfig.Github.ToGithubConfig()
gitter, err := git.New(appConfig.CliOptions.RepoPath)
if err != nil {
return nil, nil, err
}
summer, err := github.NewSummarizer(gitter, ghConfig)
if err != nil {
return nil, nil, fmt.Errorf("unable to create summarizer: %w", err)
}
changeTypeTitles := getGithubSupportedChanges()
var untilTag = appConfig.UntilTag
if untilTag == "" {
untilTag, err = github.FindChangelogEndTag(summer, gitter)
if err != nil {
return nil, nil, err
}
}
if untilTag != "" {
log.WithFields("tag", untilTag).Infof("until")
} else {
log.Infof("until the current revision")
}
var speculator release.VersionSpeculator
if appConfig.SpeculateNextVersion {
speculator = github.NewVersionSpeculator(gitter, release.SpeculationBehavior{
EnforceV0: appConfig.EnforceV0,
NoChangesBumpsPatch: true,
})
}
changelogConfig := release.ChangelogInfoConfig{
RepoPath: appConfig.CliOptions.RepoPath,
SinceTag: appConfig.SinceTag,
UntilTag: untilTag,
VersionSpeculator: speculator,
ChangeTypeTitles: changeTypeTitles,
}
return release.ChangelogInfo(summer, changelogConfig)
}
func getGithubSupportedChanges() []change.TypeTitle {
var supportedChanges []change.TypeTitle
for _, c := range appConfig.Github.Changes {
// TODO: this could be one source of truth upstream
k := change.ParseSemVerKind(c.SemVerKind)
t := change.NewType(c.Type, k)
supportedChanges = append(supportedChanges, change.TypeTitle{
ChangeType: t,
Title: c.Title,
})
}
return supportedChanges
}