![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
github-api
Advanced tools
Readme
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 was formerly developed in the context of Prose, a content editor for GitHub.
Either grab github.js
from this repo or install Github.js via npm:
npm install github-api
Alternatively, you can install the library using Bower:
bower install github-api
## Compatibility
Note: Starting from version 0.10.8, Github.js supports Internet Explorer 9. However, the underlying
methodology used under the hood to perform CORS requests (the XDomainRequest
object),
has limitations.
In particular, requests must be targeted to the same scheme as the hosting page. This means that if a page is at
http://example.com, your target URL must also begin with HTTP. Similarly, if your page is at https://example.com, then
your target URL must also begin with HTTPS. For this reason, if your requests are sent to the GitHub API (the default),
which are served via HTTPS, your page must use HTTPS too.
The team behind Github.js has created a whole organization, called GitHub Tools, dedicated to GitHub and its API. In the near future this repository could be moved under the GitHub Tools organization as well. In the meantime, we recommend you to take a look at other projects of the organization.
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"
});
You can use either:
See these pages for more info:
Creating an access token for command-line use
Enterprise Github instances may be specified using the apiUrl
option:
var github = new Github({
apiUrl: "https://serverName/api/v3",
...
});
var repo = github.getRepo(username, reponame);
Show repository information
repo.show(function(err, repo) {});
Delete a repository
repo.deleteRepo(function(err, res) {});
Get contents at a particular path in a particular branch.
repo.contents(branch, "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) {});
List forks.
repo.listForks(function(err, forks) {});
Create new branch for repo. You can omit oldBranchName to default to "master".
repo.branch(oldBranchName, newBranchName, function(err) {});
List Pull Requests.
var state = 'open'; //or 'closed', or 'all'
repo.listPulls(state, function(err, pullRequests) {});
Get details of a Pull Request.
var pullRequestID = 123;
repo.getPull(pullRequestID, function(err, pullRequestInfo) {});
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) {});
Get list of statuses for a particular commit.
repo.getStatuses(sha, function(err, statuses) {});
Store content at a certain path. If the file specified in the path exists, the content is updated. If the file doesn't exist, it's created on the fly. You can also provide an optional object literal, (options
in the example below) containing information about the author and the committer.
var options = {
author: {name: 'Author Name', email: 'author@example.com'},
committer: {name: 'Committer Name', email: 'committer@example.com'},
encode: true // Whether to base64 encode the file. (default: true)
}
repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', options, 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) {});
Get information about a particular commit.
repo.getCommit('master', sha, function(err, commit) {});
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) {});
Get contributors list with additions, deletions, and commit counts.
repo.contributors(function(err, data) {});
Check if a repository is starred.
repo.isStarred(owner, repository, function(err) {});
Star a repository.
repo.star(owner, repository, function(err) {});
Unstar a repository.
repo.unstar(owner, repository, function(err) {});
var user = github.getUser();
List repositories of the authenticated user, including private repositories and repositories in which the user is a collaborator and not an owner.
user.repos(options, function(err, repos) {});
List organizations the authenticated user belongs to.
user.orgs(function(err, orgs) {});
List authenticated user's gists.
user.gists(function(err, gists) {});
List unread notifications for the authenticated user.
user.notifications(options, function(err, notifications) {});
Show user information for a particular username. Also works for organizations. Pass in a falsy value (null, '', etc) for 'username' to retrieve user information for the currently authorized user.
user.show(username, function(err, user) {});
List public repositories for a particular user.
user.userRepos(username, function(err, repos) {});
List starred repositories for a particular user.
user.userStarred(username, function(err, repos) {});
Create a new repo for the authenticated user
user.createRepo({"name": "test"}, function(err, res) {});
Repo description, homepage, private/public can also be set. For a full list of options see the docs here
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) {});
var gist = github.getGist(3165654);
Read the contents of a Gist.
gist.read(function(err, gist) {
});
Updating the contents of a Gist. 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) {
});
var issues = github.getIssues(username, reponame);
To read all the issues of a given repository
issues.list(options, function(err, issues) {});
To comment in a issue
issues.comment(issue, comment,function(err, comment) {});
var search = github.getSearch(query);
Suppose you want to search for popular Tetris repositories written in Assembly. Your query might look like this:
var search = github.getSearch("tetris+language:assembly&sort=stars&order=desc");
search.repositories(options, function (err, repositories) {});
Suppose you want to find the definition of the addClass function inside jQuery. Your query would look something like this:
var search = github.getSearch("addClass+in:file+language:js+repo:jquery/jquery");
search.code(options, function (err, codes) {});
Let’s say you want to find the oldest unresolved Python bugs on Windows. Your query might look something like this:
var search = github.getSearch("windows+label:bug+language:python+state:open&sort=created&order=asc");
search.issues(options, function (err, issues) {});
Imagine you’re looking for a list of popular users. You might try out this query:
var search = github.getSearch("tom+repos:%3E42+followers:%3E1000");
search.users(options, function (err, users) {});
Here, we’re looking at users with the name Tom. We’re only interested in those with more than 42 repositories, and only if they have over 1,000 followers.
Create and delete repositories Repos - getCommit
Paging (introduced at tail end of 0.8.X, note: different callbacks for success & errors now)
Fixes and tweaks, simpler auth, CI tests, node.js support, Raw+JSON, UTF8, plus: Users - follow, unfollow, get info, notifications Gists - create Issues - get Repos - createRepo, deleteRepo, createBranch, star, unstar, isStarred, getCommits, listTags, listPulls, getPull, compare Hooks - listHooks, getHook, createHook, editHook, deleteHook
Switched to a native request
implementation (thanks @mattpass). Adds support for GitHub gists, forks and pull requests.
Adds support for organizations and fixes an encoding issue.
Smart caching of latest commit sha.
Added support for OAuth.
Support for Moving and removing files.
Consider commit messages.
Initial version.
FAQs
A higher-level wrapper around the Github API.
The npm package github-api receives a total of 16,681 weekly downloads. As such, github-api popularity was classified as popular.
We found that github-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.