@@ -13,6 +13,7 @@ import (
1313
1414 "log"
1515 "os"
16+ "os/exec"
1617 "strings"
1718)
1819
@@ -56,9 +57,14 @@ func main() {
5657 Usage : "Stages updater changes and creates commit message" ,
5758 Required : false ,
5859 },
60+ & cli.BoolFlag {
61+ Name : "github-action" ,
62+ Usage : "Specifies whether tool is being used through github action workflow" ,
63+ Required : false ,
64+ },
5965 },
6066 Action : func (ctx context.Context , cmd * cli.Command ) error {
61- err := updater (string (cmd .String ("token" )), string (cmd .String ("repo" )), cmd .Bool ("commit" ))
67+ err := updater (string (cmd .String ("token" )), string (cmd .String ("repo" )), cmd .Bool ("commit" ), cmd . Bool ( "github-action" ) )
6268 if err != nil {
6369 return fmt .Errorf ("error running updater: %s" , err )
6470 }
@@ -71,7 +77,7 @@ func main() {
7177 }
7278}
7379
74- func updater (token string , repoPath string , commit bool ) error {
80+ func updater (token string , repoPath string , commit bool , githubAction bool ) error {
7581 var err error
7682 var dependencies Dependencies
7783 var updatedDependencies []VersionUpdateInfo
@@ -110,8 +116,8 @@ func updater(token string, repoPath string, commit bool) error {
110116 }
111117 }
112118
113- if commit && updatedDependencies != nil {
114- err := createCommitMessage (updatedDependencies , repoPath )
119+ if ( commit && updatedDependencies != nil ) || ( githubAction && updatedDependencies != nil ) {
120+ err := createCommitMessage (updatedDependencies , repoPath , githubAction )
115121 if err != nil {
116122 return fmt .Errorf ("error creating commit message: %s" , err )
117123 }
@@ -125,7 +131,7 @@ func updater(token string, repoPath string, commit bool) error {
125131 return nil
126132}
127133
128- func createCommitMessage (updatedDependencies []VersionUpdateInfo , repoPath string ) error {
134+ func createCommitMessage (updatedDependencies []VersionUpdateInfo , repoPath string , githubAction bool ) error {
129135 var repos []string
130136 commitTitle := "chore: updated "
131137 commitDescription := "Updated dependencies for: \n "
@@ -137,11 +143,18 @@ func createCommitMessage(updatedDependencies []VersionUpdateInfo, repoPath strin
137143 }
138144 commitDescription = strings .TrimSuffix (commitDescription , "\n " )
139145
140- commitTitle += strings .Join (repos , ", " )
141- commitDescription = "\" " + commitDescription + "\" "
142- err := createGitMessageEnv (commitTitle , commitDescription , repoPath )
143- if err != nil {
144- return fmt .Errorf ("error creating git commit message: %s" , err )
146+ if githubAction {
147+ commitTitle += strings .Join (repos , ", " )
148+ commitDescription = "\" " + commitDescription + "\" "
149+ err := createGitMessageEnv (commitTitle , commitDescription , repoPath )
150+ if err != nil {
151+ return fmt .Errorf ("error creating git commit message: %s" , err )
152+ }
153+ } else if ! githubAction {
154+ cmd := exec .Command ("git" , "commit" , "-am" , commitTitle , "-m" , commitDescription )
155+ if err := cmd .Run (); err != nil {
156+ return fmt .Errorf ("error running git commit -m: %s" , err )
157+ }
145158 }
146159 return nil
147160}
0 commit comments