Skip to content

Commit

Permalink
Merge pull request #102 from zotoio/feature/blacklist-repos
Browse files Browse the repository at this point in the history
Feature/blacklist repos
  • Loading branch information
wyvern8 authored Apr 18, 2018
2 parents e955350 + 8ca5648 commit 35132f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .envExample
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ GTM_DYNAMO_TABLE_EVENTS=GtmEvents
GTM_AWS_VPC_ID=<redacted>
GTM_BASE_URL=http://localhost:9091
GTM_S3_DEPENDENCY_BUCKET=gtmstorage
GTM_WELCOME_MESSAGE_ENABLED=true
GTM_WELCOME_MESSAGE_ENABLED=true
GTM_REPO_BLACKLIST=.*ignore-repo.*,.*another-repo.*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Create an asynchronous CI agnostic mechanism for running custom test stage gates
|GTM_AWS_VPC_ID| vpc id - only required for ddb endpoints |
|GTM_BASE_URL| Base url used to render links to agent ui - eg elb cname |
|GTM_WELCOME_MESSAGE_ENABLED| If not 'false', send a warning message on unconfigured repository pull requests |
|GTM_S3_DEPENDENCY_BUCKET| aws s3 storage of build dependencies|
|GTM_AWS_S3_PROXY| https_proxy for aws s3 |
|GTM_REPO_BLACKLIST| comma separated list of regex to blackist repo names from triggering events |

## Configure and deploy
- run: `npm run sls-deploy` - note that this will create aws re$ources..
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ resources:
GtmS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${env:GTM_S3_BUCKET}
BucketName: ${env:GTM_S3_DEPENDENCY_BUCKET}
# add additional custom bucket configuration here

# DynamoVpcEndpoint:
Expand Down
2 changes: 1 addition & 1 deletion src/agent/AgentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class AgentUtils {
static templateReplace(varDict, template, log) {
let templateStr = JSON.stringify(template);
if (!templateStr) {
log.error(`invalid template string for ${template}`);
log.debug(`invalid template string for ${template}`);
return template;
}
for (let key in varDict) {
Expand Down
31 changes: 31 additions & 0 deletions src/serverless/gtmGithubHook/gtmGithubHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ async function listener(event, context, callback) {
// decode and parse event body
let eventBody = decodeEventBody(event);

// blacklisted repos result in null error and 200 as this is a valid result
err = checkRepoBlacklisted(eventBody);
if (err) {
return callback(null, {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: err.message
});
}

/* eslint-disable */
console.log('---------------------------------');
console.log(`Github-Event: "${githubEvent}"`);
Expand Down Expand Up @@ -189,6 +199,27 @@ function setPullRequestEventStatus(ghEventId, eventBody) {
githubUtils.updateGitHubPullRequestStatus(status, () => {});
}

function checkRepoBlacklisted(body) {
let repoName = body.pull_request.head.repo.name || body.repository.name;

let blacklist = process.env.GTM_REPO_BLACKLIST ? process.env.GTM_REPO_BLACKLIST.split(',') : [];

let blacklisted = false;
if (blacklist && blacklist.length > 0) {
blacklist.forEach(blacklistPattern => {
if (!blacklisted) {
let pattern = new RegExp(blacklistPattern.trim());
if (pattern.test(repoName)) {
let msg = `matched blacklist repo pattern '${blacklistPattern.trim()}' - skipping.`;
console.log(msg);
blacklisted = new Error(msg);
}
}
});
}
return blacklisted;
}

module.exports = {
listener: listener,
getTaskConfig: getTaskConfig,
Expand Down

0 comments on commit 35132f7

Please sign in to comment.