Skip to content

Commit

Permalink
fixing logging comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pGrovesy committed Apr 20, 2020
1 parent 87e0905 commit 21c1af6
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 14 deletions.
231 changes: 230 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,230 @@
node_modules
# Logs
.logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.pnp.*
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"javascript.suggestionActions.enabled": false,
"editor.tabSize": 2,
"files.eol": "\n"
"files.eol": "\n",
"terminal.integrated.disableLineWrapping": true,
"debug.console.wordWrap": false,
"editor.wordWrap":"off"
}
19 changes: 11 additions & 8 deletions lib/chain.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
const proc = require('./processors/index.js');
const actions = require('./actions/index.js');

// Pre Processors are mandatory steps to figure out the incomming action
const preProcessors = [proc.parseRequest, proc.parseAction];

// A NoAction chain is when we are not interested in what's going through
const noActionChain = [proc.audit];

// A pushg action chain is when someone tries to push to a remote repo
const pushActionChain = [proc.parsePush, proc.checkRepoInWhiteList, proc.audit];

// Executes the chain
const chain = (req) => {
let result = { };

Expand All @@ -24,15 +32,10 @@ const chain = (req) => {
return result;
};

// Get the chain for the action type
const getChain = (result) => {
if (result.action instanceof actions.NoAction) return [];

if (result.action instanceof actions.PushAction) {
return [
proc.parsePush,
proc.checkRepoInWhiteList,
];
}
if (result.action instanceof actions.NoAction) return noActionChain;
if (result.action instanceof actions.PushAction) return pushActionChain;
};

exports.exec = chain;
24 changes: 24 additions & 0 deletions lib/processors/audit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');

const dir = './.logs/';

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}

const exec = (req, result) => {
const data = JSON.stringify(result, null, 2);
fs.writeFileSync(`${dir}/${result.timestamp}.json`, data);

const action = {
action: 'checkRepoInWhiteList',
ok: true,
};

result.actionLog.push(action);

return result;
};

exports.exec = exec;

2 changes: 1 addition & 1 deletion lib/processors/checkRepoInWhiteList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const exec = (req, result, whiteList=config.getWhiteList) => {
if (!whiteList().includes(result.repo)) {
action.ok = false;
result.ok = false;
result.message = `Rejecting repo ${result.repoName} not in the whitelist`;
result.message = `Rejecting repo ${result.repo} not in the whitelist`;
}

result.actionLog.push(action);
Expand Down
1 change: 1 addition & 0 deletions lib/processors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ exports.parseRequest = require('./parseRequest.js').exec;
exports.parseAction = require('./parseAction.js').exec;
exports.parsePush = require('./parsePush.js').exec;
exports.checkRepoInWhiteList = require('./checkRepoInWhiteList.js').exec;
exports.audit = require('./audit.js').exec;
1 change: 0 additions & 1 deletion lib/processors/parsePush.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const exec = (req, result) => {
const messageParts = req.rawBody.split(' ');
console.debug(req.rawBody);
result.commit = messageParts[0];
result.commit2 = messageParts[1];
result.branch = messageParts[2];
Expand Down
3 changes: 1 addition & 2 deletions lib/processors/parseRequest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const exec = (req, result) => {
// Setup the basics
result.timesteamp = Date.now();
result.timestamp = Date.now();

// We'll use the URL for the moment to figure out the repo name
result.url = req.originalUrl;
Expand All @@ -15,7 +15,6 @@ const exec = (req, result) => {
result.actionLog = [];

const repo = getRepoNameFromUrl(result.url);
console.debug(repo);
result.repo = repo;

return result;
Expand Down

0 comments on commit 21c1af6

Please sign in to comment.