@@ -44,11 +44,11 @@ func (ga *GithubActions) GetLanguage() *Language {
4444}
4545
4646func (ga * GithubActions ) AddWorkflow (workflow * Workflow ) error {
47- exists , err := ga .fileExists (workflow .workflowFileName )
47+ sha , err := ga .getFileSHA (workflow .workflowFileName )
4848 if err != nil {
4949 return err
5050 }
51- if exists {
51+ if sha != "" {
5252 log .Printf ("github actions Workflow %s already exists\n " , workflow .workflowFileName )
5353 return nil
5454 }
@@ -77,11 +77,11 @@ func (ga *GithubActions) AddWorkflow(workflow *Workflow) error {
7777}
7878
7979func (ga * GithubActions ) DeleteWorkflow (workflow * Workflow ) error {
80- exists , err := ga .fileExists (workflow .workflowFileName )
80+ sha , err := ga .getFileSHA (workflow .workflowFileName )
8181 if err != nil {
8282 return err
8383 }
84- if ! exists {
84+ if sha == "" {
8585 log .Printf ("github actions Workflow %s already removed\n " , workflow .workflowFileName )
8686 return nil
8787 }
@@ -109,27 +109,31 @@ func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
109109 return nil
110110}
111111
112- func (ga * GithubActions ) fileExists (filename string ) (bool , error ) {
113- _ , _ , resp , err := ga .client .Repositories .GetContents (
112+ // getFileSHA:
113+ // 1. if file exists without error: return (string(SHA), nil)
114+ // 2. if some errors occurred: return ("", err)
115+ // 3. if file not found without error: return ("", nil)
116+ func (ga * GithubActions ) getFileSHA (filename string ) (string , error ) {
117+ content , _ , resp , err := ga .client .Repositories .GetContents (
114118 ga .ctx ,
115119 ga .options .Owner ,
116120 ga .options .Repo ,
117121 generateGitHubWorkflowFileByName (filename ),
118122 & github.RepositoryContentGetOptions {},
119123 )
120124
121- if err != nil {
122- return false , err
125+ if resp . StatusCode == http . StatusNotFound {
126+ return "" , nil
123127 }
124128
125- if resp . StatusCode == http . StatusNotFound {
126- return false , nil
129+ if err != nil {
130+ return "" , err
127131 }
128132
129133 if resp .StatusCode == http .StatusOK {
130- return true , nil
134+ return * content . SHA , nil
131135 }
132- return false , fmt .Errorf ("got some error is not expected" )
136+ return "" , fmt .Errorf ("got some error is not expected" )
133137}
134138
135139func generateGitHubWorkflowFileByName (f string ) string {
0 commit comments