Giter Site home page Giter Site logo

ionicabizau / git-stats Goto Github PK

View Code? Open in Web Editor NEW
6.3K 60.0 178.0 5.51 MB

πŸ€ Local git statistics including GitHub-like contributions calendars.

License: MIT License

JavaScript 12.49% Shell 0.89% HTML 86.63%
contributions-calendar gitstats calendar statistics hacktoberfest

git-stats's Introduction

git-stats

$ git-stats

Support me on Patreon Buy me a book PayPal Ask me anything Version Downloads Get help on Codementor

Buy Me A Coffee

Local git statistics including GitHub-like contributions calendars.

I'd be curious to see your calendar with all your commits. Ping me on Twitter (@IonicaBizau). πŸ˜„ Until then, here's my calendar:

Contents

☁️ Installation

You can install the package globally and use it as command line tool:

# Install the package globally
npm i -g git-stats

# Initialize git hooks
# This is for tracking the new commits
curl -s https://raw.githubusercontent.com/IonicaBizau/git-stats/master/scripts/init-git-post-commit | bash

Then, run git-stats --help and see what the CLI tool can do.

$ git-stats --help
Usage: git-stats [options]

Local git statistics including GitHub-like contributions calendars.

Options:
  -r, --raw              Outputs a dump of the raw JSON data.
  -g, --global-activity  Shows global activity calendar in the current
                         repository.
  -d, --data <path>      Sets a custom data store file.
  -l, --light            Enables the light theme.
  -n, --disable-ansi     Forces the tool not to use ANSI styles.
  -A, --author           Filter author related contributions in the current
                         repository.
  -a, --authors          Shows a pie chart with the author related
                         contributions in the current repository.
  -u, --until <date>     Optional end date.
  -s, --since <date>     Optional start date.
  --record <data>        Records a new commit. Don't use this unless you are
                         a mad scientist. If you are a developer just use
                         this option as part of the module.
  -h, --help             Displays this help.
  -v, --version          Displays version information.

Examples:
  $ git-stats # Default behavior (stats in the last year)
  $ git-stats -l # Light mode
  $ git-stats -s '1 January 2012' # All the commits from 1 January 2012 to now
  $ git-stats -s '1 January 2012' -u '31 December 2012' # All the commits from 2012

Your commit history is kept in ~/.git-stats by default. You can create
~/.git-stats-config.js to specify different defaults.

Documentation can be found at https://github.com/IonicaBizau/git-stats.

Usage

Importing and deleting commits

I know it's not nice to start your git commit calendar from scratch. That's why I created git-stats-importer–a tool which imports or deletes the commits from selected repositories.

Check it out here: https://github.com/IonicaBizau/git-stats-importer

The usage is simple:

# Install the importer tool
$ npm install -g git-stats-importer

# Go to the repository you want to import
$ cd path/to/my-repository

# Import the commits
$ git-stats-importer

# ...or delete them if that's a dummy repository
$ git-stats-importer --delete

Importing all the commits from GitHub and BitBucket

Yes, that's also possible. I built a tool which downloads and then imports all the commits you have pushed to GitHub and BitBucket!

# Download the repository downloader
$ git clone https://github.com/IonicaBizau/repository-downloader.git

# Go to repository downloader
$ cd repository-downloader

# Install the dependencies
$ npm install

# Start downloading and importing
$ ./start

What about the GitHub Contributions calendar?

If you want to visualize the calendars that appear on GitHub profiles, you can do that using ghcal.

# Install ghcal
$ npm install -g ghcal

# Check out @alysonla's contributions
$ ghcal -u alysonla

For more detailed documentation, check out the repository: https://github.com/IonicaBizau/ghcal.

If want to get even more GitHub stats in your terminal, you may want to try github-stats--this is like git-stats but with data taken from GitHub.

Using the configuration file

You can tweak the git-stats behavior using a configuration file in your home directory: ~/.git-stats-config.js.

This file should export an object, like below (defaults are listed):

