-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replaced git-standup with gitlog #18
Changes from 21 commits
e159030
a2f3250
83da292
8cff4ac
ed9f20e
36cb216
2146858
cf3ecc8
f38f9fd
d349d8d
752a227
29a7b70
878fea1
b30df8b
df56ba5
6922c43
3eebc08
4bc9a05
1aed41b
3f3886d
294657b
4cf5e21
86caaa0
7d6ed23
f945c1e
e1ded0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/usr/bin/env node | ||
var config = require(__dirname + '/config.js'); | ||
var twitterbot = require(__dirname + '/twitterbot.js'); | ||
var gitbot = require(__dirname + '/gitbot.js'); | ||
|
||
var spawn = require('child_process').spawn; | ||
var blessed = require('blessed'); | ||
|
@@ -116,21 +117,54 @@ function doTheCodes() { | |
var todayCommits = 0; | ||
var weekCommits = 0; | ||
|
||
var today = spawn('sh ' + __dirname + '/standup-helper.sh', ['-m ' + config.depth, config.repos], {shell:true}); | ||
todayBox.content = ''; | ||
today.stdout.on('data', data => { | ||
todayCommits = getCommits(`${data}`, todayBox); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
function getCommits(box, data) { | ||
var content = colorizeLog(data || ''); | ||
box.content += content; | ||
var commitRegex = /(.......) (- .*)/g; | ||
return (box && box.content) ? (box.content.match(commitRegex) || []).length : '0'; | ||
} | ||
|
||
var week = spawn('sh ' + __dirname + '/standup-helper.sh', ['-m ' + config.depth + ' -d 7', config.repos], {shell:true}); | ||
weekBox.content = ''; | ||
week.stdout.on('data', data => { | ||
weekCommits = getCommits(`${data}`, weekBox); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
if (config.gitbot.toLowerCase() === 'gitstandup') { | ||
todayBox.content = ''; | ||
config.repos.forEach(repo => { | ||
var today = spawn(`cd ${repo} && git-standup`, [`-m ${config.depth}`, '-d 1'], {shell:true}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uhhhhhh so I'm not 100% sure this works, because git-standup is on the wrong path (and works locally, but doesn't work when installed as a package). Can you just revert this, and leave the old git-standup behaviour, so that this PR just adds gitlog, and not other things? That way it's easier if something goes wrong after this PR :) |
||
today.stdout.on('data', data => { | ||
todayCommits = getCommits(todayBox, `${data}`); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
}); | ||
weekBox.content = ''; | ||
config.repos.forEach(repo => { | ||
var today = spawn(`cd ${repo} && git-standup`, [`-m ${config.depth}`, '-d 7'], {shell:true}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
today.stdout.on('data', data => { | ||
weekCommits = getCommits(weekBox, `${data}`); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
}); | ||
} else { | ||
gitbot.findGitRepos(config.repos, config.depth-1, (err, allRepos) => { | ||
if (err) | ||
return todayBox.content = err; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this won't call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point! I'll improve.. |
||
gitbot.getCommitsFromRepos(allRepos, 1, (err, data) => { | ||
if (err) | ||
return todayBox.content = err; | ||
todayBox.content = ''; | ||
todayCommits = getCommits(todayBox, `${data}`); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
gitbot.getCommitsFromRepos(allRepos, 7, (err, data) => { | ||
if (err) | ||
return weekBox.content = err; | ||
weekBox.content = ''; | ||
weekCommits = getCommits(weekBox, `${data}`); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
function makeBox(label) { | ||
|
@@ -169,13 +203,6 @@ function makeGraphBox(label) { | |
return options; | ||
} | ||
|
||
var commitRegex = /(.......) (- .*)/g; | ||
function getCommits(data, box) { | ||
var content = colorizeLog(data); | ||
box.content += content; | ||
return (box.content.match(commitRegex) || []).length; | ||
} | ||
|
||
function updateCommitsGraph(today, week) { | ||
commits.setData({titles: ['today', 'week'], data: [today, week]}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,14 @@ var config = { | |
apiKeys: (process.env.TTC_APIKEYS || 'true') === 'true', | ||
|
||
// Directories in which to run git-standup on for a list of your recent commits. | ||
repos: (process.env.TTC_REPOS || '~/Code').replace(/,/g, ' '), | ||
repos: (process.env.TTC_REPOS || '~/Code').split(','), | ||
|
||
// Directory-depth to look for git repositories. | ||
depth: (process.env.TTC_REPOS_DEPTH || 1), | ||
|
||
// Which method is to be used to read the git commits ('gitstandup' | 'gitlog'). | ||
gitbot: (process.env.TTC_GITBOT || 'gitstandup'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Awesome! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. git-standup is the default settings for now. Let's give the gitlog implementation a try on different platforms, maybe we can remove the whole bash-scripting stuff all together at some point! |
||
|
||
// Where to check the weather for. | ||
// It's using weather.service.msn.com behind the curtains. | ||
weather: process.env.TTC_WEATHER || 'San Francisco', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const gitUsername = require('git-user-name')(); | ||
const resolve = require('resolve-dir'); | ||
const subdirs = require('subdirs'); | ||
const isGit = require('is-git'); | ||
const gitlog = require('gitlog'); | ||
const path = require('path'); | ||
const async = require("async"); | ||
|
||
/** | ||
* Go through all `repos` and look for subdirectories up to a given `depth` | ||
* and look for repositories. | ||
* Calls `callback` with array of repositories. | ||
*/ | ||
function findGitRepos(repos, depth, callback) { | ||
let allRepos = []; | ||
async.each(repos, (repo, repoDone) => { | ||
repo = resolve(repo); | ||
subdirs(repo, depth, (err, dirs) => { | ||
if (err) { | ||
switch (err.code) { | ||
case 'ENOENT': | ||
return callback(`Could not open directory directory: ${err.path}\n`, null); | ||
case 'EACCES': | ||
return; //ignore if no access | ||
default: | ||
return callback(`Error "${err.code}" doing "${err.syscall}" on directory: ${err.path}\n`, null); | ||
} | ||
} | ||
if (dirs) dirs.push(repo); | ||
async.each(dirs, (dir, dirDone) => { | ||
isGit(dir, (err, isGit) => { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
if (!dir.includes('.git') && isGit) { | ||
allRepos.push(dir); | ||
} | ||
dirDone(); | ||
}); | ||
}, repoDone); | ||
}); | ||
}, err => { | ||
callback(err, allRepos.sort().reverse()); | ||
}); | ||
} | ||
|
||
/** | ||
* returns all commits of the last given `days`. | ||
* Calls `callback` with line-seperated-strings of the formatted commits. | ||
*/ | ||
function getCommitsFromRepos(repos, days, callback) { | ||
let cmts = []; | ||
async.each(repos, (repo, repoDone) => { | ||
try { | ||
gitlog({ | ||
repo: repo, | ||
number: 100, //max commit count | ||
since: `${days} days ago`, | ||
fields: ['abbrevHash', 'subject', 'authorDateRel', 'authorName'], | ||
author: gitUsername | ||
}, (err, logs) => { | ||
// Error | ||
if (err) | ||
return callback(err, null); | ||
|
||
// Repo path | ||
if (logs.length >= 1) | ||
cmts.push(repo); | ||
|
||
// Commit | ||
logs.forEach(c => { | ||
if (c.status && c.status.length) | ||
cmts.push(`${c.abbrevHash} - ${c.subject} (${c.authorDateRel}) <${c.authorName.replace('@end@\n','')}>`); | ||
}); | ||
repoDone(); | ||
}); | ||
} catch(err) { | ||
callback(err, null); | ||
} | ||
}, err => { | ||
callback(err, cmts.length > 0 ? cmts.join('\n') : "Nothing yet. Start small!"); | ||
}); | ||
} | ||
|
||
module.exports.findGitRepos = findGitRepos; | ||
module.exports.getCommitsFromRepos = getCommitsFromRepos; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,17 @@ | |
"blessed": "^0.1.81", | ||
"blessed-contrib": "^4.7.5", | ||
"chalk": "^1.1.3", | ||
"git-user-name": "^1.2.0", | ||
"gitlog": "^2.4.0", | ||
"is-git": "0.0.1", | ||
"parrotsay-api": "^0.1.1", | ||
"resolve-dir": "^1.0.0", | ||
"sign-bunny": "^1.0.0", | ||
"scraperjs": "^1.2.0", | ||
"subdirs": "^1.0.1", | ||
"twit": "^2.2.5", | ||
"weather-js": "^2.0.0" | ||
}, | ||
"peerDependencies": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls add this back in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @notwaldorf Wow! You actually reviewed this at #jsconfeu ! 🎉 Thx. I'll try to have a look tonight. |
||
"git-standup": "^2.1.8" | ||
}, | ||
"scripts": { | ||
"start": "node care.js" | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