1 | const cli = require('heroku-cli-util')
|
2 | const GITHUB_API = 'https://api.github.com'
|
3 |
|
4 | module.exports = class GitHubAPI {
|
5 | constructor (version, token) {
|
6 | this.version = version
|
7 | this.token = token
|
8 | }
|
9 |
|
10 | request (url, options = {}) {
|
11 | options.headers = Object.assign({
|
12 | Authorization: `Token ${this.token}`,
|
13 | 'User-Agent': this.version
|
14 | }, options.headers)
|
15 |
|
16 | options.json = true
|
17 |
|
18 | return cli.got.get(`${GITHUB_API}${url}`, options)
|
19 | }
|
20 |
|
21 | getRepo (name) {
|
22 | return this.request(`/repos/${name}`).then((res) => res.body)
|
23 | }
|
24 |
|
25 | getArchiveURL (repo, ref) {
|
26 | return this.request(`/repos/${repo}/tarball/${ref}`, {
|
27 | followRedirect: false
|
28 | }).then((res) => res.headers.location)
|
29 | }
|
30 | }
|