module.exports = {
    // "DARK", "LIGHT" or an object interpreted by IonicaBizau/node-git-stats-colors
    "theme": "DARK"

    // The file where the commit hashes will be stored
  , "path": "~/.git-stats"

    // [DEPRECATED] First day of the week https://github.com/IonicaBizau/git-stats/issues/121
  , first_day: "Sun"

    // This defaults to *one year ago*
    // It can be any parsable date
  , since: undefined

    // This defaults to *now*
    // It can be any parsable date
  , until: undefined

    // Don't show authors by default
    // If true, this will enable the authors pie
  , authors: false

    // No global activity by default
    // If true, this will enable the global activity calendar in the current project
  , global_activity: false
};

Since it's a js file, you can require any other modules there.

Saving the data as HTML and images

git-stats --raw outputs raw JSON format which can be consumed by other tools to generate results such as HTML files or images.

git-stats-html interprets the JSON data and generates an HTML file. Example:

# Install git-stats-html

npm install -g git-stats-html



# Export the data from the last year (generate out.html)

git-stats --raw | git-stats-html -o out.html



# Export data since 2015 (save the results in out.html)

git-stats --since '1 January 2015' --raw | ./bin/git-stats-html -o out.html --big

After we have the HTML file, we can generate an image file using pageres by @sindresorhus:

# Install pageres

npm install -g pageres-cli



# Generate the image from HTML

pageres out.html 775x250

Cross-platform compatibility

git-stats is working fine in terminal emulators supporting ANSI styles. It should work fine on Linux and OS X.

If you run git-stats to display graph on Windows, please use a terminal that can properly display ANSI colors.

Cygwin Terminal is known to work, while Windows Command Prompt and Git Bash do not. Improvements are more than welcome! πŸ’«

πŸ“‹ Example

Here is an example how to use this package as library. To install it locally, as library, you can use npm install git-stats (or yarn add git-stats):

// Dependencies
var GitStats = require("git-stats");

// Create the GitStats instance
var g1 = new GitStats();

// Display the ansi calendar
g1.ansiCalendar({
    theme: "DARK"
}, function (err, data) {
    console.log(err || data);
});

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. πŸ›
  3. For direct and quick help, you can use Codementor. πŸš€

πŸ“ Documentation

For full API reference, see the DOCUMENTATION.md file.

πŸ“° Press Highlights

πŸ˜‹ How to contribute

Have an idea? Found a bug? See how to contribute.

πŸ’– Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like πŸš€

  • Buy me a bookβ€”I love books! I will remember you after years if you buy me one. 😁 πŸ“–

  • PayPalβ€”You can make one-time donations via PayPal. I'll probably buy a coffee tea. 🍡

  • Support me on Patreonβ€”Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoinβ€”You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! ❀️

πŸ’« Where is this library used?

If you are using this library in one of your projects, add it in this list. ✨

  • git-stats-importer
  • git-stats-fcc-importer

πŸ“œ License

MIT © Ionică Bizău

git-stats's People

Contributors

alexander-mart avatar alromh87 avatar benhollomon avatar denvercoder1 avatar dependabot[bot] avatar flavioribeiro avatar furgerf avatar greut avatar imagdy avatar ionicabizau avatar jamieslome avatar jatenate avatar joeyhipolito avatar johannjacobsohn avatar kciter avatar linquize avatar m-zuber avatar rafaelstz avatar rrrene avatar ryanseys avatar sanketdg avatar theowenyoung avatar tyler-h avatar williamboman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-stats's Issues

TypeError: Cannot read property 'message' of null

When trying to import using the -e flag I get the following error:

/Users/aventurella/github/project/node_modules/gitlog-parser/index.js:37
      this._current.message += ('\n'+chunk);

TypeError: Cannot read property 'message' of null
    at Gitlog._write (/Users/aventurella/github/project/node_modules/gitlog-parser/index.js:37:20)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at Gitlog.Writable.write (_stream_writable.js:220:11)
    at LineStream.ondata (_stream_readable.js:556:20)
    at emitOne (events.js:96:13)
    at LineStream.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:177:18)
    at LineStream.Readable.push (_stream_readable.js:135:10)
    at LineStream.Transform.push (_stream_transform.js:128:32)

Doesn't launch on Ubuntu

