Open konklone opened 9 years ago
#!/usr/bin/env node
'use strict';
var star = '😜'
, tagged = '👾'
var github = require( 'github' )
, g = new github( {
version : '3.0.0',
debug : false,
protocol : 'https',
timeout : 5000,
headers : {
'user-agent': 'jane-prefers-the-shell-over-the-webz-thx'
}
} );
if (process.env.GH_TOKEN) { // {{{
g.authenticate( {
type : 'oauth',
token : process.env.GH_TOKEN
} )
}
else if (process.env.GH_SECRET) {
g.authenticate( {
type : 'oauth',
key : process.env.GH_KEY,
secret : process.env.GH_SECRET
} )
} // }}}
g.repos.getAll( { type: 'all' }, function (e,m) { console.log( e ? e : m ) } );
Gives us something like:
[ { id: 26825166,
name: 'deep-grep',
full_name: 'janearc/deep-grep',
owner:
{ login: 'janearc',
id: 777319,
avatar_url: 'https://avatars.githubusercontent.com/u/777319?v=3',
gravatar_id: '',
url: 'https://api.github.com/users/janearc',
html_url: 'https://github.com/janearc',
followers_url: 'https://api.github.com/users/janearc/followers',
following_url: 'https://api.github.com/users/janearc/following{/other_user}',
gists_url: 'https://api.github.com/users/janearc/gists{/gist_id}',
starred_url: 'https://api.github.com/users/janearc/starred{/owner}{/repo}',
subscriptions_url: 'https://api.github.com/users/janearc/subscriptions',
organizations_url: 'https://api.github.com/users/janearc/orgs',
repos_url: 'https://api.github.com/users/janearc/repos',
events_url: 'https://api.github.com/users/janearc/events{/privacy}',
received_events_url: 'https://api.github.com/users/janearc/received_events',
type: 'User',
site_admin: false },
private: false,
html_url: 'https://github.com/janearc/deep-grep',
description: 'Too many haystacks, not enough needles',
fork: false,
url: 'https://api.github.com/repos/janearc/deep-grep',
forks_url: 'https://api.github.com/repos/janearc/deep-grep/forks',
keys_url: 'https://api.github.com/repos/janearc/deep-grep/keys{/key_id}',
collaborators_url: 'https://api.github.com/repos/janearc/deep-grep/collaborators{/collaborator}',
teams_url: 'https://api.github.com/repos/janearc/deep-grep/teams',
hooks_url: 'https://api.github.com/repos/janearc/deep-grep/hooks',
issue_events_url: 'https://api.github.com/repos/janearc/deep-grep/issues/events{/number}',
events_url: 'https://api.github.com/repos/janearc/deep-grep/events',
assignees_url: 'https://api.github.com/repos/janearc/deep-grep/assignees{/user}',
branches_url: 'https://api.github.com/repos/janearc/deep-grep/branches{/branch}',
tags_url: 'https://api.github.com/repos/janearc/deep-grep/tags',
blobs_url: 'https://api.github.com/repos/janearc/deep-grep/git/blobs{/sha}',
git_tags_url: 'https://api.github.com/repos/janearc/deep-grep/git/tags{/sha}',
git_refs_url: 'https://api.github.com/repos/janearc/deep-grep/git/refs{/sha}',
trees_url: 'https://api.github.com/repos/janearc/deep-grep/git/trees{/sha}',
statuses_url: 'https://api.github.com/repos/janearc/deep-grep/statuses/{sha}',
languages_url: 'https://api.github.com/repos/janearc/deep-grep/languages',
stargazers_url: 'https://api.github.com/repos/janearc/deep-grep/stargazers',
contributors_url: 'https://api.github.com/repos/janearc/deep-grep/contributors',
subscribers_url: 'https://api.github.com/repos/janearc/deep-grep/subscribers',
subscription_url: 'https://api.github.com/repos/janearc/deep-grep/subscription',
commits_url: 'https://api.github.com/repos/janearc/deep-grep/commits{/sha}',
git_commits_url: 'https://api.github.com/repos/janearc/deep-grep/git/commits{/sha}',
comments_url: 'https://api.github.com/repos/janearc/deep-grep/comments{/number}',
issue_comment_url: 'https://api.github.com/repos/janearc/deep-grep/issues/comments/{number}',
contents_url: 'https://api.github.com/repos/janearc/deep-grep/contents/{+path}',
compare_url: 'https://api.github.com/repos/janearc/deep-grep/compare/{base}...{head}',
merges_url: 'https://api.github.com/repos/janearc/deep-grep/merges',
archive_url: 'https://api.github.com/repos/janearc/deep-grep/{archive_format}{/ref}',
downloads_url: 'https://api.github.com/repos/janearc/deep-grep/downloads',
issues_url: 'https://api.github.com/repos/janearc/deep-grep/issues{/number}',
pulls_url: 'https://api.github.com/repos/janearc/deep-grep/pulls{/number}',
milestones_url: 'https://api.github.com/repos/janearc/deep-grep/milestones{/number}',
notifications_url: 'https://api.github.com/repos/janearc/deep-grep/notifications{?since,all,participating}',
labels_url: 'https://api.github.com/repos/janearc/deep-grep/labels{/name}',
releases_url: 'https://api.github.com/repos/janearc/deep-grep/releases{/id}',
created_at: '2014-11-18T19:05:23Z',
updated_at: '2014-12-25T10:41:44Z',
pushed_at: '2014-12-25T10:41:43Z',
git_url: 'git://github.com/janearc/deep-grep.git',
ssh_url: 'git@github.com:janearc/deep-grep.git',
clone_url: 'https://github.com/janearc/deep-grep.git',
svn_url: 'https://github.com/janearc/deep-grep',
homepage: null,
size: 396,
stargazers_count: 0,
watchers_count: 0,
language: 'JavaScript',
has_issues: true,
has_downloads: true,
has_wiki: true,
has_pages: false,
forks_count: 0,
mirror_url: null,
open_issues_count: 2,
forks: 0,
open_issues: 2,
watchers: 0,
default_branch: 'master',
permissions: { admin: true, push: true, pull: true } },
... ]
is that what you're looking for?
(also it's pretty annoying that the github
api above does not conform exactly to the GitHub API spec (listYourRepositories
vs getAll
))
I think so, yeah. It should fail if the GH_TOKEN (or GH_KEY + GH_SECRET) is wrong, and not be executed if credentials aren't provided.
Yeah, that was just a chop-things-up-and-see-if-its-doable-quickly. The "real thing" would be substantially more put-together. There's an issue to bring over that code that I haven't quite gotten to; I'm starting to think that to clean up a lot of this and simplify the codebase that shell-pluggable might actually be justified. It will also increase the ease of making unit tests because it makes it easier to mock everything.
Also, you could work with the code given :)
Also, you could work with the code given :)
I certainly could! I was opening the issue to get it out of my head as I was thinking it -- not to abstain from all responsibility. ;)
Since app token based auth (
$GH_TOKEN
) is always associated with a user, not an organization, then I think you should always be able to check the Your Repositories endpoint, at/user/repos
.