@twexchangesolutions/hubot-jira-deployment
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -12,3 +12,3 @@ "use strict"; | ||
function getDeployScriptRegex() { | ||
return (/(deploy|check) (([A-Z]+)-\d+)/i | ||
return (/\s*(deploy|check)\s+(([A-Z]+)-\d+)/i | ||
); | ||
@@ -15,0 +15,0 @@ } |
@@ -55,3 +55,3 @@ 'use strict'; | ||
return { | ||
errors: errorList, | ||
errorList: errorList, | ||
result: errorList.length === 0 | ||
@@ -72,3 +72,3 @@ }; | ||
if (!crossReferenceResult.result) { | ||
(0, _errorAccumulator.accumulateAndThrow)(crossReferenceResult.errors); | ||
(0, _errorAccumulator.accumulateAndThrow)(crossReferenceResult.errorList); | ||
} | ||
@@ -75,0 +75,0 @@ |
@@ -125,3 +125,3 @@ // Description: | ||
robot.logger.debug('Beginning network queries for git commits'); | ||
return (0, _toolTeamcityRequests.getDeploymentCommitLists)(parsedDeployments, teamcityAPI, githubAPI, res); | ||
return (0, _toolTeamcityRequests.getDeploymentCommitLists)(parsedDeployments, teamcityAPI, githubAPI, res, robot); | ||
}).then(function (commitListsResult) { | ||
@@ -144,4 +144,4 @@ robot.logger.debug('Network queries for git commits complete'); | ||
robot.logger.debug('Catch block hit, there was an error.'); | ||
robot.logger.error(err); | ||
res.send((0, _errorConversionJs2['default'])(err)); | ||
robot.logger.error((0, _errorConversionJs2['default'])(err, true)); | ||
res.send((0, _errorConversionJs2['default'])(err, false)); | ||
res.send(operationType + ' aborted.'); | ||
@@ -148,0 +148,0 @@ robot.logger.debug('Logging after the res.send() call to prove this gets hit.'); |
@@ -46,2 +46,24 @@ 'use strict'; | ||
function findIssueLinkParentKey(issue) { | ||
var result = null; | ||
issue.fields.issuelinks.forEach(function (issueLink) { | ||
if (issueLink.type.name !== 'Relates') { | ||
return; | ||
} | ||
var linkDirection = null; | ||
if (issueLink.inwardIssue) { | ||
linkDirection = 'inwardIssue'; | ||
} else if (issueLink.outwardIssue) { | ||
linkDirection = 'outwardIssue'; | ||
} | ||
if (linkDirection && issueLink[linkDirection].fields.issuetype.name === 'Initiative') { | ||
result = issueLink[linkDirection].key; | ||
} | ||
}); | ||
return result; | ||
} | ||
var OurJiraApi = (function () { | ||
@@ -127,5 +149,35 @@ function OurJiraApi(env) { | ||
}, { | ||
key: 'findParent', | ||
value: function findParent(issue) { | ||
var _this5 = this; | ||
switch (issue.fields.issuetype.name) { | ||
case 'Sub-task': | ||
return this.findIssue(issue.fields.parent.key); | ||
case 'Story': | ||
if (issue.fields.issuelinks) { | ||
var _parentKey = findIssueLinkParentKey(issue); | ||
if (_parentKey) { | ||
return this.findIssue(_parentKey); | ||
} | ||
} | ||
return this.getJiraFieldByName('Epic Link').then(function (linkField) { | ||
return _this5.findIssue(issue.fields[linkField]); | ||
}); | ||
case 'Epic': | ||
var parentKey = findIssueLinkParentKey(issue); | ||
return parentKey ? this.findIssue(parentKey) : _Promise.reject('Cannot find parent from Epic ' + issue.key); | ||
default: | ||
return _Promise.reject(issue.fields.issuetype.name + ' should not have a parent.'); | ||
} | ||
} | ||
}, { | ||
key: 'findDeploymentTask', | ||
value: function findDeploymentTask(issueNumber) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -147,15 +199,15 @@ return this.searchJira('id=' + issueNumber, []).then(function (jqlResponse) { | ||
return _this5.queryForAllIssues(linkedIssueKeys).then(function (linkedIssueArray) { | ||
var self = _this5; | ||
return _this6.queryForAllIssues(linkedIssueKeys).then(function (linkedIssueArray) { | ||
var self = _this6; | ||
return _extends({}, deploymentTask, { | ||
'linkedIssueObjects': linkedIssueArray, | ||
findField: function findField(fieldName) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
return self.getJiraFieldByName(fieldName).then(function (resultField) { | ||
if (!_this6.fields[resultField]) { | ||
throw new Error('Issue ' + _this6.key + ' does not contain a field with name \'' + fieldName + '\''); | ||
if (!_this7.fields[resultField]) { | ||
throw new Error('Issue ' + _this7.key + ' does not contain a field with name \'' + fieldName + '\''); | ||
} | ||
return _this6.fields[resultField]; | ||
return _this7.fields[resultField]; | ||
}); | ||
@@ -162,0 +214,0 @@ } |
@@ -48,16 +48,14 @@ 'use strict'; | ||
return []; | ||
} else if (commitToParse.commit.message.indexOf('This reverts commit ') > -1) { | ||
return []; | ||
} else { | ||
var returnList = parseAllIssuesFromString(commitToParse.commit.message, projectKey); | ||
if (returnList.length === 0) { | ||
if (commitToParse.__gitRepo) { | ||
throw new Error('commit from ' + commitToParse.__gitRepo + ' with sha: ' + commitToParse.sha + ' did not have a jira issue referenced.'); | ||
} else { | ||
throw new Error('commit with commit sha: ' + commitToParse.sha + ' did not have a jira issue referenced.'); | ||
} | ||
} | ||
var returnList = parseAllIssuesFromString(commitToParse.commit.message, projectKey); | ||
if (returnList.length === 0) { | ||
if (commitToParse.__gitRepo) { | ||
throw new Error('commit from ' + commitToParse.__gitRepo + ' with sha: ' + commitToParse.sha + ' did not have a jira issue referenced.'); | ||
} else { | ||
throw new Error('commit with commit sha: ' + commitToParse.sha + ' did not have a jira issue referenced.'); | ||
} | ||
} | ||
return returnList; | ||
} | ||
return returnList; | ||
} | ||
@@ -64,0 +62,0 @@ |
@@ -30,2 +30,6 @@ 'use strict'; | ||
var _errorConversion = require('./error-conversion'); | ||
var _errorConversion2 = _interopRequireDefault(_errorConversion); | ||
function findTheGitURLFromPropertyList(propertyList) { | ||
@@ -78,3 +82,3 @@ return new _Promise(function (resolve, reject) { | ||
function compareBuilds(buildId1, buildId2, theTeamCityAPI, theGitHubAPI) { | ||
function compareBuilds(buildId1, buildId2, theTeamCityAPI, theGitHubAPI, hubotRobot) { | ||
var gitRepo = undefined; | ||
@@ -99,6 +103,15 @@ return _Promise.all([getShaFromBuildId(buildId1, theTeamCityAPI), getShaFromBuildId(buildId2, theTeamCityAPI), getRepoAndOwnerFromBuildId(buildId1, theTeamCityAPI)]).then(function (shaResult) { | ||
} | ||
})['catch'](function (err) { | ||
if (err.message.indexOf('Not Found') > -1) { | ||
if (hubotRobot) { | ||
hubotRobot.logger.error((0, _errorConversion2['default'])(err, false)); | ||
} | ||
throw new Error('The Git Repository ' + gitRepo + ' is not linked properly in Teamcity. Check to make sure the repository exists, and that the URL specified in the Teamcity CI Build is not a redirected URL.'); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
} | ||
function recursiveCompare(response, indexToCheck, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild) { | ||
function recursiveCompare(response, indexToCheck, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild, hubotRobot) { | ||
@@ -109,3 +122,3 @@ if (indexToCheck >= response.build.length) { | ||
return compareBuilds(buildIdOfStartingBuild, response.build[indexToCheck].id, theTeamCityAPI, theGitHubAPI)['catch'](function (err) { | ||
return compareBuilds(buildIdOfStartingBuild, response.build[indexToCheck].id, theTeamCityAPI, theGitHubAPI, hubotRobot)['catch'](function (err) { | ||
if (err.message === 'Not a valid range of commits. Check for divergent commits.') { | ||
@@ -119,3 +132,3 @@ return recursiveCompare(response, indexToCheck + 1, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild); | ||
function getProductionGitCommitsFromBuildTypeId(buildTypeID, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild) { | ||
function getProductionGitCommitsFromBuildTypeId(buildTypeID, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild, hubotRobot) { | ||
var indexToCheck = 0; | ||
@@ -127,15 +140,15 @@ | ||
} | ||
return recursiveCompare(response, indexToCheck, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild); | ||
return recursiveCompare(response, indexToCheck, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild, hubotRobot); | ||
}); | ||
} | ||
function getCommitsFromTeamCityBuildId(buildId, teamCityAPI, githubAPI) { | ||
function getCommitsFromTeamCityBuildId(buildId, teamCityAPI, githubAPI, hubotRobot) { | ||
return teamCityAPI.fetchInfoFromBuildID(buildId).then(function (buildInfo) { | ||
return getProductionGitCommitsFromBuildTypeId(buildInfo.buildTypeId, teamCityAPI, githubAPI, buildInfo.id); | ||
return getProductionGitCommitsFromBuildTypeId(buildInfo.buildTypeId, teamCityAPI, githubAPI, buildInfo.id, hubotRobot); | ||
}); | ||
} | ||
function scanDeployment(commitsFromTeamCityFunction, deployment, teamCityAPI, githubAPI, hubotResponse) { | ||
function scanDeployment(commitsFromTeamCityFunction, deployment, teamCityAPI, githubAPI, hubotResponse, hubotRobot) { | ||
hubotResponse.send('Beginning scan of Deployment: \'' + deployment.name + '\''); | ||
return commitsFromTeamCityFunction(deployment.buildId, teamCityAPI, githubAPI).then(function (commitResponse) { | ||
return commitsFromTeamCityFunction(deployment.buildId, teamCityAPI, githubAPI, hubotRobot).then(function (commitResponse) { | ||
return { | ||
@@ -154,8 +167,8 @@ deploymentName: deployment.name, | ||
//Use the error aggregator when that branch gets brought in rather than reducing the errorList here. | ||
//Use the error aggregator when that branch gets brought in rather than reducing the errors here. | ||
//Don't know why I didn't think to make that its own pull request. | ||
function getCommitLists(commitsFromTeamCityFunction, scanDeploymentFunction, productionBuildList, teamCityAPI, githubAPI, hubotResponse) { | ||
function getCommitLists(commitsFromTeamCityFunction, scanDeploymentFunction, productionBuildList, teamCityAPI, githubAPI, hubotResponse, hubotRobot) { | ||
return _Promise.all(productionBuildList.deployments.map(function (x) { | ||
return scanDeploymentFunction(commitsFromTeamCityFunction, x, teamCityAPI, githubAPI, hubotResponse); | ||
return scanDeploymentFunction(commitsFromTeamCityFunction, x, teamCityAPI, githubAPI, hubotResponse, hubotRobot); | ||
})).then(function (resultList) { | ||
@@ -185,4 +198,4 @@ var accumulatedSuccesses = resultList.filter(function (x) { | ||
function getDeploymentCommitLists(productionBuildList, teamCityAPI, githubAPI, hubotResponse) { | ||
return getCommitLists(getCommitsFromTeamCityBuildId, scanDeployment, productionBuildList, teamCityAPI, githubAPI, hubotResponse); | ||
function getDeploymentCommitLists(productionBuildList, teamCityAPI, githubAPI, hubotResponse, hubotRobot) { | ||
return getCommitLists(getCommitsFromTeamCityBuildId, scanDeployment, productionBuildList, teamCityAPI, githubAPI, hubotResponse, hubotRobot); | ||
} |
{ | ||
"name": "@twexchangesolutions/hubot-jira-deployment", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Hook used to ensure that all issues being deployed to production meet audit requirements", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
52175
20
1092