55 "fmt"
66 "log"
77 "net/http"
8+ "strings"
89
910 "github.com/google/go-github/v40/github"
1011 "github.com/mitchellh/mapstructure"
@@ -109,10 +110,10 @@ func (ga *GithubActions) DeleteWorkflow(workflow *Workflow) error {
109110 return nil
110111}
111112
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
116117func (ga * GithubActions ) getFileSHA (filename string ) (string , error ) {
117118 content , _ , resp , err := ga .client .Repositories .GetContents (
118119 ga .ctx ,
@@ -122,14 +123,17 @@ func (ga *GithubActions) getFileSHA(filename string) (string, error) {
122123 & github.RepositoryContentGetOptions {},
123124 )
124125
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
127129 }
128130
129- if err != nil {
130- return "" , err
131+ // error reason is 404
132+ if resp .StatusCode == http .StatusNotFound {
133+ return "" , nil
131134 }
132135
136+ // no error occurred
133137 if resp .StatusCode == http .StatusOK {
134138 return * content .SHA , nil
135139 }
0 commit comments