@fountainhead/branch-officer
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -50,4 +50,9 @@ "use strict"; | ||
default: false | ||
}, | ||
requiredStatusChecks: { | ||
describe: 'An optional list of Status Check names that must a Pull Request must pass in order for a Release to ' | ||
+ 'be created or updated. If omitted, a Pull Request must pass all applicable Status Checks.' | ||
} | ||
}) | ||
.array('requiredStatusChecks') | ||
.argv; | ||
@@ -57,3 +62,4 @@ const gitHub = { | ||
repo: args.repo, | ||
owner: args.owner | ||
owner: args.owner, | ||
requiredStatusChecks: args.requiredStatusChecks | ||
}; | ||
@@ -60,0 +66,0 @@ const helmfile = { |
@@ -28,3 +28,10 @@ "use strict"; | ||
]))); | ||
exports.getBuildSucceeded = ramda_1.pipe(ramda_1.prop('data'), ramda_1.head, ramda_1.defaultTo({}), ramda_1.propEq('state', 'success')); | ||
exports.getBuildSucceeded = (requiredStatusChecks) => ramda_1.pipe(ramda_1.path(['data', 'statuses']), requiredStatusChecks ? | ||
ramda_1.allPass(requiredStatusChecks.map(name => ramda_1.any(ramda_1.whereEq({ | ||
context: name, | ||
state: 'success' | ||
})))) : | ||
ramda_1.all(ramda_1.whereEq({ | ||
state: 'success' | ||
}))); | ||
exports.fetchAll = ({ client, owner, repo }) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -53,3 +60,3 @@ console.log(`Fetching all PRs for '${owner}/${repo}'`); | ||
}); | ||
exports.withBuildStatuses = ({ client, owner, repo, pullRequests }) => __awaiter(this, void 0, void 0, function* () { | ||
exports.withBuildStatuses = ({ client, owner, repo, pullRequests, statusChecker }) => __awaiter(this, void 0, void 0, function* () { | ||
console.log('Fetching build status for open PRs'); | ||
@@ -59,5 +66,4 @@ const bar = new cli_progress_1.Bar({}); | ||
const buildStatuses = yield Promise.all(pullRequests.map((pr) => __awaiter(this, void 0, void 0, function* () { | ||
const response = yield client.repos.getStatuses({ | ||
const response = yield client.repos.getCombinedStatusForRef({ | ||
ref: pr.sha, | ||
per_page: 1, | ||
owner, | ||
@@ -68,3 +74,3 @@ repo | ||
return ramda_1.merge(pr, { | ||
buildSucceeded: exports.getBuildSucceeded(response) | ||
buildSucceeded: statusChecker(response) | ||
}); | ||
@@ -75,7 +81,13 @@ }))); | ||
}); | ||
exports.fetch = ({ token, owner, repo }) => __awaiter(this, void 0, void 0, function* () { | ||
exports.fetch = ({ token, owner, repo, requiredStatusChecks }) => __awaiter(this, void 0, void 0, function* () { | ||
const client = new rest_1.default(); | ||
client.authenticate({ type: 'token', token }); | ||
const pullRequests = yield exports.fetchAll({ client, owner, repo }); | ||
return exports.withBuildStatuses({ client, owner, repo, pullRequests }); | ||
return exports.withBuildStatuses({ | ||
statusChecker: exports.getBuildSucceeded(requiredStatusChecks), | ||
client, | ||
owner, | ||
repo, | ||
pullRequests | ||
}); | ||
}); |
{ | ||
"name": "@fountainhead/branch-officer", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Automates the deployment of GitHub Pull Requests as Preview Environments using Helm and Helmfile", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
24222
544