@twexchangesolutions/hubot-jira-deployment
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -54,2 +54,4 @@ // Description: | ||
// - If Empty or unspecified, defaults to no authentication | ||
// HUBOT_TEAMCITY_DEPENDENCY_BLACKLIST: | ||
// - A comma separated string containing buildTypeIds of artifact dependencies we need to ignore. (For example, Deployment Configs) | ||
// | ||
@@ -56,0 +58,0 @@ // Commands: |
'use strict'; | ||
var _extends = require('babel-runtime/helpers/extends')['default']; | ||
var _toConsumableArray = require('babel-runtime/helpers/to-consumable-array')['default']; | ||
@@ -116,6 +118,12 @@ | ||
var buildIdParse = ciUrl.match(/.*?buildId=([0-9]+).*/i); | ||
var buildTypeIdParse = deploymentUrl.match(/.*?buildTypeId=(.+).*/i); | ||
var returnObject = { | ||
deployment: null, | ||
error: null | ||
}; | ||
if (buildIdParse) { | ||
var buildId = buildIdParse[1]; | ||
return { | ||
returnObject = { | ||
deployment: { unused: unused, name: _name, deploymentUrl: deploymentUrl, ciNumber: ciNumber, ciUrl: ciUrl, buildId: buildId }, | ||
@@ -125,3 +133,3 @@ error: null | ||
} else { | ||
return { | ||
returnObject = { | ||
deployment: null, | ||
@@ -131,2 +139,14 @@ error: 'The ciUrl \'' + ciUrl + '\' does not have a buildId in its query.' | ||
} | ||
if (buildTypeIdParse) { | ||
var buildTypeId = buildTypeIdParse[1]; | ||
returnObject.deployment = _extends({}, returnObject.deployment, { | ||
buildTypeId: buildTypeId | ||
}); | ||
} else { | ||
var errorMessage = 'The deployment url does not contain a buildTypeId.'; | ||
returnObject.error = returnObject.error ? returnObject.error + '\n' + errorMessage : errorMessage; | ||
} | ||
return returnObject; | ||
} else { | ||
@@ -133,0 +153,0 @@ return { |
@@ -73,2 +73,3 @@ 'use strict'; | ||
this.restApiUrl = this.baseUrl + '/app/rest'; | ||
this.dependencyIgnoreList = env.HUBOT_TEAMCITY_DEPENDENCY_BLACKLIST ? env.HUBOT_TEAMCITY_DEPENDENCY_BLACKLIST.split(',') : []; | ||
this.requestOptions = { | ||
@@ -100,2 +101,12 @@ method: 'GET', | ||
}, { | ||
key: 'fetchBuildsFromBuildType', | ||
value: function fetchBuildsFromBuildType(buildTypeID) { | ||
return this.makeRequest(this.restApiUrl + '/buildTypes/' + buildTypeID + '/builds'); | ||
} | ||
}, { | ||
key: 'fetchSuccessfulBuildsFromBuildType', | ||
value: function fetchSuccessfulBuildsFromBuildType(buildTypeID) { | ||
return this.makeRequest(this.restApiUrl + '/buildTypes/' + buildTypeID + '/builds?status=SUCCESS'); | ||
} | ||
}, { | ||
key: 'fetchBuildsWithTagFromBuildType', | ||
@@ -111,2 +122,15 @@ value: function fetchBuildsWithTagFromBuildType(buildTypeID, tag) { | ||
}, { | ||
key: 'fetchArtifactDependenciesFromBuildType', | ||
value: function fetchArtifactDependenciesFromBuildType(buildTypeID) { | ||
var _this = this; | ||
return this.fetchInfoFromBuildType(buildTypeID).then(function (result) { | ||
return result['artifact-dependencies']['artifact-dependency'].map(function (x) { | ||
return x['source-buildType'].id; | ||
}).filter(function (x) { | ||
return _this.dependencyIgnoreList.indexOf(x) === -1; | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'fetchInfoFromBuildID', | ||
@@ -139,3 +163,3 @@ value: function fetchInfoFromBuildID(buildID) { | ||
value: function fetchBuildByBuildNumber(buildTypeID, buildNumber) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -148,3 +172,3 @@ return this.makeRequest(this.restApiUrl + '/builds/?locator=buildType:' + buildTypeID).then(function (response) { | ||
if (build) { | ||
return _this.fetchInfoFromBuildID(build.id); | ||
return _this2.fetchInfoFromBuildID(build.id); | ||
} else { | ||
@@ -163,6 +187,6 @@ throw new Error('Build with build number ' + buildNumber + ' not found in build type: ' + buildTypeID); | ||
value: function runBuild(buildTypeID) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return this.triggerBuildFromBuildConfigurationID(buildTypeID).then(function () { | ||
return _this2.fetchLastBuild(buildTypeID); | ||
return _this3.fetchLastBuild(buildTypeID); | ||
}).then(function (lastBuild) { | ||
@@ -173,3 +197,3 @@ var previousBuildNumber = lastBuild.build[0].number; | ||
}).then(function (buildNumber) { | ||
return pollForLastBuildByBuildNumber(_this2, buildTypeID, buildNumber); | ||
return pollForLastBuildByBuildNumber(_this3, buildTypeID, buildNumber); | ||
}); | ||
@@ -176,0 +200,0 @@ } |
@@ -15,3 +15,4 @@ 'use strict'; | ||
exports.parseGitURLForUserAndRepo = parseGitURLForUserAndRepo; | ||
exports.getShaFromBuildId = getShaFromBuildId; | ||
exports.getShaFromCIBuildId = getShaFromCIBuildId; | ||
exports.getShaFromDeploymentBuildId = getShaFromDeploymentBuildId; | ||
exports.getProductionGitCommitsFromBuildTypeId = getProductionGitCommitsFromBuildTypeId; | ||
@@ -74,7 +75,16 @@ exports.getCommitsFromTeamCityBuildId = getCommitsFromTeamCityBuildId; | ||
function getShaFromBuildId(buildId, theTeamCityAPI) { | ||
return theTeamCityAPI.fetchInfoFromBuildID(buildId).then(function (_ref3) { | ||
var revisions = _ref3.revisions; | ||
function getShaFromCIBuildId(buildId, theTeamCityAPI) { | ||
return theTeamCityAPI.fetchInfoFromBuildID(buildId).then(function (buildResponse) { | ||
return _Promise.resolve(buildResponse.revisions.revision[0].version); | ||
}); | ||
} | ||
return _Promise.resolve(revisions.revision[0].version); | ||
//The SHA is in a property called version on 'list' of revisions on the build. | ||
//I've never seen a list of revisions with a length of more than one. | ||
function getShaFromDeploymentBuildId(buildId, theTeamCityAPI) { | ||
return theTeamCityAPI.fetchInfoFromBuildID(buildId).then(function (deployBuildResponse) { | ||
return theTeamCityAPI.fetchInfoFromBuildID(deployBuildResponse['artifact-dependencies'].build[0].id); | ||
}).then(function (buildResponse) { | ||
return _Promise.resolve(buildResponse.revisions.revision[0].version); | ||
}); | ||
@@ -85,3 +95,3 @@ } | ||
var gitRepo = undefined; | ||
return _Promise.all([getShaFromBuildId(buildId1, theTeamCityAPI), getShaFromBuildId(buildId2, theTeamCityAPI), getRepoAndOwnerFromBuildId(buildId1, theTeamCityAPI)]).then(function (shaResult) { | ||
return _Promise.all([getShaFromCIBuildId(buildId1, theTeamCityAPI), getShaFromDeploymentBuildId(buildId2, theTeamCityAPI), getRepoAndOwnerFromBuildId(buildId1, theTeamCityAPI)]).then(function (shaResult) { | ||
gitRepo = shaResult[2].repo; | ||
@@ -117,3 +127,2 @@ return (0, _githubFunctions.compareCommits)(theGitHubAPI, { | ||
function recursiveCompare(response, indexToCheck, theTeamCityAPI, theGitHubAPI, buildIdOfStartingBuild, hubotRobot) { | ||
if (indexToCheck >= response.build.length) { | ||
@@ -135,3 +144,3 @@ throw new Error('No valid range of commits exist for buildTypeId: ' + response.build[0].buildTypeId + ', check to make sure production commits have not diverged.'); | ||
return theTeamCityAPI.fetchBuildsWithTagFromBuildType(buildTypeID, 'Production').then(function (response) { | ||
return theTeamCityAPI.fetchSuccessfulBuildsFromBuildType(buildTypeID).then(function (response) { | ||
if (response.build.length < 1) { | ||
@@ -144,5 +153,13 @@ return _Promise.reject(new Error('The List of production builds was empty. Cannot find a range between buildId ' + buildIdOfStartingBuild + ' and a build that does not exist.')); | ||
function getCommitsFromTeamCityBuildId(buildId, teamCityAPI, githubAPI, hubotRobot) { | ||
function getCommitsFromTeamCityBuildId(buildId, teamCityAPI, githubAPI, hubotRobot, deployment) { | ||
return teamCityAPI.fetchInfoFromBuildID(buildId).then(function (buildInfo) { | ||
return getProductionGitCommitsFromBuildTypeId(buildInfo.buildTypeId, teamCityAPI, githubAPI, buildInfo.id, hubotRobot); | ||
return teamCityAPI.fetchArtifactDependenciesFromBuildType(deployment.buildTypeId).then(function (artifactDependencies) { | ||
if (artifactDependencies.indexOf(buildInfo.buildTypeId) === -1) { | ||
throw new Error('Deployment ' + deployment.name + ' has a mismatched Deployment build type and CI build type on the Deployment Task. Ensure the deployment has the CI listed as an artifact dependency in TeamCity.'); | ||
} | ||
return buildInfo; | ||
}); | ||
}).then(function (validatedBuildInfo) { | ||
return getProductionGitCommitsFromBuildTypeId(deployment.buildTypeId, teamCityAPI, githubAPI, validatedBuildInfo.id, hubotRobot); | ||
}); | ||
@@ -152,3 +169,3 @@ } | ||
function scanDeployment(commitsFromTeamCityFunction, deployment, teamCityAPI, githubAPI, hubotResponse, hubotRobot) { | ||
return commitsFromTeamCityFunction(deployment.buildId, teamCityAPI, githubAPI, hubotRobot).then(function (commitResponse) { | ||
return commitsFromTeamCityFunction(deployment.buildId, teamCityAPI, githubAPI, hubotRobot, deployment).then(function (commitResponse) { | ||
return { | ||
@@ -155,0 +172,0 @@ deploymentName: deployment.name, |
{ | ||
"name": "@twexchangesolutions/hubot-jira-deployment", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"description": "Hook used to ensure that all issues being deployed to production meet audit requirements", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
61735
1268