npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-activity

v1.0.4

Published

Retrieve a users GitHub activity feed in neat JSON

Downloads

8

Readme

github-activity

Retrieves a users GitHub activity (from their Atom feed) and parses it into a useful js object/json. GitHub has capped the feed to return the most recent 30 events.

Installation

Use npm to install:

$ npm install --save github-activity
$ npm test

Usage

A simple example using the asynchronous fetch(username) method:

var activity = require('github-activity');

activity.fetch('barangutan', function(err, feed) {
    if(err) console.log(err);
    
    if(feed) {
        console.log('Returned %d feed items\n', feed.length);
        // Returned 30 feed items
        
        feed.forEach(function(item) {
            console.log('%s (%s)', item.action, item.date);
            // barangutan starred chalk/chalk (15 hours ago)
        });
    }
});

Another example, this time using stream(username) method which emits custom events:

var activity = require('github-activity');

activity.stream('barangutan');

activity.on('item', function(item) {
    console.log('%s (%s)', item.action, item.date);
    // barangutan starred chalk/chalk (15 hours ago)
});

activity.on('error', function(err) {
    console.log(error);
});

activity.on('end', function(count) {
    console.log('\nReturned %d feed items', count);
    // Returned 30 feed items
});

Results

fetch() returns an array of feed objects ('items') while stream() will obviously return one item at a time. The properties of said item should be self-explanatory.

{
    "guid": "PushEvent/2972967863",
    "action": "barangutan pushed to master at barangutan/github-activity",
    "event": "push",
    "icon": "<span class='mega-octicon octicon-git-commit'></span>",
    "href": "https://github.com/barangutan/github-activity/compare/e178f00e59...8bd8b9b6ea",
    "date": "2 hours ago"
}

Config

There are a handful of config options you can pass into the fetch(username, config) and stream(username, config) methods as a second argument:

{
    events: ['issues', 'pull_request', 'push', 'issue_comments', 'watch'],
    megaIcons: true|false,
    dateFormat: 'MMMM Do YYYY'
}
  • events: [] - an array of valid 'event' types you want returned. Valid types are listed in the example above. Please note that a watch event is triggered when you Star a repo, and not when you 'Watch' it. GitHub doesn't differenciate between the two for its activity feed.
  • megaIcons: bool - by default, GitHub adds the mega-octicon class to icons for events such as issue comments, pushes and pull requests in order to highlight their importance (this class makes the icon 32px instead of the standard 16px). If you would rather return a uniform size for all your items, set this megaIcons flag to false.
  • dateFormat: string - the default date returned is using the moment().fromNow() method (2 hours ago, yesterday etc). You can pass a date format string here to override.

Example:

So we're only interested in pull requests, disabling mega-icons and formatting the date to 'Day, nth of month year':

var activity = require('github-activity');

activity.stream('barangutan', {
    events: ['pull_request'],
    megaIcons: false,
    dateFormat: 'dddd, Do of MMMM YYYY'
});

activity.on('item', function(item) {
    console.log('%s on %s', item.action, item.date);
    // barangutan opened pull request Marak/faker.js#236 on Thursday, 9th of July 2015
    console.log('Icon: %s', item.icon);
    // Icon: <span class="octicon octicon-git-pull-request"></span>
});