-
Notifications
You must be signed in to change notification settings - Fork 727
/
Copy pathupload-dist.js
60 lines (47 loc) · 1.69 KB
/
upload-dist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Uploads a file to the webhintio/hint "dist" release.
* `node scripts/upload-dist.js fileName.zip`
*
* A valid GitHub auth token needs to be set in
* `process.env.GITHUB_TOKEN`
*/
const path = require('path');
const fs = require('fs');
const Octokit = require('@octokit/rest').Octokit;
const throttling = require('@octokit/plugin-throttling').throttling;
const Client = Octokit.plugin(throttling);
const octokitOptions = {
auth: `token ${process.env.GITHUB_TOKEN}`, // eslint-disable-line no-process-env
throttle: {
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.log(`Abuse detected for request ${options.method} ${options.url}`);
},
onRateLimit: (retryAfter, options) => {
console.log(`Request quota exhausted for request ${options.method} ${options.url}`);
if (options.request.retryCount <= 4) { // retry 5 times
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
return false;
}
},
userAgent: 'Nellie The Narwhal'
};
const kit = new Client(octokitOptions);
const name = process.argv[2];
const data = fs.readFileSync(path.join(process.cwd(), name)); // eslint-disable-line no-sync
const upload = async () => {
console.log('Uploading');
await kit.repos.uploadReleaseAsset({
file: data,
headers: {
'content-length': data.length,
'content-type': 'application/zip'
},
name,
url: 'https://uploads.github.com/repos/webhintio/hint/releases/20378720/assets{?name,label}'
});
console.log('File uploaded');
};
upload();