Skip to content

Extend gh release list to add --json flag #4572

Description

@stevehipwell

Describe the feature or problem you’d like to solve

With GitHub being the primary source of OSS software it's a pretty common requirement to install the latest version from GitHub releases. The issue is that the current gh release list command has no way of getting the latest version, defining the sort order or filtering by release name. This is made even harder to implement by the lack of JSON output from the gh release list command.

Proposed solution

Support the --json and --jq flags that are in gh release view. It would be great is the --json flag worked without a value or with a catch-all such as --json ALL to return all fields.

Additional context

n/a

Activity

  1. mislav commented on Oct 20, 2021

    @mislav
    Contributor

    The issue is that the current gh release list command has no way of getting the latest version, defining the sort order or filtering by release name. This is made even harder to implement by the lack of JSON output from the gh release list command.

    All true, however: if the main goal is to get the latest version, it's easy to do so with gh release view, including JSON output:

    $ gh release view -R cli/cli --json assets --jq '.assets[].url'
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_checksums.txt
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_386.deb
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_386.rpm
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_386.tar.gz
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_amd64.deb
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_amd64.rpm
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_amd64.tar.gz
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_arm64.deb
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_arm64.rpm
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_arm64.tar.gz
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_armv6.deb
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_armv6.rpm
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_armv6.tar.gz
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_macOS_amd64.tar.gz
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_windows_386.zip
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_windows_amd64.msi
    https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_windows_amd64.zip
    

    What would you like to sort the gh release list output by? Also, what exactly do you mean by filtering by release name—can you provide some examples?

  2. stevehipwell commented on Oct 20, 2021

    @stevehipwell
    Author

    @mislav thanks for your example for using gh release view.

    In answer to your questions. The last release isn't necessarily the latest release in respect to versioning (the latest tag is a whole new issue for another repo), so being able to sort by the release name or part of it is important. Some releases have a release name before the version so zulu-zebra-1.0.0 would alpha sort later than active-aardvark-2.0.0 despite being an older version, so this needs to be handled. Filtering is required for repos with multiple release types, e.g. Helm charts, where you might only be interested in releases following the format v* or release without the format helm-chart-*.

  3. mislav commented on Oct 20, 2021

    @mislav
    Contributor

    The last release isn't necessarily the latest release in respect to versioning

    You're right. Currently what GitHub calls a "latest" release isn't necessary latest by version number, but it's the latest published release by date. I don't think that's ideal, but it's something to be potentially fixed on the GitHub platform, not in the CLI itself.

    so being able to sort by the release name or part of it is important.

    By release name, do you mean the tag name? And by sorting by tag name, which exact sorting algorithm are you referring to? I'm not familiar with a version scheme like active-aardvark-2.0.0; how would a user describe to the CLI that the active-aardvark- portion should be discarded when sorting versions?

    Filtering is required for repos with multiple release types

    Similar question to above: if someone needs to implement release filtering based on arbitrary criteria, why and how would we implement that as a flag to gh release list? Isn't it a better idea that someone takes the output of gh release list as it is right now and implements their own filtering however they want? Or are you simply asking for a flag that takes in a glob-like pattern (e.g. v*) and only outputs releases that match the pattern?

  4. stevehipwell commented on Oct 20, 2021

    @stevehipwell
    Author

    @mislav I think I've misread the output, it looks like you get name and tag separately, the active-aardvark-2.0.0 release would be a name on a 2.0.0 tag.

    I'm under the impression that the --jq functionality would allow filtering and sorting so it looks like gh release view might be the solution? If this is the case did I miss something in the docs? I would like to see an easier way to get all fields via the --json flag as that would help discovery.

  5. mislav commented on Oct 20, 2021

    @mislav
    Contributor

    I would like to see an easier way to get all fields via the --json flag as that would help discovery.

    gh release view --json will list all available JSON fields.

    Note, however, that gh release view can only show information about a single release at a time. For generic filtering needs, you can use gh release list to filter through all releases. For example, this simple script grabs the 3rd column of gh release list (the tag name) and outputs only ones that start with v1.12.:

    $ gh release list -R cli/cli --limit 999 | awk -F '\t' '{if (match($3, "^v1\.12\.")) print $3}'
    v1.12.1
    v1.12.1-pre.0
    v1.12.0
    v1.12.0-pre.4
    v1.12.0-pre.2
    v1.12.0-pre.1
    v1.12.0-pre.0
    
  6. stevehipwell commented on Oct 20, 2021

    @stevehipwell
    Author

    Personally I'd like (an expected when looking to use this) gh release view --repo <repo> --json to return the whole objects not a list of fields.

    I think adding a --json flag to gh release list would be the best way forward.

  7. mislav commented on Oct 20, 2021

    @mislav
    Contributor

    I think adding a --json flag to gh release list would be the best way forward.

    Agreed! Should I rename this issue to be about adding the relase list --json functionality then?

    Personally I'd like (an expected when looking to use this) gh release view --repo <repo> --json to return the whole objects not a list of fields.

    That's a valid remark, but we generally cannot show a "whole" object for JSON output because the underlying API requests are mostly GraphQL requests, and GraphQL requests always require you to explicitly list all the fields that you want to see in the response. Hence we always require users to enumerate the kind of data they want to see in the JSON result.

  8. stevehipwell commented on Oct 21, 2021

    @stevehipwell
    Author

    @mislav I'll rename the issue as suggested.

    That's a valid remark, but we generally cannot show a "whole" object for JSON output because the underlying API requests are mostly GraphQL requests, and GraphQL requests always require you to explicitly list all the fields that you want to see in the response. Hence we always require users to enumerate the kind of data they want to see in the JSON result.

    I get that implementing --json without a value would require two GraphQL calls, but that's an implementation detail (you can implement a catch all parameter in you GraphQL server code using the same logic as you use for listing the available fields). As a user I don't want to know about the implementation, I want to know abut the data. If the fields are dynamic as you say there is even more reason to support the empty --json flag, otherwise every time I want to investigate this tool I need to call the command to return all possible fields and then manually concatenate them into the --json flag values to get the full data context.

  9. changed the title [-]Extend `gh release list` to support ordering and filtering[/-] [+]Extend `gh release list` to add `--json` flag[/+] on Oct 21, 2021
  10. added and removed
    more-info-neededMore info needed from user/contributor
    on Feb 28, 2022
  11. 13 remaining items

  12. justinmchase commented on Jun 29, 2023

    @justinmchase

    json should be the default and --output table should be required to get a non-json view.

  13. 007vasy commented on Jul 5, 2023

    @007vasy

    any progress on this?

  14. tarlepp commented on Sep 6, 2023

    @tarlepp

    This is something that I need too.

  15. jakeatoms commented on Oct 30, 2023

    @jakeatoms

    @mislav I'm picking this up to work on this week and part of my attempt to learn some Go. I've already got the basic --json argument working that prints the available fields. I've even got support for a list of fields (tagName, etc), however, it only works with tagName and panics with anything else 🙃. I'd love to get a draft PR open to elicit some early feedback. Is that something that's OK in this repo?

  16. jakeatoms commented on Oct 31, 2023

    @jakeatoms

    @mislav I recall seeing some discussion about needing to migrate the release list code over to REST. Is that still the case and would you like that done in a separate PR to the --json work? I do think the change would have an impact on the output for the current list command (without JSON) in that the REST API does not return a latest property.

    EDIT:
    I found the original quote from above and I have it backwards. You want to standardize both Release commands on GraphQL. Right now, list is GraphQL while view is REST.

    To reach gh release list --json parity with gh release view --json, we might have to significantly restructure how gh release list API calls are implemented: right now they are REST but I think we should move to GraphQL. If we continue to use two different API flavors to implement two related gh commands, I think we may run into inconsistencies.

  17. samcoe commented on Nov 1, 2023

    @samcoe
    Contributor

    @jakeatoms Unfortunately Mislav is no longer working at GitHub.

    Regarding this work, it sounds like you are on the right track as we are looking to standardize on using the GraphQL endpoint for both release list and release view. I would be in favor of breaking this work up into two separate PRs. The first to do the switch to the GraphQL endpoint and the second to actually add in the --json flag feature. How does that sound?

  18. jakeatoms commented on Nov 1, 2023

    @jakeatoms

    @samcoe thanks for the update! Yes, I think 2 PRs will work great here. I'll try to get the 1st opened either today or tomorrow.

  19. jakeatoms commented on Nov 1, 2023

    @jakeatoms

    @samcoe There are potentially a number of API-breaking changes moving to GraphQL for view:
    The current --json argument supports returning the following fields that don't exist via GQL:

    Additionally, there are top-level fields on Release via REST that don't exist in GQL, but can be found within the individual Assets:

    So my question is, is maintaining backwards compability important here? Removing these could break any existing scripts that are handling their own uploads or API interactions for a given release. An alternative would be to point users to the other subcommands like upload in order to facilitate additional API actions.

    Side note: The various other release commands like upload can continue to make use of the existing shared code to fetch a release via the REST API, so things like the uploadUrl will still be present.

  20. justinmchase commented on Nov 5, 2023

    @justinmchase

    Can you emit a warning to stderr that said something along the lines of "to retrieve these deprecated fields use the gh rest... or gh release upload... commands instead".

    Also arguably, it would be nice if the user could specify optional subgraphs, since its gql by adding something like --subbraphs assets,uploads or whatever.

  21. samcoe commented on Nov 6, 2023

    @samcoe
    Contributor

    @jakeatoms Thanks for the investigation. I should have double checked what Mislav had stated before giving the go-ahead here. We really care about maintaining backwards compatibility and having this feature cause a breaking change is not something we can move forwards with.

    I am going to propose a different path forward here and that is to instead move gh release list to use the REST API so that both gh release view and gh release list can support the same list of --json fields. There is only one caveat and that is currently gh release list displays an indicator of the latest release, that is not something returned by the REST endpoint so we will have to make on extra API call to retrieve that. I feel like that one extra API call is not a huge deal and allows us to move forward with this work. I suspect that this direction makes #8288 mostly irrelevant now, apologies for that 🙇

  22. jakeatoms commented on Nov 8, 2023

    @jakeatoms

    @jakeatoms Thanks for the investigation. I should have double checked what Mislav had stated before giving the go-ahead here. We really care about maintaining backwards compatibility and having this feature cause a breaking change is not something we can move forwards with.

    I am going to propose a different path forward here and that is to instead move gh release list to use the REST API so that both gh release view and gh release list can support the same list of --json fields. There is only one caveat and that is currently gh release list displays an indicator of the latest release, that is not something returned by the REST endpoint so we will have to make on extra API call to retrieve that. I feel like that one extra API call is not a huge deal and allows us to move forward with this work. I suspect that this direction makes #8288 mostly irrelevant now, apologies for that 🙇

    sounds good! I'll close that other PR and begin work on this design!

  23. bestmike007 commented on Nov 22, 2023

    @bestmike007

    This might help if you need to get the tag name:

    gh release ls | awk '{print $(NF-1)}'
  24. SamEdwardes commented on Dec 14, 2023

    @SamEdwardes

    I want to share my solution (https://cli.github.com/manual/gh_api):

    # get all the release data in JSON
    gh api repos/cli/cli/releases
    
    # get all the tag_names
    gh api repos/cli/cli/releases | jq -r '.[].tag_name'
    
    # get the most recent tag name
    gh api repos/cli/cli/releases | jq -r '.[0].tag_name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-releaserelating to the gh release commandhelp wantedContributions welcome

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions