-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.go
83 lines (72 loc) · 2.04 KB
/
release.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
74
75
76
77
78
79
80
81
82
83
package glow
import (
"fmt"
"regexp"
"strings"
l "github.com/meinto/glow/logging"
"github.com/pkg/errors"
)
// Release definition
type release struct {
version string
Branch
}
// NewRelease creates a new release definition
func NewRelease(version string) (b Branch, err error) {
l.Log().Info(l.Fields{"version": version})
defer func() {
l.Log().
Info(l.Fields{"branch": b}).
Error(err)
}()
branchName := fmt.Sprintf(BRANCH_NAME_PREFIX+"release/v%s", version)
b = NewBranch(branchName)
return release{version, b}, nil
}
// ReleaseFromBranch extracts a release definition from branch name
func ReleaseFromBranch(branchName string) (b Branch, err error) {
l.Log().Info(l.Fields{"branchName": branchName})
defer func() {
l.Log().
Info(l.Fields{"branch": b}).
Error(err)
}()
matched, err := regexp.Match(RELEASE_BRANCH_PATTERN, []byte(branchName))
if !matched || err != nil {
return release{}, errors.New("no valid release branch")
}
b = NewBranch(branchName)
parts := strings.Split(branchName, "/")
if len(parts) < 1 {
return release{}, errors.New("invalid branch name " + branchName)
}
version := parts[len(parts)-1]
version = strings.TrimPrefix(version, "v")
return release{version, b}, nil
}
// CreationIsAllowedFrom returns wheter branch is allowed to be created
// from given this source branch
func (f release) CreationIsAllowedFrom(sourceBranch Branch) bool {
if strings.Contains(sourceBranch.ShortBranchName(), "develop") {
return true
}
return false
}
// CanBeClosed checks if the branch name is a valid
func (f release) CanBeClosed() bool {
return true
}
// CanBePublished checks if the branch can be published directly to production
func (f release) CanBePublished() bool {
return true
}
// CloseBranches returns all branches which this branch have to be merged with
func (f release) CloseBranches(availableBranches []Branch) []Branch {
return []Branch{
NewBranch("develop"),
}
}
// PublishBranch returns the publish branch if available
func (f release) PublishBranch() Branch {
return NewBranch("master")
}