Skip to content

Commit

Permalink
Upgrade github package
Browse files Browse the repository at this point in the history
`github` package is now called `@octokit/rest` [1]

[1] https://github.com/octokit/rest.js/releases/tag/v14.0.0
  • Loading branch information
walac committed Apr 24, 2020
1 parent 5a58d96 commit b03c024
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 29 deletions.
33 changes: 14 additions & 19 deletions deploy/bin/github-release.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env node
const GithubApi = require('github');
const { Octokit } = require('@octokit/rest');
const fs = require('fs');
const mime = require('mime');
const path = require('path');
const dateformat = require('dateformat');

const RELEASE_NAME = dateformat(new Date(), 'vyyyymmddHHMM', true);
const OWNER = 'taskcluster';
const REPO = 'docker-worker';
const REPO = 'docker-worker-deploy';

function signin() {
if (!process.env.DOCKER_WORKER_GITHUB_TOKEN) {
Expand All @@ -16,49 +15,45 @@ function signin() {
);
}

const github = new GithubApi({
const github = new Octokit({
timeout: 5000,
host: 'api.github.com',
protocol: 'https',
headers: {
'user-agent': 'docker-worker'
'user-agent': REPO,
},
rejectUnauthorized: false, // default: true
});

github.authenticate({
type: 'token',
token: process.env.DOCKER_WORKER_GITHUB_TOKEN,
auth: process.env.DOCKER_WORKER_GITHUB_TOKEN,
});

return github;
}

function createRelease(github) {
return github.repos.createRelease({
owner: 'taskcluster',
repo: 'docker-worker',
owner: OWNER,
repo: REPO,
tag_name: RELEASE_NAME,
name: RELEASE_NAME,
});
}

// upload a file as a release asset
function uploadFile(github, filename) {
const stat = fs.statSync(filename);
const stream = fs.createReadStream(filename);
console.log(`Uploading ${filename}`);
const stream = fs.readFileSync(filename);

return github.repos.getReleaseByTag({
owner: OWNER,
repo: REPO,
tag: RELEASE_NAME,
}).then(result => {
return github.repos.uploadAsset({
url: result.data.upload_url,
file: stream,
contentType: mime.lookup(filename),
contentLength: stat.size,
return github.repos.uploadReleaseAsset({
owner: OWNER,
repo: REPO,
release_id: result.data.id,
name: path.basename(filename),
data: stream,
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
},
"homepage": "https://github.com/taskcluster/docker-worker-deploy#readme",
"dependencies": {
"@octokit/rest": "^17.6.0",
"dateformat": "^3.0.3",
"github": "^14.0.0",
"json-templater": "^1.2.0",
"mime": "^2.4.4",
"mkdirp": "^1.0.4",
"tweetnacl": "^1.0.3"
}
Expand Down
Loading

0 comments on commit b03c024

Please sign in to comment.