-
Notifications
You must be signed in to change notification settings - Fork 0
/
mikku.go
62 lines (49 loc) · 1.51 KB
/
mikku.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
package mikku
import (
"errors"
"fmt"
"os"
)
var (
errInvalidSemanticVersioningTag = errors.New("invalid semantic versioning tag")
)
// Release is the entry point of `mikku release` command
func Release(repo string, bumpTyp string) error {
cfg, err := readConfig()
if err != nil {
return fmt.Errorf("release: %w", err)
}
svc := newGitHubClientUsingEnv(cfg.GitHubOwner, cfg.GitHubAccessToken)
isFirstRelease := false
after, currentTag, err := svc.getLastPublishedAndCurrentTag(repo)
if err != nil {
if errors.Is(err, errReleaseNotFound) {
isFirstRelease = true
_, _ = fmt.Fprintf(os.Stdout, "Release not found. First Release...\n")
} else {
return fmt.Errorf("failed to get latest published date or tag: %w", err)
}
}
newTag, err := determineNewTag(currentTag, bumpTyp)
if err != nil {
if errors.Is(err, errInvalidSemanticVersioningTag) && isFirstRelease {
return fmt.Errorf("you must specify the tag because of the first release")
}
return fmt.Errorf("failed to determine new tag: %w", err)
}
prs, err := svc.getMergedPRsAfter(repo, after)
if err != nil {
return fmt.Errorf("get pull requests: %w", err)
}
body, err := generateReleaseBody(prs)
if err != nil {
return fmt.Errorf("failed to generate release body: %w", err)
}
newRelease, err := svc.createRelease(repo, newTag, body)
if err != nil {
return fmt.Errorf("failed to create release: %w", err)
}
_, _ = fmt.Fprintf(os.Stdout, "Release was created.\n")
_, _ = fmt.Fprintf(os.Stdout, *newRelease.HTMLURL+"\n")
return nil
}