@@ -19,7 +19,7 @@ const (
1919 DefaultTemplateRepo = "dtm-scaffolding-golang"
2020 DefaultTemplateOwner = "merico-dev"
2121 TransitBranch = "init-with-devstream"
22- MainBranch = "main"
22+ DefaultMainBranch = "main"
2323)
2424
2525type Config struct {
@@ -44,11 +44,14 @@ func InitRepoLocalAndPushToRemote(repoPath string, param *Param, ghClient *githu
4444 return err
4545 }
4646
47- return MergeCommits (ghClient )
47+ mainBranch := getMainBranchName (param )
48+ return MergeCommits (ghClient , mainBranch )
4849}
4950
5051func WalkLocalRepoPath (repoPath string , param * Param , ghClient * github.Client ) error {
5152 appName := param .Repo
53+ mainBranch := getMainBranchName (param )
54+
5255 if err := filepath .Walk (repoPath , func (path string , info fs.FileInfo , err error ) error {
5356 if err != nil {
5457 log .Debugf ("Walk error: %s." , err )
@@ -95,13 +98,13 @@ func WalkLocalRepoPath(repoPath string, param *Param, ghClient *github.Client) e
9598 } else {
9699 // the main branch needs a initial commit
97100 if strings .Contains (newPathForGithub , "gitignore" ) {
98- err := ghClient .CreateFile (content , strings .TrimSuffix (newPathForGithub , ".tpl" ), MainBranch )
101+ err := ghClient .CreateFile (content , strings .TrimSuffix (newPathForGithub , ".tpl" ), mainBranch )
99102 if err != nil {
100103 log .Debugf ("Failed to add the .gitignore file." )
101104 return err
102105 }
103106 log .Debugf ("Added the .gitignore file." )
104- return ghClient .NewBranch (MainBranch , TransitBranch )
107+ return ghClient .NewBranch (mainBranch , TransitBranch )
105108 }
106109 return ghClient .CreateFile (content , strings .TrimSuffix (newPathForGithub , ".tpl" ), TransitBranch )
107110 }
@@ -112,8 +115,8 @@ func WalkLocalRepoPath(repoPath string, param *Param, ghClient *github.Client) e
112115 return nil
113116}
114117
115- func MergeCommits (ghClient * github.Client ) error {
116- number , err := ghClient .NewPullRequest (TransitBranch , MainBranch )
118+ func MergeCommits (ghClient * github.Client , mainBranch string ) error {
119+ number , err := ghClient .NewPullRequest (TransitBranch , mainBranch )
117120 if err != nil {
118121 return err
119122 }
@@ -186,3 +189,10 @@ func buildState(param *Param) map[string]interface{} {
186189 res ["repoName" ] = param .Repo
187190 return res
188191}
192+
193+ func getMainBranchName (param * Param ) string {
194+ if param .Branch == "" {
195+ return DefaultMainBranch
196+ }
197+ return param .Branch
198+ }
0 commit comments