Skip to content

Commit

Permalink
Merge pull request #463 from rhwlo/fix-homebrew-outdated-json-unmarsh…
Browse files Browse the repository at this point in the history
…alling

Fixes unmarshalling for homebrew outdated v2 JSON
  • Loading branch information
aengelberg authored Sep 14, 2020
2 parents b58303d + ffefaf3 commit cf6a918
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ We are very grateful to the following people have helped us to build the CLI too
- [Josef Šimánek](https://github.com/simi)
- [Brady Sullivan](https://github.com/d1str0)
- [Ashley Reid](https://github.com/akanix42)
- [Joshu Coats](https://github.com/rhwlo)
41 changes: 23 additions & 18 deletions update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func checkFromHomebrew(check *Options) error {
return errors.Wrap(err, "failed to parse output of `brew outdated --json=v2`")
}

for _, o := range outdated {
for _, o := range outdated.Formulae {
if o.Name == "circleci" {
if len(o.InstalledVersions) > 0 {
check.Current = semver.MustParse(o.InstalledVersions[0])
Expand All @@ -104,23 +104,28 @@ func checkFromHomebrew(check *Options) error {
// HomebrewOutdated wraps the JSON output from running `brew outdated --json=v2`
// We're specifically looking for this kind of structured data from the command:
//
// [
// {
// "name": "circleci",
// "installed_versions": [
// "0.1.1248"
// ],
// "current_version": "0.1.3923",
// "pinned": false,
// "pinned_version": null
// },
// ]
type HomebrewOutdated []struct {
Name string `json:"name"`
InstalledVersions []string `json:"installed_versions"`
CurrentVersion string `json:"current_version"`
Pinned bool `json:"pinned"`
PinnedVersion string `json:"pinned_version"`
// {
// "formulae": [
// {
// "name": "circleci",
// "installed_versions": [
// "0.1.1248"
// ],
// "current_version": "0.1.3923",
// "pinned": false,
// "pinned_version": null
// }
// ],
// "casks": []
// }
type HomebrewOutdated struct {
Formulae []struct {
Name string `json:"name"`
InstalledVersions []string `json:"installed_versions"`
CurrentVersion string `json:"current_version"`
Pinned bool `json:"pinned"`
PinnedVersion string `json:"pinned_version"`
} `json:"formulae"`
}

// Options contains everything we need to check for or perform updates of the CLI.
Expand Down

0 comments on commit cf6a918

Please sign in to comment.