How to download private GitHub asset?ΒΆ

If you want to download private GitHub asset you have to use GitHub API. First you have to find out URL with asset id. For example get info about tag v3.2.1 using curl command:

> curl -s -u \
    ${username}:${token} \
    https://api.github.com/repos/${orgname}/${reponame}/releases/tags/v3.2.1

Name, id and URL of asset:

> curl -s -u \
    ${username}:${token} \
    https://api.github.com/repos/${orgname}/${reponame}/releases/tags/v3.2.1 \
    | grep -A3 '"url":.*assets'

    "url": "https://api.github.com/repos/.../.../releases/assets/7654321",
    "id": 7654321,
    "name": "hello.txt",
    "label": null,

Use asset URL in hunter_private_data and add extra Accept:application/octet-stream header:

# CMakeLists.txt

hunter_private_data(
    URL "https://api.github.com/repos/${orgname}/${reponame}/releases/assets/7654321"
    SHA1 "..."
    CREDENTIALS "github"
    HTTPHEADER "Accept:application/octet-stream"
    FILE hello.txt
    LOCATION myfile
)

Add GitHub credentials using hunter_private_data_password:

# ~/.config/Hunter/passwords.cmake

hunter_private_data_password(
    CREDENTIALS "github"
    USERNAME "${username}"
    PASSWORD "${github_token}"
)