5
5
"fmt"
6
6
"log"
7
7
"net/http"
8
+ "strings"
8
9
9
10
"github.com/google/go-github/v40/github"
10
11
"github.com/mitchellh/mapstructure"
@@ -109,10 +110,10 @@ func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
109
110
return nil
110
111
}
111
112
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)
113
+ // getFileSHA will try to collect the SHA hash value of the file, then return it. the return values will be:
114
+ // 1. If file exists without error -> string(SHA), nil
115
+ // 2. If some errors occurred -> return "", err
116
+ // 3. If file not found without error -> return "", nil
116
117
func (ga * GithubActions ) getFileSHA (filename string ) (string , error ) {
117
118
content , _ , resp , err := ga .client .Repositories .GetContents (
118
119
ga .ctx ,
@@ -122,14 +123,17 @@ func (ga *GithubActions) getFileSHA(filename string) (string, error) {
122
123
& github.RepositoryContentGetOptions {},
123
124
)
124
125
125
- if resp .StatusCode == http .StatusNotFound {
126
- return "" , nil
126
+ // error reason is not 404
127
+ if err != nil && ! strings .Contains (err .Error (), "404" ) {
128
+ return "" , err
127
129
}
128
130
129
- if err != nil {
130
- return "" , err
131
+ // error reason is 404
132
+ if resp .StatusCode == http .StatusNotFound {
133
+ return "" , nil
131
134
}
132
135
136
+ // no error occurred
133
137
if resp .StatusCode == http .StatusOK {
134
138
return * content .SHA , nil
135
139
}
0 commit comments