@dog-ai/github-wrapper
Advanced tools
Comparing version 1.1.5 to 1.1.6
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/* | ||
@@ -11,14 +7,12 @@ * Copyright (C) 2017, Hugo Freire <hugo@dog.ai>. All rights reserved. | ||
var _ = require('lodash'); | ||
var Promise = require('bluebird'); | ||
const _ = require('lodash'); | ||
const Promise = require('bluebird'); | ||
var GitHub = require('github'); | ||
const GitHub = require('github'); | ||
var all = function all(fn, params) { | ||
var _this = this; | ||
const all = function all(fn, params) { | ||
return new Promise((resolve, reject) => { | ||
let data = []; | ||
return new Promise(function (resolve, reject) { | ||
var data = []; | ||
var next = function next(error, page) { | ||
const next = (error, page) => { | ||
if (error) { | ||
@@ -30,4 +24,4 @@ return reject(error); | ||
if (_this.github.hasNextPage(page)) { | ||
_this.github.getNextPage(page, next); | ||
if (this.github.hasNextPage(page)) { | ||
this.github.getNextPage(page, next); | ||
} else { | ||
@@ -42,19 +36,17 @@ resolve(data); | ||
var defaultOptions = { auth: {} }; | ||
const defaultOptions = { auth: {} }; | ||
var GitHubWrapper = function () { | ||
function GitHubWrapper() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOptions; | ||
class GitHubWrapper { | ||
constructor(options = defaultOptions) { | ||
var _$defaults = _.defaults(options, defaultOptions); | ||
_classCallCheck(this, GitHubWrapper); | ||
const auth = _$defaults.auth; | ||
var _$defaults = _.defaults(options, defaultOptions), | ||
auth = _$defaults.auth; | ||
this.github = new GitHub({ Promise: Promise }); | ||
this.github = new GitHub({ Promise }); | ||
var type = auth.type; | ||
const type = auth.type; | ||
switch (type) { | ||
case 'token': | ||
this.github.authenticate({ type: type, token: auth.token }); | ||
this.github.authenticate({ type, token: auth.token }); | ||
break; | ||
@@ -65,103 +57,73 @@ default: | ||
_createClass(GitHubWrapper, [{ | ||
key: 'getUser', | ||
value: function getUser() { | ||
return this.github.users.get({}).then(function (page) { | ||
return page.data; | ||
}); | ||
} | ||
}, { | ||
key: 'getUserOrgs', | ||
value: function getUserOrgs() { | ||
return this.github.users.getOrgMemberships({}).then(function (page) { | ||
return page.data; | ||
}).mapSeries(function (orgMembership) { | ||
return orgMembership.organization.login; | ||
}); | ||
} | ||
}, { | ||
key: 'getOrgRepos', | ||
value: function getOrgRepos(owner) { | ||
return all.bind(this)(this.github.repos.getAll, { per_page: 100 }).then(function (repos) { | ||
return _.filter(repos, { owner: { login: owner } }); | ||
}); | ||
} | ||
}, { | ||
key: 'getRepoPullRequestsByState', | ||
value: function getRepoPullRequestsByState(owner, repo, state) { | ||
var _this2 = this; | ||
getUser() { | ||
return this.github.users.get({}).then(page => page.data); | ||
} | ||
return all.bind(this)(this.github.pullRequests.getAll, { | ||
owner: owner, | ||
repo: repo, | ||
state: state, | ||
per_page: 100, | ||
sort: 'created', | ||
direction: 'asc' | ||
}).mapSeries(function (pullRequest) { | ||
var ref = pullRequest.head.sha; | ||
return all.bind(_this2)(_this2.github.repos.getCombinedStatus, { | ||
owner: owner, | ||
repo: repo, | ||
ref: ref, | ||
per_page: 100 | ||
}).then(function (combinedStatus) { | ||
pullRequest.combinedStatus = combinedStatus; | ||
getUserOrgs() { | ||
return this.github.users.getOrgMemberships({}).then(page => page.data).mapSeries(orgMembership => orgMembership.organization.login); | ||
} | ||
return pullRequest; | ||
}); | ||
getOrgRepos(owner) { | ||
return all.bind(this)(this.github.repos.getAll, { per_page: 100 }).then(repos => _.filter(repos, { owner: { login: owner } })); | ||
} | ||
getRepoPullRequestsByState(owner, repo, state) { | ||
return all.bind(this)(this.github.pullRequests.getAll, { | ||
owner, | ||
repo, | ||
state, | ||
per_page: 100, | ||
sort: 'created', | ||
direction: 'asc' | ||
}).mapSeries(pullRequest => { | ||
const ref = pullRequest.head.sha; | ||
return all.bind(this)(this.github.repos.getCombinedStatus, { | ||
owner, | ||
repo, | ||
ref, | ||
per_page: 100 | ||
}).then(combinedStatus => { | ||
pullRequest.combinedStatus = combinedStatus; | ||
return pullRequest; | ||
}); | ||
} | ||
}, { | ||
key: 'mergePullRequest', | ||
value: function mergePullRequest(owner, repo, number, sha) { | ||
return this.github.pullRequests.merge({ owner: owner, repo: repo, number: number, sha: sha }); | ||
} | ||
}, { | ||
key: 'mergeGreenkeeperPullRequests', | ||
value: function mergeGreenkeeperPullRequests(owner) { | ||
var _this3 = this; | ||
}); | ||
} | ||
var mergedPullRequests = []; | ||
mergePullRequest(owner, repo, number, sha) { | ||
return this.github.pullRequests.merge({ owner, repo, number, sha }); | ||
} | ||
var mergeGreenkeeperPullRequest = function mergeGreenkeeperPullRequest(owner, repoName, pullRequest) { | ||
var isGreenkeeper = pullRequest.user.login === 'greenkeeper[bot]'; | ||
var isSuccess = pullRequest.combinedStatus[0].state === 'success'; | ||
var statuses = pullRequest.combinedStatus[0].statuses; | ||
var isVerified = _.find(statuses, { context: 'greenkeeper/verify', state: 'success' }); | ||
mergeGreenkeeperPullRequests(owner) { | ||
const mergedPullRequests = []; | ||
if (isGreenkeeper && isSuccess && isVerified) { | ||
var number = pullRequest.number; | ||
var sha = pullRequest.sha; | ||
const mergeGreenkeeperPullRequest = (owner, repoName, pullRequest) => { | ||
const isGreenkeeper = pullRequest.user.login === 'greenkeeper[bot]'; | ||
const isSuccess = pullRequest.combinedStatus[0].state === 'success'; | ||
const statuses = pullRequest.combinedStatus[0].statuses; | ||
const isVerified = _.find(statuses, { context: 'greenkeeper/verify', state: 'success' }); | ||
return _this3.mergePullRequest(owner, repoName, number, sha).then(function () { | ||
return mergedPullRequests.push({ owner: owner, repoName: repoName, number: number, sha: sha, success: true }); | ||
}).catch(function (error) { | ||
return mergedPullRequests.push({ | ||
owner: owner, | ||
repoName: repoName, | ||
number: number, | ||
sha: sha, | ||
success: false, | ||
error: error | ||
}); | ||
}); | ||
} | ||
}; | ||
if (isGreenkeeper && isSuccess && isVerified) { | ||
const number = pullRequest.number; | ||
const sha = pullRequest.sha; | ||
return this.getOrgRepos(owner).mapSeries(function (repo) { | ||
var repoName = repo.name; | ||
return this.mergePullRequest(owner, repoName, number, sha).then(() => mergedPullRequests.push({ owner, repoName, number, sha, success: true })).catch(error => mergedPullRequests.push({ | ||
owner, | ||
repoName, | ||
number, | ||
sha, | ||
success: false, | ||
error | ||
})); | ||
} | ||
}; | ||
return _this3.getRepoPullRequestsByState(owner, repoName, 'open').mapSeries(function (pullRequest) { | ||
return mergeGreenkeeperPullRequest(owner, repoName, pullRequest); | ||
}).catch(function () {}); | ||
}).then(function () { | ||
return mergedPullRequests; | ||
}).catch(function () {}); | ||
} | ||
}]); | ||
return this.getOrgRepos(owner).mapSeries(repo => { | ||
const repoName = repo.name; | ||
return GitHubWrapper; | ||
}(); | ||
return this.getRepoPullRequestsByState(owner, repoName, 'open').mapSeries(pullRequest => mergeGreenkeeperPullRequest(owner, repoName, pullRequest)).catch(() => {}); | ||
}).then(() => mergedPullRequests).catch(() => {}); | ||
} | ||
} | ||
module.exports = GitHubWrapper; |
{ | ||
"name": "@dog-ai/github-wrapper", | ||
"description": "A GitHub wrapper library", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"main": "lib/index.js", | ||
@@ -17,26 +17,26 @@ "repository": { | ||
"dependencies": { | ||
"bluebird": "3.4.6", | ||
"github": "9.0.0", | ||
"lodash": "4.17.2" | ||
"bluebird": "3.5.0", | ||
"github": "9.2.0", | ||
"lodash": "4.17.4" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.23.0", | ||
"babel-preset-es2015": "6.22.0", | ||
"chai": "3.5.0", | ||
"chai-as-promised": "6.0.0", | ||
"coveralls": "2.11.16", | ||
"eslint": "3.19.0", | ||
"babel-cli": "6.24.1", | ||
"babel-preset-env": "1.6.1", | ||
"chai": "4.0.2", | ||
"chai-as-promised": "7.0.0", | ||
"coveralls": "2.13.1", | ||
"eslint": "4.0.0", | ||
"eslint-config-hfreire": "1.0.6", | ||
"eslint-plugin-import": "2.3.0", | ||
"eslint-plugin-import": "2.6.1", | ||
"eslint-plugin-json": "1.2.0", | ||
"eslint-plugin-mocha": "4.9.0", | ||
"eslint-plugin-mocha": "4.11.0", | ||
"eslint-plugin-node": "5.0.0", | ||
"eslint-plugin-promise": "3.5.0", | ||
"eslint-plugin-standard": "3.0.1", | ||
"eslint-plugin-unicorn": "2.1.1", | ||
"eslint-plugin-unicorn": "2.1.2", | ||
"istanbul": "0.4.5", | ||
"mocha": "3.2.0", | ||
"semantic-release": "6.3.2", | ||
"pre-git": "3.13.0", | ||
"testdouble": "2.1.2" | ||
"mocha": "3.4.2", | ||
"semantic-release": "6.3.6", | ||
"pre-git": "3.15.0", | ||
"testdouble": "3.1.1" | ||
}, | ||
@@ -43,0 +43,0 @@ "config": { |
@@ -6,2 +6,3 @@ # A :octocat: GitHub :package: wrapper library | ||
[![Coverage Status](https://coveralls.io/repos/github/dog-ai/github-wrapper/badge.svg?branch=master)](https://coveralls.io/github/dog-ai/github-wrapper?branch=master) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/dog-ai/github-wrapper.svg)](https://greenkeeper.io/) | ||
[![](https://img.shields.io/github/release/dog-ai/github-wrapper.svg)](https://github.com/dog-ai/github-wrapper/releases) | ||
@@ -8,0 +9,0 @@ [![](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32
8095
101
+ Addedbluebird@3.5.0(transitive)
+ Addedgithub@9.2.0(transitive)
+ Addedlodash@4.17.4(transitive)
- Removedbluebird@3.4.6(transitive)
- Removedgithub@9.0.0(transitive)
- Removedlodash@4.17.2(transitive)
Updatedbluebird@3.5.0
Updatedgithub@9.2.0
Updatedlodash@4.17.4