vadi@vadi-HP-ZBook-14 ~/Programs (master) $ git-stats
/usr/bin/env: node: No such file or directory
vadi@vadi-HP-ZBook-14 ~/Programs (master) $ node
node-gyp  nodejs    
vadi@vadi-HP-ZBook-14 ~/Programs (master) $ which git-stats
/usr/local/bin/git-stats
vadi@vadi-HP-ZBook-14 ~/Programs (master) $ cat /usr/local/bin/git-stats
#!/usr/bin/env node

Usage not immediately clear

You have to get at least half way through the readme to understand that the tool has to be run from within a repository. (at least that is my feeling).

It would be nice to have a section much earlier explaining that you have to move into a folder of a repo in order to get data.
Maybe a new section (the first obviously) under the Usage heading?

Is there a particular reason git-stats keeps it's own record of git activity?

My first thought upon finding this project was that it was, of course, very cool! So I jumped into a terminal, downloaded the npm package, cd'd into the first big repo I thought of (my copy of the git repo itself) and ran git-stats. To my surprise, I saw an empty calendar. Perplexed, I jumped back to the readme to discover that git-stats keeps it's own commit history, rather than doing what I'd assumed it did, reading through the commit history of the repo the user was currently working in.

Graph current repository

How does one can graph current (working directory) repository commitments? Can git-stats take this information from git log?

error Error: ENOENT, open '~/.git-stats'

I get this when running git-stats:

error Error: ENOENT, open '/home/ionel/.git-stats'

Seems it doesn't create this file. What's going on here?

Details

$ node --version
v0.10.33

Export option

I was thinking it would be nice to have an data export option so that it could be used on a website.

Data is not displayed correctly

My contribute data is not correctly displayed: I can see some commits in ~/.git-stats are not shown. For example, there are many commits since 2016, but the calendar just showed one of them:

image

~/.git-stats is attached here: git-stat.zip

Browser graph

For the 2.0.0 I want to introduce some nice graphs in browser. 🌟

Formatting breaks when using `watch`

If you were to use watch git-stats, which calls the same command (i.e. git-stats) after a set interval of time, you should be able to see the stats graph update as changes are made.

Instead, there is a formatting issue that only shows you strange (unicode?) characters across your terminal. See image below:
screenshot from 2015-02-16 12 27 20

ReferenceError: lines is not defined

$ git-stats --authors
/usr/local/lib/node_modules/git-stats/lib/index.js:537
lines = stdout.split("\n");
^

ReferenceError: lines is not defined
at /usr/local/lib/node_modules/git-stats/lib/index.js:537:15
at LimitIt. (/usr/local/lib/node_modules/git-stats/node_modules/gry/lib/index.js:73:9)
at /usr/local/lib/node_modules/git-stats/node_modules/limit-it/lib/index.js:138:20
at ChildProcess.exithandler (child_process.js:204:7)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:821:16)
at Socket. (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)

Empty stats

I cloned my github repo and it shows zero stats... What am i doing wrong?
screenshot from 2015-02-16 17 27 02

Extract graph generation

