Skip to content

Commit

Permalink
Merge pull request #17 from Connehito/16-allow-main-branch
Browse files Browse the repository at this point in the history
#16 Allow main branch
  • Loading branch information
itosho authored Sep 12, 2020
2 parents 2b54d2f + cb74881 commit fc0f602
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func printError(w io.Writer, message string, args ...interface{}) {

func validate(cli *CLI, subCommand string, tag string) bool {
if subCommand == CommandDeploy {
if !cli.gdp.IsMasterBranch() {
printError(cli.errStream, fmt.Sprintf("Branch is not master."))
if !cli.gdp.IsMasterOrMainBranch() {
printError(cli.errStream, fmt.Sprintf("Branch is not master or main."))
return false
}
if cli.gdp.IsExistTagInLocal(tag) {
Expand Down
14 changes: 7 additions & 7 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type FakeGdpDeploy struct {
Gdp
}

func (f *FakeGdpDeploy) IsMasterBranch() bool {
func (f *FakeGdpDeploy) IsMasterOrMainBranch() bool {
return true
}

Expand Down Expand Up @@ -279,7 +279,7 @@ type FakeGdpDeployNotMasterBranch struct {
Gdp
}

func (f *FakeGdpDeployNotMasterBranch) IsMasterBranch() bool {
func (f *FakeGdpDeployNotMasterBranch) IsMasterOrMainBranch() bool {
return false
}

Expand All @@ -297,7 +297,7 @@ func TestRun_DeployNotMasterBranch(t *testing.T) {
t.Errorf("ExitCode=%d, Expected=%d", code, ExitError)
}

expected := "Branch is not master."
expected := "Branch is not master or main."
if !strings.Contains(err.String(), expected) {
t.Errorf("Output=%q, Expected=%q", err.String(), expected)
}
Expand All @@ -307,7 +307,7 @@ type FakeGdpDeployExistTagInLocal struct {
Gdp
}

func (f *FakeGdpDeployExistTagInLocal) IsMasterBranch() bool {
func (f *FakeGdpDeployExistTagInLocal) IsMasterOrMainBranch() bool {
return true
}

Expand Down Expand Up @@ -339,7 +339,7 @@ type FakeGdpDeployErrorInGetNextTag struct {
Gdp
}

func (f *FakeGdpDeployErrorInGetNextTag) IsMasterBranch() bool {
func (f *FakeGdpDeployErrorInGetNextTag) IsMasterOrMainBranch() bool {
return true
}

Expand Down Expand Up @@ -375,7 +375,7 @@ type FakeGdpDeployErrorInGetMergeCommitList struct {
Gdp
}

func (f *FakeGdpDeployErrorInGetMergeCommitList) IsMasterBranch() bool {
func (f *FakeGdpDeployErrorInGetMergeCommitList) IsMasterOrMainBranch() bool {
return true
}

Expand Down Expand Up @@ -411,7 +411,7 @@ type FakeGdpDeployErrorInDeploy struct {
Gdp
}

func (f *FakeGdpDeployErrorInDeploy) IsMasterBranch() bool {
func (f *FakeGdpDeployErrorInDeploy) IsMasterOrMainBranch() bool {
return true
}

Expand Down
8 changes: 4 additions & 4 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Gdp is the interface which has methods deploying and publising.
type Gdp interface {
IsMasterBranch() bool
IsMasterOrMainBranch() bool
IsExistTagInLocal(tag string) bool
IsExistTagInRemote(tag string) bool
GetMergeCommitList(toTag string) (string, error)
Expand Down Expand Up @@ -39,15 +39,15 @@ func NewCommand() (Gdp, error) {
return &Command{}, nil
}

// IsMasterBranch checks current branch is master or not.
func (c *Command) IsMasterBranch() bool {
// IsMasterOrMainBranch checks current branch is master|main or not.
func (c *Command) IsMasterOrMainBranch() bool {
out, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").CombinedOutput()
if err != nil {
return false
}

branch := strings.TrimRight(string(out), "\n")
if branch != "master" {
if branch != "master" && branch != "main" {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Version is GDP's version.
const Version string = "v0.2.3"
const Version string = "v0.2.4"

// Usage is GDP's usage.
const Usage string = "usage: gdp deploy|publish [options]"
Expand Down

0 comments on commit fc0f602

Please sign in to comment.