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

ae-github

v0.0.1

Published

A higher-level wrapper around the Github API.

Downloads

4

Readme

browser support

Build Status

Github.js

Github.js provides a minimal higher-level wrapper around git's plumbing commands, exposing an API for manipulating GitHub repositories on the file level. It is being developed in the context of Prose, a content editor for GitHub.

This repo is now officially maintained by DevelopmentSeed, the people behind Prose.io.

Usage

Create a Github instance.

var github = new Github({
  username: "YOU_USER",
  password: "YOUR_PASSWORD",
  auth: "basic"
});

Or if you prefer OAuth, it looks like this:

var github = new Github({
  token: "OAUTH_TOKEN"
  auth: "oauth"
});

Repository API

var repo = github.getRepo(username, reponame);

Show repository information

repo.show(function(err, repo) {});

Get contents at a particular path.

repo.contents("path/to/dir", function(err, contents) {});

Fork repository. This operation runs asynchronously. You may want to poll for repo.contents until the forked repo is ready.

repo.fork(function(err) {});

Create Pull Request.

var pull = {
  title: message,
  body: "This pull request has been automatically generated by Prose.io.",
  base: "gh-pages",
  head: "michael" + ":" + "prose-patch",
};
repo.createPullRequest(pull, function(err, pullRequest) {});

Retrieve all available branches (aka heads) of a repository.

repo.listBranches(function(err, branches) {});

Store contents at a certain path, where files that don't yet exist are created on the fly.

repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', function(err) {});

Not only can you can write files, you can of course read them.

repo.read('master', 'path/to/file', function(err, data) {});

Move a file from A to B.

repo.move('master', 'path/to/file', 'path/to/new_file', function(err) {});

Remove a file.

repo.remove('master', 'path/to/file', function(err) {});

Exploring files of a repository is easy too by accessing the top level tree object.

repo.getTree('master', function(err, tree) {});

If you want to access all blobs and trees recursively, you can add ?recursive=true.

repo.getTree('master?recursive=true', function(err, tree) {});

Given a filepath, retrieve the reference blob or tree sha.

repo.getSha('master', '/path/to/file', function(err, sha) {});

For a given reference, get the corresponding commit sha.

repo.getRef('heads/master', function(err, sha) {});

Create a new reference.

var refSpec = {
  "ref": "refs/heads/my-new-branch-name",
  "sha": "827efc6d56897b048c772eb4087f854f46256132"
};
repo.createRef(refSpec, function(err) {});

Delete a reference.

repo.deleteRef('heads/gh-pages', function(err) {});

User API

var user = github.getUser();

List all repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner.

user.repos(function(err, repos) {});

List organizations the autenticated user belongs to.

user.orgs(function(err, orgs) {});

List authenticated user's gists.

user.gists(username, function(err, gists) {});

Show user information for a particular username. Also works for organizations.

user.show(username, function(err, user) {});

List public repositories for a particular user.

user.userRepos(username, function(err, repos) {});

List repositories for a particular organization. Includes private repositories if you are authorized.

user.orgRepos(orgname, function(err, repos) {});

List all gists of a particular user. If username is ommitted gists of the current authenticated user are returned.

user.userGists(username, function(err, gists) {});

Gist API

var gist = github.getGist(3165654);

Read the contents of a Gist.

gist.read(function(err, gist) {

});

Updating the contents of a Git. Please consult the documentation on GitHub.

var delta = {
  "description": "the description for this gist",
  "files": {
    "file1.txt": {
      "content": "updated file contents"
    },
    "old_name.txt": {
      "filename": "new_name.txt",
      "content": "modified contents"
    },
    "new_file.txt": {
      "content": "a new file"
    },
    "delete_this_file.txt": null
  }
};

gist.update(delta, function(err, gist) {
  
});

Tests

Github.js is automatically™ tested by the users of Prose. Because of that, we decided to save some time by not maintaining a test suite. Yes, you heard right. :) However, you can still consider it stable since it is used in production.

##Setup

Github.js has the following dependencies:

  • Underscore
  • Base64 (for basic auth). You can leave this if you are not using basic auth.

Include these before github.js :

<script src="lib/underscore-min.js">
<script src="lib/base64.js">
<script src="github.js">

Change Log

0.7.X

Switched to a native request implementation (thanks @mattpass). Adds support for GitHub gists, forks and pull requests.

0.6.X

Adds support for organizations and fixes an encoding issue.

0.5.X

Smart caching of latest commit sha.

0.4.X

Added support for OAuth.

0.3.X

Support for Moving and removing files.

0.2.X

Consider commit messages.

0.1.X

Initial version.