Skip to content
This repository has been archived by the owner on Jun 14, 2019. It is now read-only.

Commit

Permalink
custom configuration per repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaltas committed Apr 25, 2018
1 parent 3196577 commit bc73adf
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func main() {
var releaseOffset string
var releaseTag string

var releaseBranchesString string

//command flags
var statusCmd bool
var pendingCmd bool
Expand Down Expand Up @@ -89,24 +91,12 @@ func main() {
fmt.Println("Proceeding without configuration file")
}

if baseBranch == "" {
baseBranch = viper.GetString("generic.base-branch")
}
if branchesString == "" {
branchesString = viper.GetString("generic.status-branches")
}

repository, err := repo.LoadOrClone(repoURL, directory, viper.GetString("generic.remote"), skipFetch)
if err != nil {
fmt.Printf("Error loading repo:%s\n", err)
return
}

if branchesString == "" {
fmt.Printf("no branches to compare, use -branches\n")
return
}

rmt, err := repository.Remote(viper.GetString("generic.remote"))

if err != nil {
Expand All @@ -116,13 +106,42 @@ func main() {

parts := strings.Split(rmt.Config().URLs[0], "/")
repoName := strings.TrimSuffix(parts[len(parts)-1], ".git")
organizationName := parts[len(parts)-2]
// if remote is set by ssh instead of https
if strings.Contains(organizationName, ":") {
organizationName = organizationName[strings.LastIndex(organizationName, ":")+1:]
}

repoForRelease := ""
if strings.Contains(viper.GetString("generic.release-repos"), repoName) {
repoForRelease = repoName
}

if baseBranch == "" {
baseBranch = viper.GetString("generic.base-branch")
}

if branchesString == "" {
branchesString = viper.GetString(fmt.Sprintf("repos.%s.status-branches", repoName))
releaseBranchesString = viper.GetString(fmt.Sprintf("repos.%s.release-branches", repoName))
}

if branchesString == "" {
branchesString = viper.GetString("generic.status-branches")
}

if releaseBranchesString == "" {
releaseBranchesString = viper.GetString("generic.release-branches")
}

if branchesString == "" {
fmt.Printf("no branches to compare, use -branches\n")
return
}

branches := strings.Split(branchesString, ",")
releaseBranches := strings.Split(releaseBranchesString, ",")

for _, branch := range branches {
ahead, behind, err := repo.CompareBranch(repository, baseBranch, branch, directory)
if err != nil {
Expand Down Expand Up @@ -152,11 +171,11 @@ func main() {
if deployCmd {
branchMap := viper.GetStringMapString("release.branch-map")
deployBranches(
viper.GetString("generic.organization"),
organizationName,
viper.GetString("generic.remote"),
repoForRelease,
baseBranch,
branches,
releaseBranches,
releaseOffset,
releaseInterval,
directory,
Expand Down Expand Up @@ -187,7 +206,7 @@ func main() {
release, err := github.CreateDraftRelease(
context.Background(),
viper.GetString("github.access-token"),
viper.GetString("generic.organization"),
organizationName,
repoForRelease,
name, tagName, releaseBody)

Expand All @@ -202,8 +221,8 @@ func main() {
release, err := github.LastRelease(
context.Background(),
viper.GetString("github.access-token"),
viper.GetString("generic.organization"),
viper.GetString("generic.release-repo"),
organizationName,
repoForRelease,
)
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit bc73adf

Please sign in to comment.