diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 68ed693f..934e0c44 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -19,17 +19,13 @@ export default class API { return this.request("/user"); } - isCollaborator(user) { - return this.request('/user/repos').then((repos) => { - let contributor = false - for (const repo of repos) { - if (repo.full_name.toLowerCase() === this.repo.toLowerCase() && repo.permissions.push) contributor = true; - } - return contributor; - }).catch((error) => { - console.error("Problem with response of /user/repos from GitHub"); - throw error; - }) + hasWriteAccess() { + return this.request(this.repoURL) + .then(repo => repo.permissions.push) + .catch(error => { + console.error("Problem fetching repo data from GitHub"); + throw error; + }); } requestHeaders(headers = {}) { diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index 116f6789..8f978fa0 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -32,7 +32,7 @@ export default class GitHub { this.token = state.token; this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root }); return this.api.user().then(user => - this.api.isCollaborator(user.login).then((isCollab) => { + this.api.hasWriteAccess().then((isCollab) => { // Unauthorized user if (!isCollab) throw new Error("Your GitHub user account does not have access to this repo."); // Authorized user