| 7 | const exec = util.promisify(cp.exec); |
| 8 | |
| 9 | export default class GithubAPI { |
| 10 | constructor(owner, repo) { |
| 11 | if (!owner) { |
| 12 | throw new Error('repo owner must be specified'); |
| 13 | } |
| 14 | |
| 15 | if (!repo) { |
| 16 | throw new Error('repo must be specified'); |
| 17 | } |
| 18 | |
| 19 | this.repo = repo; |
| 20 | this.owner = owner; |
| 21 | this.axios = githubAxios.create({ |
| 22 | baseURL: `https://api.github.com/repos/${this.owner}/${this.repo}/`, |
| 23 | }) |
| 24 | } |
| 25 | |
| 26 | async createComment(issue, body) { |
| 27 | return (await this.axios.post(`/issues/${issue}/comments`, {body})).data; |
| 28 | } |
| 29 | |
| 30 | async getComments(issue, {desc = false, per_page= 100, page = 1} = {}) { |
| 31 | return (await this.axios.get(`/issues/${issue}/comments`, {params: {direction: desc ? 'desc' : 'asc', per_page, page}})).data; |
| 32 | } |
| 33 | |
| 34 | async getComment(id) { |
| 35 | return (await this.axios.get(`/issues/comments/${id}`)).data; |
| 36 | } |
| 37 | |
| 38 | async updateComment(id, body) { |
| 39 | return (await this.axios.patch(`/issues/comments/${id}`, {body})).data; |
| 40 | } |
| 41 | |
| 42 | async appendLabels(issue, labels) { |
| 43 | return (await this.axios.post(`/issues/${issue}/labels`, {labels})).data; |
| 44 | } |
| 45 | |
| 46 | async getUser(user) { |
| 47 | return (await githubAxios.get(`/users/${user}`)).data; |
| 48 | } |
| 49 | |
| 50 | async isCollaborator(user) { |
| 51 | try { |
| 52 | return (await this.axios.get(`/collaborators/${user}`)).status === 204; |
| 53 | } catch (e) { |
| 54 | |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | async deleteLabel(issue, label) { |
| 59 | return (await this.axios.delete(`/issues/${issue}/labels/${label}`)).data; |
| 60 | } |
| 61 | |
| 62 | async getIssue(issue) { |
| 63 | return (await this.axios.get(`/issues/${issue}`)).data; |
| 64 | } |
| 65 | |
| 66 | async getPR(issue) { |
nothing calls this directly
no outgoing calls
no test coverage detected