Get meta data for repositories associated with a user.
var repos = require( '@stdlib/_tools/github/user-repos' );Gets meta data for repositories associated with a user.
var opts = {
'username': 'kgryte'
};
repos( opts, clbk );
function clbk( error, results, info ) {
// Check for rate limit information...
if ( info ) {
console.error( 'Limit: %d', info.limit );
console.error( 'Remaining: %d', info.remaining );
console.error( 'Reset: %s', (new Date( info.reset*1000 )).toISOString() );
}
if ( error ) {
throw new Error( error.message );
}
console.log( JSON.stringify( results ) );
// => <repo_data>
}The function accepts the following options:
- token: GitHub access token.
- username: GitHub username.
- type: repository type. Can be one of
all,owner,member,public, orprivate. Thepublicandprivateoptions are only applicable if the function is provided atokenand nousername. - sort: method used to sort meta data. Can be one of
full_name,created,pushed, orupdated. - direction: sort direction; either
ascordesc. - visibility: repository visibility. Can be one of
all,public, orprivate. Applicable if provided atokenand nousername. Ignored iftypeoption is present. - affiliation: repository affiliation. A comma-separated list of values, which may include:
owner,collaborator,organization_member. Applicable if provided atokenand nousername. Ignored iftypeoption is present. - useragent: user agent
string.
To authenticate with GitHub, set the token option.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
repos( opts, clbk );To specify a user agent, set the useragent option.
var opts = {
'username': 'kgryte',
'useragent': 'hello-github!'
};
repos( opts, clbk );To return repositories of a particular type, set the type option.
var opts = {
'username': 'kgryte',
'type': 'owner'
};
repos( opts, clbk );To return repositories of a particular visibility, set the visibility option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'visibility': 'private'
};
repos( opts, clbk );To return repositories of a particular affiliation, set the affiliation option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'affiliation': 'collaborator,organization_member'
};
repos( opts, clbk );Creates a reusable function.
var opts = {
'username': 'kgryte',
'token': 'tkjorjk34ek3nj4!'
};
var get = repos.factory( opts, clbk );
get();
get();
get();
// ...The factory method accepts the same options as repos().
-
Either a
usernameor atokenor both must be provided. If provided atoken, but not ausername, thefunctionfetches repositories associated with the authenticated user. -
If not provided a
token, thefunctioncan only return public repository meta data. -
Rate limit information includes the following:
- limit: maximum number of requests a consumer is permitted to make per hour.
- remaining: number of remaining requests.
- reset: time at which the current rate limit window resets in UTC seconds.
var repos = require( '@stdlib/_tools/github/user-repos' );
var opts = {
'username': 'kgryte',
'useragent': 'beep-boop-bop'
};
repos( opts, clbk );
function clbk( error, results, info ) {
if ( info ) {
console.error( info );
}
if ( error ) {
throw new Error( error.message );
}
console.log( results );
}Usage: ghuserrepos [options]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--token token GitHub access token.
--username username GitHub username.
-ua, --useragent ua User agent.
--visibility visibility Repository visibility: public, private, all.
--affiliation affiliation Repository affiliation.
--type type Repository type: forks, public, private, etc.
--sort sort Sort method: full_name, created, pushed, etc.
--direction dir Sort direction: asc, desc.- In addition to the
tokenoption, the token may also be specified by aGITHUB_TOKENenvironment variable. The command-line option always takes precedence. - Request resources are written to
stdout. - Rate limit information is written to
stderr.
Setting the access token using the command-line option:
$ DEBUG=* ghuserrepos --token <token> --username kgryte
# => '[{...},{...},...]'Setting the access token using an environment variable:
$ DEBUG=* GITHUB_TOKEN=<token> ghuserrepos --username kgryte
# => '[{...},{...},...]'