Is there a link to GitHub for downloading a file in the latest release of a repository?

前端 未结 18 2273
情深已故
情深已故 2020-12-02 04:26

Using GitHub\'s Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-pag

18条回答
  •  失恋的感觉
    2020-12-02 05:13

    Not possible according to GitHub support as of 2018-05-23

    Contacted support@github.com on 2018-05-23 with message:

    Can you just confirm that there is no way besides messing with API currently?

    and they replied:

    Thanks for reaching out. We recommend using the API to fetch the latest release because that approach is stable, documented, and not subject to change any time soon:

    https://developer.github.com/v3/repos/releases/#get-the-latest-release

    I will also keep tracking this at: https://github.com/isaacs/github/issues/658

    Python solution without any dependencies

    Robust and portable:

    #!/usr/bin/env python3
    
    import json
    import urllib.request
    
    _json = json.loads(urllib.request.urlopen(urllib.request.Request(
        'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases/latest',
         headers={'Accept': 'application/vnd.github.v3+json'},
    )).read())
    asset = _json['assets'][0]
    urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])
    

    See also:

    • What is the quickest way to HTTP GET in Python?
    • Basic http file downloading and saving to disk in python?

    Also consider pre-releases

    /latest does not see pre-releases, but it is easy to do since /releases shows the latest one first:

    #!/usr/bin/env python3
    
    import json
    import urllib.request
    
    _json = json.loads(urllib.request.urlopen(urllib.request.Request(
        'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases',
         headers={'Accept': 'application/vnd.github.v3+json'},
    )).read())
    asset = _json[0]['assets'][0]
    urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])
    

提交回复
热议问题