Skip to content

Track a daily contribution goal #10

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
GITHUB_USERNAME="<YOUR_GITHUB_NAME_HERE>"
CONTRIBUTION_GOAL_TRACKING=true
CONTRIBUTION_GOAL="1000"
CONTRIBUTION_GOAL_DAILY_TRACKING=true
CONTRIBUTION_GOAL_DAILY="5"
COMPACT_UI=true
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ $ npm install

### Configure

In the root folder you'll need to modify the `.env` file with **your** GitHub username. Here you'll also be able to customize contribution goal tracking as well. Simply give the tracking value `TRUE` or `FALSE` to turn it on or off, respectively, and provide your ideal goal number to give yourself a completion percentage.
In the root folder you'll need to modify the `.env` file with **your** GitHub username. Here you'll also be able to customize contribution goal tracking as well. Simply give the tracking value `TRUE` or `FALSE` to turn it on or off, respectively, and provide your ideal goal number to give yourself a completion percentage. You can also enable the tracking of daily contributions.

```bash
GITHUB_USERNAME="<YOUR_GITHUB_NAME_HERE>"
CONTRIBUTION_GOAL_TRACKING=true
CONTRIBUTION_GOAL="1000"
CONTRIBUTION_GOAL_DAILY_TRACKING=true
CONTRIBUTION_GOAL_DAILY="5"
COMPACT_UI=true
```

Expand All @@ -54,7 +56,7 @@ Obviously [BitBar](https://github.com/matryer/bitbar).

I also use the [gh-scrape](https://github.com/Shikkic/gh-scrape) to crawl GitHub and parse selected values from public GitHub profiles. Feel free to contribute if you'd like!

I use this module instead of using the GitHub API for a few reasons. I wanted to make it as easy as possible to setup and requiring users to generate and input an API key made the barrier of entry seem high. Also, this allows us to only focus on publicly available contributions, which was the original intended purpose.
I use this module instead of using the GitHub API for a few reasons. I wanted to make it as easy as possible to setup and requiring users to generate and input an API key made the barrier of entry seem high. Also, this allows us to only focus on publicly available contributions, which was the original intended purpose.

#### Suggestions, comments?

Expand Down
42 changes: 33 additions & 9 deletions gitbar_plugin/gh.5m.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
require('dotenv').config({path: __dirname+'/../.env'});
const username = process.env.GITHUB_USERNAME;
const userUrl = "http://github.com/" + username;

const compactUI = process.env.COMPACT_UI;

// Yearly contribution goal
const contributionGoalTracking = process.env.CONTRIBUTION_GOAL_TRACKING;
const contributionGoal = process.env.CONTRIBUTION_GOAL;
const compactUI = process.env.COMPACT_UI;

// Daily contribution goal
const contributionGoalDailyTracking = process.env.CONTRIBUTION_GOAL_DAILY_TRACKING;
const contributionGoalDaily = process.env.CONTRIBUTION_GOAL_DAILY;

// Detect user's menu bar style
var child_process = require('child_process');
Expand All @@ -32,10 +39,12 @@ try {

// Font, Color, and Emoji Settings
const redText = "| color=red size=14",
normalText = "| size=14",
boldText = "| color=" + boldColor + " size=14",
heartEmoji = ":heart_decoration:",
brokenHeartEmoji = ":broken_heart:";
normalText = "| size=14",
boldText = "| color=" + boldColor + " size=14",
heartEmoji = ":heart_decoration:",
brokenHeartEmoji = ":broken_heart:",
chartEmoji = ":chart_with_upwards_trend:",
starEmoji = ":star:";

// Import Github Scraping Library
var gh = require('gh-scrape'),
Expand Down Expand Up @@ -65,8 +74,16 @@ gh.scrapeContributionDataAndStats(userUrl, function(data) {
// Set Displayed Emoji
var visibleEmoji = data.commitsToday ? heartEmoji : brokenHeartEmoji;

if (contributionGoalDailyTracking == 'true') {
if (commitsToday >= contributionGoalDaily) {
visibleEmoji = starEmoji;
} else {
visibleEmoji = chartEmoji;
}
}

// Log Output To Bitbar
if (compactUI == 'true') {
if (compactUI === "true") {
console.log(visibleEmoji + " " + commitsToday + contributionsTodayColor);
console.log("---");
console.log("Contributions");
Expand All @@ -76,13 +93,20 @@ gh.scrapeContributionDataAndStats(userUrl, function(data) {
console.log("---");
}
console.log("Total: ", totalContributions, totalContributionsColor);
if (contributionGoalTracking) {
// Log Contribution Goal tracking if enabled
if (contributionGoalTracking === "true") {
// Log Yearly Contribution Goal tracking if enabled
console.log("---");
console.log("Contribution Goal");
console.log("Yearly Contribution Goal");
console.log("Goal: ", contributionGoal, normalText);
console.log("Completion: ", (totalContributions / contributionGoal * 100).toFixed(2) + "% " + boldText);
}
if (contributionGoalDailyTracking === "true") {
// Log Yearly Contribution Goal tracking if enabled
console.log("---");
console.log("Daily Contribution Goal");
console.log("Goal: ", contributionGoalDaily, normalText);
console.log("Completion: ", (commitsToday / contributionGoalDaily * 100).toFixed(2) + "% " + boldText);
}
console.log("---");
console.log("Streaks");
console.log("Current: ", currentStreak, currentStreakColor);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitbar",
"version": "0.0.0",
"version": "0.1.0",
"description": "text",
"main": "index.js",
"scripts": {
Expand Down