-
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
Add ability to toggle the commits graph via env variable #110
Open
zdoc01
wants to merge
1
commit into
notwaldorf:master
Choose a base branch
from
zdoc01:toggle-commits-graph
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ var bunnySay = require('sign-bunny'); | |
var yosay = require('yosay'); | ||
var weather = require('weather-js'); | ||
|
||
var TODAY_BOX_LABEL = ' 📝 Today '; | ||
var WEEK_BOX_LABEL = ' 📝 Week '; | ||
|
||
var inPomodoroMode = false; | ||
|
||
var screen = blessed.screen( | ||
|
@@ -81,17 +84,13 @@ screen.key(['p', 'C-p'], function(ch, key) { | |
}); | ||
|
||
var grid = new contrib.grid({rows: 12, cols: 12, screen: screen}); | ||
|
||
// grid.set(row, col, rowSpan, colSpan, obj, opts) | ||
var weatherBox = grid.set(0, 8, 2, 4, blessed.box, makeScrollBox(' 🌤 ')); | ||
var todayBox = grid.set(0, 0, 6, 6, blessed.box, makeScrollBox(' 📝 Today ')); | ||
var weekBox = grid.set(6, 0, 6, 6, blessed.box, makeScrollBox(' 📝 Week ')); | ||
var commits = grid.set(0, 6, 6, 2, contrib.bar, makeGraphBox('Commits')); | ||
var parrotBox = grid.set(6, 6, 6, 6, blessed.box, makeScrollBox('')); | ||
|
||
var tweetBoxes = {} | ||
tweetBoxes[config.twitter[1]] = grid.set(2, 8, 2, 4, blessed.box, makeBox(' 💖 ')); | ||
tweetBoxes[config.twitter[2]] = grid.set(4, 8, 2, 4, blessed.box, makeBox(' 💬 ')); | ||
var boxes = buildBoxes(config.commitsGraph); | ||
var weatherBox = boxes.weather; | ||
var todayBox = boxes.today; | ||
var weekBox = boxes.week; | ||
var commits = boxes.commits; | ||
var parrotBox = boxes.parrot; | ||
var tweetBoxes = boxes.tweets; | ||
|
||
tick(); | ||
setInterval(tick, 1000 * 60 * config.updateInterval); | ||
|
@@ -102,6 +101,62 @@ function tick() { | |
doTheCodes(); | ||
} | ||
|
||
function buildBoxes(showCommitsGraph) { | ||
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. because the |
||
var firstQuadrant = buildFirstQuadrantBoxes(showCommitsGraph); | ||
|
||
return { | ||
today: buildTodayBox(), | ||
week: buildWeekBox(), | ||
tweets: firstQuadrant.tweets, | ||
weather: firstQuadrant.weather, | ||
commits: firstQuadrant.commits, | ||
parrot: buildParrotBox() | ||
}; | ||
} | ||
|
||
function buildFirstQuadrantBoxes(showCommitsGraph) { | ||
var col = 6, colSpan = 6; | ||
|
||
if (showCommitsGraph) { | ||
col += 2; | ||
colSpan -= 2; | ||
} | ||
|
||
return { | ||
tweets: buildTweetBoxes(col, colSpan), | ||
weather: buildWeatherBox(col, colSpan), | ||
commits: (showCommitsGraph) ? buildCommitsGraphBox() : null | ||
}; | ||
} | ||
|
||
// grid.set(row, col, rowSpan, colSpan, obj, opts) | ||
function buildTweetBoxes(col, colSpan) { | ||
var boxes = {}; | ||
boxes[config.twitter[1]] = grid.set(2, col, 2, colSpan, blessed.box, makeBox(' 💖 ')); | ||
boxes[config.twitter[2]] = grid.set(4, col, 2, colSpan, blessed.box, makeBox(' 💬 ')); | ||
return boxes; | ||
} | ||
|
||
function buildWeatherBox(col, colSpan) { | ||
return grid.set(0, col, 2, colSpan, blessed.box, makeScrollBox(' 🌤 ')); | ||
} | ||
|
||
function buildCommitsGraphBox() { | ||
return grid.set(0, 6, 6, 2, contrib.bar, makeGraphBox('Commits')); | ||
} | ||
|
||
function buildTodayBox() { | ||
return grid.set(0, 0, 6, 6, blessed.box, makeScrollBox(TODAY_BOX_LABEL)); | ||
} | ||
|
||
function buildWeekBox() { | ||
return grid.set(6, 0, 6, 6, blessed.box, makeScrollBox(WEEK_BOX_LABEL)); | ||
} | ||
|
||
function buildParrotBox() { | ||
return grid.set(6, 6, 6, 6, blessed.box, makeScrollBox('')); | ||
} | ||
|
||
function doTheWeather() { | ||
weather.find({search: config.weather, degreeType: config.celsius ? 'C' : 'F'}, function(err, result) { | ||
if (result && result[0] && result[0].current) { | ||
|
@@ -157,29 +212,49 @@ function doTheCodes() { | |
var todayCommits = 0; | ||
var weekCommits = 0; | ||
|
||
function getCommits(data, box) { | ||
var content = colorizeLog(data || ''); | ||
box.content += content; | ||
function getNumCommits(commits) { | ||
var commitRegex = /(.......) (- .*)/g; | ||
return (box && box.content) ? (box.content.match(commitRegex) || []).length : '0'; | ||
return (commits) ? (commits.match(commitRegex) || []).length : '0'; | ||
} | ||
|
||
function updateBoxContent(box, content, numCommits) { | ||
var colorContent = colorizeLog(content || ''); | ||
box.content += colorContent; | ||
|
||
if (!config.commitsGraph) { | ||
var label = (box === todayBox) ? TODAY_BOX_LABEL : WEEK_BOX_LABEL; | ||
box.setLabel(`${label} (${numCommits})`); | ||
} | ||
|
||
return box; | ||
} | ||
|
||
function updateWeekCommits(commits) { | ||
weekCommits += getNumCommits(commits); | ||
|
||
updateBoxContent(weekBox, commits, weekCommits); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
|
||
screen.render(); | ||
} | ||
|
||
function updateTodayCommits(commits) { | ||
todayCommits += getNumCommits(commits); | ||
|
||
updateBoxContent(todayBox, commits, todayCommits); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
|
||
screen.render(); | ||
} | ||
|
||
if (config.gitbot.toLowerCase() === 'gitstandup') { | ||
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(); | ||
}); | ||
today.stdout.on('data', data => { updateTodayCommits(`${data}`); }); | ||
|
||
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(); | ||
}); | ||
week.stdout.on('data', data => { updateWeekCommits(`${data}`); }); | ||
} else { | ||
gitbot.findGitRepos(config.repos, config.depth-1, (err, allRepos) => { | ||
if (err) { | ||
|
@@ -192,19 +267,15 @@ function doTheCodes() { | |
screen.render(); | ||
} | ||
todayBox.content = ''; | ||
todayCommits = getCommits(`${data}`, todayBox); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
updateTodayCommits(`${data}`); | ||
}); | ||
gitbot.getCommitsFromRepos(allRepos, 7, (err, data) => { | ||
if (err) { | ||
return weekBox.content = err; | ||
screen.render(); | ||
} | ||
weekBox.content = ''; | ||
weekCommits = getCommits(`${data}`, weekBox); | ||
updateCommitsGraph(todayCommits, weekCommits); | ||
screen.render(); | ||
updateWeekCommits(`${data}`); | ||
}); | ||
}); | ||
} | ||
|
@@ -247,7 +318,9 @@ function makeGraphBox(label) { | |
} | ||
|
||
function updateCommitsGraph(today, week) { | ||
commits.setData({titles: ['today', 'week'], data: [today, week]}) | ||
if (commits) { | ||
commits.setData({titles: ['today', 'week'], data: [today, week]}) | ||
} | ||
} | ||
|
||
function colorizeLog(text) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The problem with this is that this changes makes it realy difficult to review your PR.
Pull request should ideally only taggle on feature or issue and should not make any changes to code that is not part of this change-set.
I like the new style. could you create a new PR that "fixes" the README please!?