Thanks for the awesome tool :)
I wanted to use CLI activity graph for other data too, especially for my clocker statistics. Therefore I extracted the part that generates the graph and published it as a standalone: cli-cal.
Looking forward to v2.0 I would love to help separating the stats- and graph-based parts. In this way git-stats is focused on generating the stats and uses external modules to generate CLI- or browser graphs (#46). These modules can be improved as a standalone, so #14 and #28 would be solved for all kind of data.

cDayObj is not defined

$ git-stats
/usr/local/lib/node_modules/git-stats/lib/index.js:506
cDayObj = graph[cDay];
^

ReferenceError: cDayObj is not defined
at /usr/local/lib/node_modules/git-stats/lib/index.js:506:21
at GitStats.iterateDays (/usr/local/lib/node_modules/git-stats/lib/index.js:371:9)
at /usr/local/lib/node_modules/git-stats/lib/index.js:505:14
at /usr/local/lib/node_modules/git-stats/lib/index.js:415:9
at /usr/local/lib/node_modules/git-stats/lib/index.js:316:9
at /usr/local/lib/node_modules/git-stats/node_modules/r-json/lib/index.js:23:13
at FSReqWrap.readFileAfterClose as oncomplete

Is there any method to git-stats --record some records from an JSON api?

Hi, I've implemented an api freeCodeCamp/freeCodeCamp#11650
of FreeCodeCamp to output stats in the format of

{
  stats: {
    username: "fcccc4f8191",
    stats: [
      {
        date: 1479552008474,
        hash: "6dedf981ecab9ce1b3f997508dcb796f90838328"
      },
      {
        date: 1479619115285,
        hash: "051284a491a053ba29896deaf7a49f17ade241c1"
      },
      {
        date: 1479619250135,
        hash: "3aa47ee34e5bab839c88bfb411f1946e84253fea"
      }
    ]
  }
}

Is there any method to import it to git-stats? If not, would you mind me to make a pull request to implement one?

number of columns not calculated correctly

When executing git-stats, the number of columns expected by the tool is always 1 bigger than the actual number of columns available (in the example the console has 100 columns, but the output fits into 101 columns). Changing the number of columns beforehand didn't change anything. Is there something that I'm missing as nobody else has this problem?

screen shot 2015-02-18 at 08 39 11

Display problem in tmux

Here's the screenshot from my gnome-terminal. It works like a charm.

git-status-terminal

But there's some problems when I execute git-status in tmux.

git-status-tmux

Catching git-commit from zsh

After adding your sample script for catching git commit to my .zshrc file:

$ git status
bash: -c: line 24: syntax error near unexpected token `status'
bash: -c: line 24: `} status'

So for now I'll have to live without it. Would be nice if there was an alternative, for zsh users though. :)

