Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unrelated commit: Updated the git_profanity_check app.
  • Loading branch information
tbranyen committed Apr 30, 2014
commit c7c961fa0076d04a29581a4c642c6c8095f1a470
68 changes: 47 additions & 21 deletions example/apps/git_profanity_check.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,66 @@
#!/usr/bin/env node
// vim: ft=javascript

// Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
// Copyright 2011-2014, Tim Branyen @tbranyen <tim@tabdeveloper.com>
// Dual licensed under the MIT and GPL licenses.
// Script to detect cursewords in commit messages and provide the
// offending commit sha's.
// vim: ft=javascript
// Script to detect cursewords in commit messages and provide the offending
// commit sha's.
//
// Usage:
//
// node git_profanity_check some/repo/.git
//
var git = require('../../');

var curses = ['add', 'swears', 'here'],
path = '../../.git',
branchName = 'master',
reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi');

var curses = ['put', 'curse', 'words', 'here'];
var path = './.git';
var branch = 'master';
var reCurse = new RegExp('\\b(?:' + curses.join('|') + ')\\b', 'gi');

// Default path is `.git`.
if (process.argv.length < 3) {
console.log('No git path passed as argument, defaulting to ./.git');
} else {
console.log('No path passed as argument, defaulting to .git.');
}
// Otherwise defaults.
else {
path = process.argv[2];

// Set repo branch
if (process.argv.length < 4) {
console.log('No repo branchName passed as argument, defaulting to master');
} else {
branchName = process.argv[3];
console.log('No branch passed as argument, defaulting to master.');
}
else {
branch = process.argv[3];
}
}

git.Repo.open(path, function(error, repo) {
if (error) throw error;
// Open repository.
git.Repo.open(path, function(err, repo) {
if (err) {
throw new Error(err);
}

repo.getBranch(branchName, function(error, branch) {
if (error) throw error;
// Open branch, default to master.
repo.getBranch(branch, function(err, branch) {
if (err) {
throw new Error(err);
}

// Iterate history
var history = branch.history();

// Iterate over every commit message and test for words.
history.on('commit', function(commit) {
if (reCurse.test(commit.message()))
console.log('Curse detected in commit', commit.sha(), 'message', commit.message());
}).start();
var message = commit.message();

if (reCurse.test(message)) {
console.log('Curse detected in commit', commit.sha());
console.log('=> ', message);
return;
}
});

// Start history iteration.
history.start();
});
});