Skip to content

Commit

Permalink
fix: Silent failure caused by branching logic
Browse files Browse the repository at this point in the history
Changed the branching after the `GetContents` call to *first* check for
a non-404 error (internal failure of some sort) and then proceed to
check the status to determine whether to `CreateFile` or `UpdateFile`.
  • Loading branch information
Southclaws authored and caarlos0 committed Feb 11, 2018
1 parent f8a7ac6 commit 0a37305
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions internal/client/github.go
Expand Up @@ -63,24 +63,28 @@ func (c *githubClient) CreateFile(
path,
&github.RepositoryContentGetOptions{},
)
if err != nil && res.StatusCode == 404 {
if err != nil && res.StatusCode != 404 {
return
}

if res.StatusCode == 404 {
_, _, err = c.client.Repositories.CreateFile(
ctx,
repo.Owner,
repo.Name,
path,
options,
)
return
} else {
options.SHA = file.SHA
_, _, err = c.client.Repositories.UpdateFile(
ctx,
repo.Owner,
repo.Name,
path,
options,
)
}
options.SHA = file.SHA
_, _, err = c.client.Repositories.UpdateFile(
ctx,
repo.Owner,
repo.Name,
path,
options,
)
return
}

Expand Down

0 comments on commit 0a37305

Please sign in to comment.