Comparing version 0.0.13 to 0.0.14
@@ -13,2 +13,6 @@ 'use strict'; | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
@@ -18,6 +22,2 @@ | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _axios = require('axios'); | ||
@@ -31,132 +31,116 @@ | ||
var _types = require('../types'); | ||
require('../types'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var BitbucketPipelinesAdapter = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(config) { | ||
var axiosGetConfig, axiosPostConfig, apiBaseUrl, buildStatus, buildUrl, buildUrlParts, buildId, _this, _this2; | ||
var BitbucketPipelinesAdapter = function BitbucketPipelinesAdapter(config) { | ||
var axiosGetConfig = { | ||
auth: { | ||
username: config.botUsername, | ||
password: config.botPassword | ||
} | ||
}; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
axiosGetConfig = { | ||
auth: { | ||
username: config.botUsername, | ||
password: config.botPassword | ||
} | ||
}; | ||
axiosPostConfig = (0, _extends3.default)({}, axiosGetConfig, { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
apiBaseUrl = `https://api.bitbucket.org/2.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
return _context3.abrupt('return', { | ||
processStatusWebhook(body) { | ||
if (!body || !body.commit_status || !body.commit_status.state || !body.commit_status.url || typeof body.commit_status.url !== 'string') { | ||
_Logger2.default.error({ statusEvent: body }, 'Status event receieved that does not match the shape we were expecting'); | ||
return null; | ||
} | ||
buildStatus = body.commit_status.state; | ||
buildUrl = body.commit_status.url; | ||
var axiosPostConfig = (0, _extends3.default)({}, axiosGetConfig, { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
_Logger2.default.info({ buildUrl, buildStatus }, 'Received build status event'); | ||
// we only care if a status was FAILED, SUCCESSFUL, or STOPPED | ||
if (buildStatus === 'INPROGRESS') return null; | ||
var apiBaseUrl = `https://api.bitbucket.org/2.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
// Status webhooks dont give you build uuid's or even build numbers. We need to get from url | ||
buildUrlParts = buildUrl.split('/'); | ||
buildId = buildUrlParts[buildUrlParts.length - 1]; | ||
return { | ||
processStatusWebhook(body) { | ||
if (!body || !body.commit_status || !body.commit_status.state || !body.commit_status.url || typeof body.commit_status.url !== 'string') { | ||
_Logger2.default.error({ statusEvent: body }, 'Status event receieved that does not match the shape we were expecting'); | ||
return null; | ||
} | ||
var buildStatus = body.commit_status.state; | ||
var buildUrl = body.commit_status.url; | ||
_Logger2.default.info({ buildUrl, buildStatus }, 'Received build status event'); | ||
// we only care if a status was FAILED, SUCCESSFUL, or STOPPED | ||
if (buildStatus === 'INPROGRESS') return null; | ||
// Status webhooks dont give you build uuid's or even build numbers. We need to get from url | ||
var buildUrlParts = buildUrl.split('/'); | ||
var buildId = buildUrlParts[buildUrlParts.length - 1]; | ||
return { | ||
buildUrl, | ||
buildId, | ||
passed: buildStatus === 'SUCCESSFUL' | ||
}; | ||
}, | ||
return { | ||
buildUrl, | ||
buildId, | ||
passed: buildStatus === 'SUCCESSFUL' | ||
}; | ||
}, | ||
createLandBuild(commit) { | ||
_this = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
var data, resp; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_Logger2.default.info({ commit }, 'Creating land build for commit'); | ||
data = { | ||
target: { | ||
commit: { | ||
hash: commit, | ||
type: 'commit' | ||
}, | ||
selector: { | ||
type: 'custom', | ||
pattern: 'landkid' | ||
}, | ||
type: 'pipeline_commit_target' | ||
} | ||
}; | ||
_context.next = 4; | ||
return _axios2.default.post(`${apiBaseUrl}/pipelines/`, (0, _stringify2.default)(data), axiosPostConfig); | ||
createLandBuild(commit) { | ||
var _this = this; | ||
case 4: | ||
resp = _context.sent; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
var data, resp; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_Logger2.default.info({ commit }, 'Creating land build for commit'); | ||
data = { | ||
target: { | ||
commit: { | ||
hash: commit, | ||
type: 'commit' | ||
}, | ||
selector: { | ||
type: 'custom', | ||
pattern: 'landkid' | ||
}, | ||
type: 'pipeline_commit_target' | ||
} | ||
}; | ||
_context.next = 4; | ||
return _axios2.default.post(`${apiBaseUrl}/pipelines/`, (0, _stringify2.default)(data), axiosPostConfig); | ||
_Logger2.default.info({ buildNumber: resp.data.build_number }, 'Created build'); | ||
case 4: | ||
resp = _context.sent; | ||
if (!(!resp.data.build_number || typeof resp.data.build_number !== 'number')) { | ||
_context.next = 9; | ||
break; | ||
} | ||
_Logger2.default.info({ buildNumber: resp.data.build_number }, 'Created build'); | ||
_Logger2.default.error('Response from creating build does not match the shape we expected'); | ||
return _context.abrupt('return', null); | ||
if (!(!resp.data.build_number || typeof resp.data.build_number !== 'number')) { | ||
_context.next = 9; | ||
break; | ||
} | ||
case 9: | ||
return _context.abrupt('return', `${resp.data.build_number}`); | ||
_Logger2.default.error('Response from creating build does not match the shape we expected'); | ||
return _context.abrupt('return', null); | ||
case 10: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}))(); | ||
}, | ||
case 9: | ||
return _context.abrupt('return', `${resp.data.build_number}`); | ||
stopLandBuild(buildId) { | ||
_this2 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return _context2.abrupt('return', true); | ||
case 10: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}))(); | ||
}, | ||
case 1: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this2); | ||
}))(); | ||
} | ||
}); | ||
stopLandBuild(buildId) { | ||
var _this2 = this; | ||
case 4: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, undefined); | ||
})); | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
return _context2.abrupt('return', true); | ||
return function BitbucketPipelinesAdapter(_x) { | ||
return _ref.apply(this, arguments); | ||
case 1: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this2); | ||
}))(); | ||
} | ||
}; | ||
}(); | ||
}; | ||
exports.default = BitbucketPipelinesAdapter; |
@@ -13,2 +13,6 @@ 'use strict'; | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
@@ -18,6 +22,2 @@ | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
require('../types'); | ||
@@ -35,213 +35,202 @@ | ||
var BitbucketAdapter = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(config) { | ||
var USERS_ALLOWED_TO_APPROVE, axiosGetConfig, axiosPostConfig, apiBaseUrl, oldApiBaseUrl, _this, _this2, _this3, _this4, _this5; | ||
var BitbucketAdapter = function BitbucketAdapter(config) { | ||
var USERS_ALLOWED_TO_APPROVE = config.usersAllowedToApprove; | ||
var axiosGetConfig = { | ||
auth: { | ||
username: config.botUsername, | ||
password: config.botPassword | ||
} | ||
}; | ||
return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
USERS_ALLOWED_TO_APPROVE = config.usersAllowedToApprove; | ||
axiosGetConfig = { | ||
auth: { | ||
username: config.botUsername, | ||
password: config.botPassword | ||
} | ||
}; | ||
axiosPostConfig = (0, _extends3.default)({}, axiosGetConfig, { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
apiBaseUrl = `https://api.bitbucket.org/2.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
oldApiBaseUrl = `https://api.bitbucket.org/1.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
return _context6.abrupt('return', { | ||
createComment(pullRequestId, parentCommentId, message) { | ||
_this = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
var data, response; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
data = { content: message }; | ||
var axiosPostConfig = (0, _extends3.default)({}, axiosGetConfig, { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
var apiBaseUrl = `https://api.bitbucket.org/2.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
var oldApiBaseUrl = `https://api.bitbucket.org/1.0/repositories/${config.repoOwner}/${config.repoName}`; | ||
if (parentCommentId) { | ||
data = (0, _extends3.default)({}, data, { parent_id: String(parentCommentId) }); | ||
} | ||
return { | ||
createComment(pullRequestId, parentCommentId, message) { | ||
var _this = this; | ||
_context.next = 4; | ||
return _axios2.default.post(`${oldApiBaseUrl}/pullrequests/${pullRequestId}/comments/`, (0, _stringify2.default)(data), axiosPostConfig); | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
var data, response; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
data = { content: message }; | ||
case 4: | ||
response = _context.sent; | ||
return _context.abrupt('return', response.data.comment_id); | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}))(); | ||
}, | ||
if (parentCommentId) { | ||
data = (0, _extends3.default)({}, data, { parent_id: String(parentCommentId) }); | ||
} | ||
// This is run when a build is at the front of the queue | ||
isAllowedToLand(pullRequestId) { | ||
_this2 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var pullRequest, buildStatuses, isOpen, createdBy, isApproved, isGreen, isAllowed; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return _this2.getPullRequest(pullRequestId); | ||
_context.next = 4; | ||
return _axios2.default.post(`${oldApiBaseUrl}/pullrequests/${pullRequestId}/comments/`, (0, _stringify2.default)(data), axiosPostConfig); | ||
case 2: | ||
pullRequest = _context2.sent; | ||
_context2.next = 5; | ||
return _this2.getPullRequestBuildStatuses(pullRequestId); | ||
case 4: | ||
response = _context.sent; | ||
return _context.abrupt('return', response.data.comment_id); | ||
case 5: | ||
buildStatuses = _context2.sent; | ||
isOpen = pullRequest.state === 'OPEN'; | ||
createdBy = pullRequest.author.username; | ||
isApproved = pullRequest.participants.some(function (participant) { | ||
return participant.approved && !participant.user.username !== createdBy && USERS_ALLOWED_TO_APPROVE.indexOf(participant.user.username) > -1 || participant.approved && !participant.user.username === 'luke_batchelor'; | ||
}); | ||
isGreen = buildStatuses.every(function (buildStatus) { | ||
return buildStatus.state === 'SUCCESSFUL'; | ||
}); | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, _this); | ||
}))(); | ||
}, | ||
_Logger2.default.info({ pullRequestId, isOpen, isApproved, isGreen }, 'isAllowedToLand()'); | ||
isAllowed = isOpen && isApproved && isGreen; | ||
return _context2.abrupt('return', { isOpen, isApproved, isGreen, isAllowed }); | ||
// This is run when a build is at the front of the queue | ||
isAllowedToLand(pullRequestId) { | ||
var _this2 = this; | ||
case 13: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this2); | ||
}))(); | ||
}, | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var pullRequest, buildStatuses, isOpen, createdBy, isApproved, isGreen, isAllowed; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return _this2.getPullRequest(pullRequestId); | ||
mergePullRequest(pullRequestId) { | ||
_this3 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { | ||
var endpoint, data, resp; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}/merge`; | ||
data = { | ||
close_source_branch: true, | ||
message: 'Merged by Landkid after successful build rebased on Master', | ||
merge_strategy: 'merge_commit' | ||
}; | ||
case 2: | ||
pullRequest = _context2.sent; | ||
_context2.next = 5; | ||
return _this2.getPullRequestBuildStatuses(pullRequestId); | ||
_Logger2.default.info({ pullRequestId, endpoint }, 'Merging pull request'); | ||
_context3.prev = 3; | ||
_context3.next = 6; | ||
return _axios2.default.post(endpoint, (0, _stringify2.default)(data), axiosPostConfig); | ||
case 5: | ||
buildStatuses = _context2.sent; | ||
isOpen = pullRequest.state === 'OPEN'; | ||
createdBy = pullRequest.author.username; | ||
isApproved = pullRequest.participants.some(function (participant) { | ||
return participant.approved && !participant.user.username !== createdBy && USERS_ALLOWED_TO_APPROVE.indexOf(participant.user.username) > -1; | ||
}); | ||
isGreen = buildStatuses.every(function (buildStatus) { | ||
return buildStatus.state === 'SUCCESSFUL'; | ||
}); | ||
case 6: | ||
resp = _context3.sent; | ||
_Logger2.default.info({ pullRequestId, isOpen, isApproved, isGreen }, 'isAllowedToLand()'); | ||
isAllowed = isOpen && isApproved && isGreen; | ||
return _context2.abrupt('return', { isOpen, isApproved, isGreen, isAllowed }); | ||
_Logger2.default.info({ pullRequestId }, 'Merged Pull Request'); | ||
_context3.next = 14; | ||
break; | ||
case 13: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this2); | ||
}))(); | ||
}, | ||
case 10: | ||
_context3.prev = 10; | ||
_context3.t0 = _context3['catch'](3); | ||
mergePullRequest(pullRequestId) { | ||
var _this3 = this; | ||
_Logger2.default.error(_context3.t0, 'Unable to merge pull request'); | ||
return _context3.abrupt('return', false); | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() { | ||
var endpoint, data, resp; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}/merge`; | ||
data = { | ||
close_source_branch: true, | ||
message: 'Merged by Landkid after successful build rebased on Master', | ||
merge_strategy: 'merge_commit' | ||
}; | ||
case 14: | ||
return _context3.abrupt('return', true); | ||
_Logger2.default.info({ pullRequestId, endpoint }, 'Merging pull request'); | ||
_context3.prev = 3; | ||
_context3.next = 6; | ||
return _axios2.default.post(endpoint, (0, _stringify2.default)(data), axiosPostConfig); | ||
case 15: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, _this3, [[3, 10]]); | ||
}))(); | ||
}, | ||
case 6: | ||
resp = _context3.sent; | ||
getPullRequest(pullRequestId) { | ||
_this4 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() { | ||
var endpoint, resp; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}`; | ||
_context4.next = 3; | ||
return _axios2.default.get(endpoint, axiosGetConfig); | ||
_Logger2.default.info({ pullRequestId }, 'Merged Pull Request'); | ||
_context3.next = 14; | ||
break; | ||
case 3: | ||
resp = _context4.sent; | ||
return _context4.abrupt('return', resp.data); | ||
case 10: | ||
_context3.prev = 10; | ||
_context3.t0 = _context3['catch'](3); | ||
case 5: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, _this4); | ||
}))(); | ||
}, | ||
_Logger2.default.error(_context3.t0, 'Unable to merge pull request'); | ||
return _context3.abrupt('return', false); | ||
getPullRequestBuildStatuses(pullRequestId) { | ||
_this5 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() { | ||
var endpoint, resp, allBuildStatuses; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}/statuses`; | ||
_context5.next = 3; | ||
return _axios2.default.get(endpoint, axiosGetConfig); | ||
case 14: | ||
return _context3.abrupt('return', true); | ||
case 3: | ||
resp = _context5.sent; | ||
case 15: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, _this3, [[3, 10]]); | ||
}))(); | ||
}, | ||
// fairly safe to assume we'll never need to paginate these results | ||
allBuildStatuses = resp.data.values; | ||
// need to remove build statuses that we created or rerunning would be impossible | ||
getPullRequest(pullRequestId) { | ||
var _this4 = this; | ||
return _context5.abrupt('return', allBuildStatuses.filter(function (buildStatus) { | ||
return !buildStatus.name.match(/Pipeline #.+? for landkid/); | ||
})); | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() { | ||
var endpoint, resp; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}`; | ||
_context4.next = 3; | ||
return _axios2.default.get(endpoint, axiosGetConfig); | ||
case 6: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, _this5); | ||
}))(); | ||
} | ||
}); | ||
case 3: | ||
resp = _context4.sent; | ||
return _context4.abrupt('return', resp.data); | ||
case 6: | ||
case 'end': | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, undefined); | ||
})); | ||
case 5: | ||
case 'end': | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4, _this4); | ||
}))(); | ||
}, | ||
return function BitbucketAdapter(_x) { | ||
return _ref.apply(this, arguments); | ||
getPullRequestBuildStatuses(pullRequestId) { | ||
var _this5 = this; | ||
return (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() { | ||
var endpoint, resp, allBuildStatuses; | ||
return _regenerator2.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
endpoint = `${apiBaseUrl}/pullrequests/${pullRequestId}/statuses`; | ||
_context5.next = 3; | ||
return _axios2.default.get(endpoint, axiosGetConfig); | ||
case 3: | ||
resp = _context5.sent; | ||
// fairly safe to assume we'll never need to paginate these results | ||
allBuildStatuses = resp.data.values; | ||
// need to remove build statuses that we created or rerunning would be impossible | ||
return _context5.abrupt('return', allBuildStatuses.filter(function (buildStatus) { | ||
return !buildStatus.name.match(/Pipeline #.+? for landkid/); | ||
})); | ||
case 6: | ||
case 'end': | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, _this5); | ||
}))(); | ||
} | ||
}; | ||
}(); | ||
}; | ||
exports.default = BitbucketAdapter; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = atlaskid; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _express = require('express'); | ||
@@ -63,61 +52,21 @@ | ||
exports.default = function () { | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) { | ||
var server, port, host, ci, persona, client, queue, runner; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
server = (0, _express2.default)(); | ||
port = config.port || 8000; | ||
function atlaskid(config) { | ||
var server = (0, _express2.default)(); | ||
var port = config.port || 8000; | ||
server.use(_bodyParser2.default.json()); | ||
server.set('baseUrl', config.baseUrl); | ||
server.set('usersAllowedToMerge', config.hostConfig.usersAllowedToApprove || []); | ||
server.use(_bodyParser2.default.json()); | ||
server.set('baseUrl', config.baseUrl); | ||
server.set('usersAllowedToMerge', config.hostConfig.usersAllowedToApprove || []); | ||
var host = _hosts2.default[config.host](config.hostConfig); | ||
var ci = _ci2.default[config.ci](config.ciConfig); | ||
var persona = _personas2.default[config.persona || 'goat']; | ||
var client = new _Client2.default(host, ci, persona); | ||
_context.next = 7; | ||
return _hosts2.default[config.host](config.hostConfig); | ||
var queue = new _Queue2.default(); | ||
var runner = new _Runner2.default(queue, client); | ||
case 7: | ||
host = _context.sent; | ||
_context.next = 10; | ||
return _ci2.default[config.ci](config.ciConfig); | ||
(0, _routes2.default)(server, client, runner); | ||
case 10: | ||
ci = _context.sent; | ||
persona = _personas2.default[config.persona || 'goat']; | ||
client = new _Client2.default(host, ci, persona); | ||
queue = new _Queue2.default(); | ||
runner = new _Runner2.default(queue, client); | ||
(0, _routes2.default)(server, client, runner); | ||
return _context.abrupt('return', new _promise2.default(function (resolve, reject) { | ||
server.on('error', function (err) { | ||
reject(err); | ||
}); | ||
server.listen(port, function () { | ||
_Logger2.default.info(`Landkid server started at http://localhost:${port}`); | ||
_Logger2.default.info(`BaseUrl set to ${config.baseUrl}`); | ||
resolve(); | ||
}); | ||
})); | ||
case 17: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function atlaskid(_x) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return atlaskid; | ||
}(); | ||
return server; | ||
} |
@@ -88,3 +88,2 @@ 'use strict'; | ||
_Logger2.default.info(state, 'Requesting current state'); | ||
res.header('Access-Control-Allow-Origin', '*').json((0, _extends3.default)({}, state, { usersAllowedToMerge })); | ||
@@ -146,3 +145,2 @@ | ||
title = req.query.title; | ||
// obviously we need more checks than this later | ||
@@ -171,3 +169,2 @@ | ||
res.header('Access-Control-Allow-Origin', '*').status(200).json({ positionInQueue }); | ||
runner.next(); | ||
@@ -174,0 +171,0 @@ |
@@ -130,2 +130,3 @@ 'use strict'; | ||
Runner.prototype.mergePassedBuildIfRunning = function mergePassedBuildIfRunning(statusEvent) { | ||
_Logger2.default.info({ statusEvent, running: this.running }, 'Status event May be relevant!'); | ||
if (!this.running) { | ||
@@ -135,3 +136,2 @@ _Logger2.default.info(statusEvent, 'No build running, status event is irrelevant'); | ||
} | ||
_Logger2.default.info({ statusEvent, running: this.running }, 'Status event May be relevant!'); | ||
if (statusEvent.buildId === this.running.buildId) { | ||
@@ -138,0 +138,0 @@ if (statusEvent.passed) { |
@@ -21,7 +21,7 @@ 'use strict'; | ||
var _types = require('../types'); | ||
require('../types'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const BitbucketPipelinesAdapter = async config => { | ||
const BitbucketPipelinesAdapter = config => { | ||
let axiosGetConfig = { | ||
@@ -28,0 +28,0 @@ auth: { |
@@ -25,3 +25,3 @@ 'use strict'; | ||
const BitbucketAdapter = async config => { | ||
const BitbucketAdapter = config => { | ||
const USERS_ALLOWED_TO_APPROVE = config.usersAllowedToApprove; | ||
@@ -64,3 +64,3 @@ const axiosGetConfig = { | ||
const createdBy = pullRequest.author.username; | ||
const isApproved = pullRequest.participants.some(participant => participant.approved && !participant.user.username !== createdBy && USERS_ALLOWED_TO_APPROVE.indexOf(participant.user.username) > -1 || participant.approved && !participant.user.username === 'luke_batchelor'); | ||
const isApproved = pullRequest.participants.some(participant => participant.approved && !participant.user.username !== createdBy && USERS_ALLOWED_TO_APPROVE.indexOf(participant.user.username) > -1); | ||
const isGreen = buildStatuses.every(buildStatus => buildStatus.state === 'SUCCESSFUL'); | ||
@@ -67,0 +67,0 @@ _Logger2.default.info({ pullRequestId, isOpen, isApproved, isGreen }, 'isAllowedToLand()'); |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = atlaskid; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _express = require('express'); | ||
@@ -55,3 +52,3 @@ | ||
exports.default = async function atlaskid(config) { | ||
function atlaskid(config) { | ||
let server = (0, _express2.default)(); | ||
@@ -64,4 +61,4 @@ let port = config.port || 8000; | ||
const host = await _hosts2.default[config.host](config.hostConfig); | ||
const ci = await _ci2.default[config.ci](config.ciConfig); | ||
const host = _hosts2.default[config.host](config.hostConfig); | ||
const ci = _ci2.default[config.ci](config.ciConfig); | ||
const persona = _personas2.default[config.persona || 'goat']; | ||
@@ -75,14 +72,3 @@ let client = new _Client2.default(host, ci, persona); | ||
return new _promise2.default((resolve, reject) => { | ||
server.on('error', err => { | ||
reject(err); | ||
}); | ||
server.listen(port, () => { | ||
_Logger2.default.info(`Landkid server started at http://localhost:${port}`); | ||
_Logger2.default.info(`BaseUrl set to ${config.baseUrl}`); | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
return server; | ||
} |
@@ -71,3 +71,2 @@ 'use strict'; | ||
_Logger2.default.info(state, 'Requesting current state'); | ||
res.header('Access-Control-Allow-Origin', '*').json((0, _extends3.default)({}, state, { usersAllowedToMerge })); | ||
@@ -88,3 +87,2 @@ })); | ||
const title = req.query.title; | ||
// obviously we need more checks than this later | ||
@@ -107,3 +105,2 @@ if (!pullRequestId || !userUuid || !commit || !title) { | ||
res.header('Access-Control-Allow-Origin', '*').status(200).json({ positionInQueue }); | ||
runner.next(); | ||
@@ -110,0 +107,0 @@ })); |
@@ -47,2 +47,3 @@ 'use strict'; | ||
let isAllowedToLand = await this.client.isAllowedToLand(landRequest.pullRequestId); | ||
if (isAllowedToLand.isAllowed) { | ||
@@ -62,2 +63,3 @@ _Logger2.default.info({ landRequest }, 'Allowed to land, creating land build'); | ||
mergePassedBuildIfRunning(statusEvent) { | ||
_Logger2.default.info({ statusEvent, running: this.running }, 'Status event May be relevant!'); | ||
if (!this.running) { | ||
@@ -67,3 +69,2 @@ _Logger2.default.info(statusEvent, 'No build running, status event is irrelevant'); | ||
} | ||
_Logger2.default.info({ statusEvent, running: this.running }, 'Status event May be relevant!'); | ||
if (statusEvent.buildId === this.running.buildId) { | ||
@@ -70,0 +71,0 @@ if (statusEvent.passed) { |
{ | ||
"name": "landkid", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "CI Queue", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"flow": "flow status", | ||
"test": "jest --coverage", | ||
"test": "ava", | ||
"format": "prettier --write src/**/*.js", | ||
@@ -33,4 +33,6 @@ "build:legacy": "BABEL_ENV=legacy babel src -d dist/legacy -D", | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-register": "^6.26.0", | ||
"flow-bin": "^0.59.0", | ||
@@ -40,3 +42,6 @@ "husky": "^0.14.3", | ||
"lint-staged": "^5.0.0", | ||
"prettier": "^1.8.2" | ||
"nock": "^9.1.6", | ||
"prettier": "^1.8.2", | ||
"sinon": "^4.2.2", | ||
"supertest": "^3.0.0" | ||
}, | ||
@@ -77,3 +82,8 @@ "dependencies": { | ||
"singleQuote": true | ||
}, | ||
"ava": { | ||
"require": [ | ||
"babel-register" | ||
] | ||
} | ||
} |
@@ -27,4 +27,9 @@ #!/usr/bin/env node | ||
landkid(landkidConfig).catch(err => { | ||
console.log(err); | ||
let server = landkid(landkidConfig); | ||
server.listen(landkidConfig.port, () => { | ||
console.log( | ||
`Landkid server started at http://localhost:${landkidConfig.port}` | ||
); | ||
console.log(`BaseUrl set to ${landkidConfig.baseUrl}`); | ||
}); |
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
55
100219
12
2300
10