Installation Error: Cannot read property 'commits' of undefined

  • OS X (Homebrew)
  • Node version : 6.0.0 (installed with homebrew, and the same happens for node 4.x, 5.x that I've tested)
$ ls -lh `which node`
lrwxr-xr-x  1 wookayin  admin    29B  5  4 00:02 /usr/local/bin/node -> ../Cellar/node/6.0.0/bin/node

Try to Install:

$ npm install -g git-stats

Error:

/usr/local/bin/git-stats -> /usr/local/lib/node_modules/git-stats/bin/git-stats

> [email protected] postinstall /usr/local/lib/node_modules/git-stats
> node scripts/migration/2.0.0.js

error EISDIR: illegal operation on a directory, read
/usr/local/lib/node_modules/git-stats/scripts/migration/2.0.0.js:23
    data.commits = data.commits || {};
                       ^

TypeError: Cannot read property 'commits' of undefined
    at migrate (/usr/local/lib/node_modules/git-stats/scripts/migration/2.0.0.js:23:24)
    at Object.<anonymous> (/usr/local/lib/node_modules/git-stats/scripts/migration/2.0.0.js:38:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:159:18)
    at node.js:444:3

Looks migration script is broken, so tried npm install -g git-stats --ignore-scripts either: then the git-stats binary is installed, but another exception is thrown:

/usr/local/lib/node_modules/git-stats/lib/index.js:501
            cDayObj = graph[cDay];
                           ^

TypeError: Cannot read property 'May 4, 2015' of undefined

I am delving into this for what is the cause; this would be just a simple report as of now.

Thanks,

With fewer columns, the left side of the calendar should be hidden, not the right

When you've got less columns in your terminal, you really want to see the most recent activity in detail rather than the earliest (1 year old).

So, in the attached screenshot, given the activity in the second calendar, the first (printed when the window was much narrower) should really show the most recent n months with left-side ellipses, rather than the older n months and right-side ellipses.

screen shot 2015-02-18 at 10 53 47 am

New schema prototype (2.x.x)

I'm thinking at the ~/.git-stats file prototype which will be implemented starting with version 2.0.0.

{
    "commits": {
       "<date>": ["628947f965..........ea9689ca747", "..."]
    },
  , "remotes": {
        "[email protected]:IonicaBizau/git-stats.git": ["git-stats-hash1", "git-stats-hash2", ... ]
      , "[email protected]:IonicaBizau/git-stats-importer.git": ["git-stats-importer-hash1", "git-stats-importer-hash2", ... ]
    }
  , "config": {
      "light": true
   }
}
  • commits: an object with dates, being arrays with unique commit hashes.
  • remotes: an object with remotes, containing arrays with unique commit hashes
  • config: defaults, aliases ❓

I'm trying to cover the feedback from the following issues:

If you have any ideas how to improve this, please leave comments here. πŸ’¬

Set defaults in ~/.git-stats

I recently tried git-stats and immediately got bitten with issue #2. After seeing that file I assume that is a preferences file but I cannot find any docs about it. Is it possible to set things like your preferred colours mode in this file, for instance I'd like to set the --no-ansi option to be the default?

Installation instructions do not work

I installed the package like this (on Ubuntu 16.04):

sudo npm i -g git-stats

There were no errors and everything appeared to install OK.

Then I ran this script (as a regular user):
curl -s https://raw.githubusercontent.com/IonicaBizau/git-stats/master/scripts/init-git-post-commit | bash

When I try to run the script, the command cannot be found:
$ git-stats
-su: git-stats: command not found

What I am missing? I'm not a node programmer, so something may be missing from my environment that node users assume is always there.

streak statistics in global view appear to be off

Maybe I'm misunderstanding something, but the reported current and longest streaks for git-stats -g don't appear to be correct to me.

In each of my repositories, longest streak is the same as current streak. Neither number looks right. The issue might be on display in the image displayed in the readme---the global stats produced by git-stats --global there don't seem to agree with the displayed calendar, and the longest streak is the same as the current streak.

Current Streak is Always Zero when --until Date Is Supplied

Using git-stats and git-stats --since <date> on the commandline always gives me a correct number for the current streak.

But git-stats --until <date>, used with or without a --since date always has Current Streak set to zero.

I'm using node v4.4.3 on Linux and the v2.9.5 of git-stats installed from npm.

Bad month labels positionning

Current month labels positionning in the output is somewhat random and does not always appear nicely above the corresponding week columns.

git-stats-importer

It would be neat to position the month labels right above the first week of the month.

I wrote a patch for this and I'm gonna post a pull request asap.

Windows Error: Cannot find the remote origin url. Please add it.

Hello! Thank you for the great tool you made. I've installed it on my Mac, and it's awesome. Unfortunately there is Windows on my work laptop, and there I've got this sad message:

> git-stats-importer
error Cannot find the remote origin url. Please add it.

My .git/config file looks like this:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    url = [email protected]:foo/my-repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Is there something wrong?

ignore commits with identical hash

multiple import of the same repository causes multiple entries for each commit, even if the commit IDs should be unique.

Thats only the visible problem, the true problem is, that git-stats --record allows to record the same commit multiple times.

Using the commit ID as unique key should solve this, maybe also add the repo.url so we avoid cross repository ID conflicts(which statistically should never happen, for the same user)

Uninstall

I did not see an uninstall process. What would be the best way to uninstall git-stats?

Calendar doesn't seem to work correctly on Windows.

As someone who uses Windows at work, I tried git-stats and it only logs the days on the calendar by highlighting the day, but does not show the density of commits.

The default cmd font, 'raster font', displays rectangles instead of squares. Changing the font to either 'Consolas' or 'Lucida Console' does display square boxes, but still does not show density of commits.
raster-font
(Using CMD with 'Raster Font')

Using 'Git Bash', the calendar seems to overflow outside it's boundaries as well.
consolas
(Using 'Git Bash' with 'Consolas')

Export graph to image file

A good feature could be to add a command to export commit graph into an image file (jpeg/png) for easy sharing.

Something like "git-stats -exporttoimage" - you name it.

Export to HTML

Would be nice to be able to export to HTML file like git-stats --export=html > stats.html

Ideally should be various exporter types, like image, html, text ansi, etc and people can add any that they like :-)

Reason for remote url?

I'm curious about your decision for making the remote url of the repository a requirement for a git stats record.

When I read "...but locally, with all your git commits.", I imagined that the graph would be aggregating data across all of my commits (at least the repositories I have imported). Many of my repositories are just kept locally -- they are not connected to any remotes.

Is git-stats intended to only aggregate public contributions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.