node.jsoctokit-js

How to download a github release by code, not by a CLI


I am making a bot that can grab a source.zip / source.targz from Github, then implement it into my app and new changes are applied, but I have not found a way to download a release because the @Octokit/Rest module I'm using only gets the release. Not download. Other npm packages don't work for me and if so, the node_modules folder can get really big, around 19mb. When I do a https GET request, Github requires me to use a USERAGENT, but I don't know how to tie in Octokit with plain HTTPS requests.

I want to be able to download releases by code, but what I get is the following in the zipfile I tie it to:

Request forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.

    var file = fs.createWriteStream('bot.zip')
    var request = await https.get(releases[num].zipball_url, function(response) {
        response.pipe(file)
    })

//https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries
var octokit = new Octokit.Octokit({
        userAgent: 'Github Bot Updater',
        previews: ['jean-grey', 'symmetra'],
        baseUrl: 'https://api.github.com',
        log: {
            debug: () => {},
            info: () => {},
            warn: console.warn,
            error: console.error
          },
          request: {
            agent: undefined,
            fetch: undefined,
            timeout: 0
          }
    })
    var releases = await octokit.paginate("GET /repos/:owner/:repo/releases", {  owner: username,  repo: reponame})
//octokit has no method for downloading a release

Solution

  • What I did was instead of getting the zipball from the release, you can also get the same thing from going to the main repo page, then going to the branches button in the corner, going to tags and the desired release tag. Then after you click on that you can download that release. When I looked into that, instead of doing

    releases[num].zipball_url in

        var request = await https.get(releases[num].zipball_url, function(response) {
            response.pipe(file)
        })
    

    You can do

    https://codeload.github.com/${username}/${reponame}/zip/${releases[num].tag_name}

    And that works.