Skip to content
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

Merged
merged 26 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e159030
replaced git-standup with gitlog
mojoaxel Apr 18, 2017
a2f3250
removed git-standup dependencie
mojoaxel Apr 19, 2017
83da292
added myself as contributor ;-)
mojoaxel Apr 19, 2017
8cff4ac
reverted: added myself as contributor ;-)
mojoaxel Apr 19, 2017
ed9f20e
also get gitlogs also from subdirs up to a given depth
mojoaxel Apr 19, 2017
36cb216
Merge branch 'master' into gitlog
mojoaxel Apr 20, 2017
2146858
updated README
mojoaxel Apr 20, 2017
cf3ecc8
updated subdirs release
mojoaxel Apr 21, 2017
f38f9fd
added error handling
mojoaxel Apr 21, 2017
d349d8d
Merge remote-tracking branch 'upstream/master' into gitlog
mojoaxel Apr 21, 2017
752a227
Merge branch 'master' into gitlog
mojoaxel Apr 26, 2017
29a7b70
Merge branch 'gitlog' of github.com:mojoaxel/tiny-care-terminal into …
mojoaxel Apr 26, 2017
878fea1
seperated gitbot into own module;
mojoaxel Apr 26, 2017
b30df8b
Merge branch 'master' into gitlog
mojoaxel Apr 26, 2017
df56ba5
fixed emty commit list
mojoaxel Apr 26, 2017
6922c43
@notwaldorf review comments
mojoaxel Apr 26, 2017
3eebc08
Merge branch 'master' into gitlog
mojoaxel Apr 27, 2017
4bc9a05
added repo name to commit history
mojoaxel Apr 27, 2017
1aed41b
do not hide commits while reloading
mojoaxel Apr 27, 2017
3f3886d
make it possible to switch between git-standup and gitlog
mojoaxel Apr 27, 2017
294657b
filter pure administrative commits
mojoaxel Apr 27, 2017
4cf5e21
readded git-stanup as peerDependency
mojoaxel May 7, 2017
86caaa0
use existing git-standup implementation
mojoaxel May 7, 2017
7d6ed23
Merge branch 'master' into gitlog
mojoaxel May 7, 2017
f945c1e
Merge branch 'master' into gitlog
mojoaxel May 12, 2017
e1ded0d
Merge branch 'gitlog' of github.com:mojoaxel/tiny-care-terminal into …
mojoaxel May 12, 2017
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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ lists the environment variables that you can copy in your `rc` files:
- `TTC_SAY_BOX = parrot | bunny | llama | cat`, to party with a different parrot (or,
more specifically: to have a different animal say a message in the big box)
- `TTC_REPOS`, a comma separated list of repos to look at for `git` commits.
This is using [`git-standup`](https://github.com/kamranahmedse/git-standup) under
the hood, and looks one subdirectory deep (so if you have all your code
directories in a `~/Code`, you only need to list that one)
- `TTC_REPOS_DEPTH` is the max directory-depth to look for git repositories in
the directories defined with `TTC_REPOS` (by default 1). Note that the deeper
the directory depth, the slower the results will be fetched.
Expand Down
50 changes: 30 additions & 20 deletions care.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env node
var config = require(__dirname + '/config.js');
var twitterbot = require(__dirname + '/twitterbot.js');
var gitbot = require(__dirname + '/gitbot.js');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌


var spawn = require('child_process').spawn;
var blessed = require('blessed');
var contrib = require('blessed-contrib');
var chalk = require('chalk');
var parrotSay = require('parrotsay-api');
var bunnySay = require('sign-bunny');
var weather = require('weather-js');

console.dir(gitbot);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 sorry...gone

debugger;

var screen = blessed.screen(
{fullUnicode: true, // emoji or bust
smartCSR: true,
Expand Down Expand Up @@ -115,21 +118,35 @@ function doTheTweets() {
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();
});

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);

function getCommits(data, box) {
var commitRegex = /(.......) (- .*)/g;
var content = colorizeLog(data);
box.content += content;
return (box.content.match(commitRegex) || []).length;
}

function showError(err, box) {
getCommits(`😥 ${err}`, box);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this bit actually needed? For an error, can't we just do box.content = err?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

screen.render();
}

gitbot.findGitRepos(config.repos, config.reposDepth-1, (err, allRepos) => {
if (err) return showError(err);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return on a new line, please (here and everywhere)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noproblemo

gitbot.getCommitsFromRepos(allRepos, 1, (err, data) => {
if (err) return showError(err, todayBox);
todayCommits = getCommits(`${data}`, todayBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
});
gitbot.getCommitsFromRepos(allRepos, 7, (err, data) => {
if (err) return showError(err, weekBox);
weekCommits = getCommits(`${data}`, weekBox);
updateCommitsGraph(todayCommits, weekCommits);
screen.render();
});
});
}

Expand Down Expand Up @@ -169,13 +186,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]})
}
Expand Down
5 changes: 4 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ 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(','),

// The directory-depth on how to look for git-repos. Use with care!
reposDepth: process.env.TTC_REPOS_DEPTH || 1,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already called depth, below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry...merges and stuff...will fix


// Directory-depth to look for git repositories.
depth: (process.env.TTC_REPOS_DEPTH || 1),
Expand Down
74 changes: 74 additions & 0 deletions gitbot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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) callback(err, null);
if (!dir.includes('.git') && isGit) {
allRepos.push(dir);
}
dirDone();
});
}, repoDone);
});
}, err => {
callback(err, allRepos.sort());
});
}

/**
* 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,
since: `${days} days ago`,
fields: ['abbrevHash', 'subject', 'authorDateRel', 'authorName'],
author: gitUsername
}, (err, logs) => {
if (err) callback(err, null);
logs.forEach(c => {
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;
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add this back in

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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"
}
Expand Down
1 change: 0 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export TTC_REPOS='~/Work/Code,~/Fun/Code'
# The max directory-depth to look for git repositories in
the directories defined with `TTC_REPOS`. Note that the deeper
the directory depth, the slower the results will be fetched.

export TTC_REPOS_DEPTH=2

# Location/zip code to check the weather for. Both 90210 and "San Francisco, CA"
Expand Down
36 changes: 0 additions & 36 deletions standup-helper.sh

This file was deleted.