Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Starred

Get a list of repositories a user has starred.

Usage

var starred = require( '@stdlib/_tools/github/starred' );

starred( opts, clbk )

Gets a list of repositories a user has starred.

var opts = {
    'username': 'kgryte'
};

starred( 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.
  • useragent: user agent string.
  • sort: sort method. Can be either 'created' or 'updated'. Default: 'created'.
  • direction: sort direction. Can be either 'asc' or 'desc'. Default: 'desc'.

To authenticate with GitHub, set the token option.

var opts = {
    'token': 'tkjorjk34ek3nj4!'
};

starred( opts, clbk );

To get a list of repositories a particular user has starred, set the username option.

var opts = {
    'username': 'kgryte'
};

starred( opts, clbk );

To specify a user agent, set the useragent option.

var opts = {
    'useragent': 'hello-github!'
};

starred( opts, clbk );

starred.factory( options, clbk )

Creates a reusable function.

var opts = {
    'username': 'kgryte',
    'token': 'tkjorjk34ek3nj4!'
};

var get = starred.factory( opts, clbk );

get();
get();
get();
// ...

The factory method accepts the same options as starred().

Notes

  • Either a username or a token or both must be provided. If provided a token, but not a username, the function fetches a list of repositories the authenticated user has starred on GitHub.

  • 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.

Examples

var starred = require( '@stdlib/_tools/github/starred' );

var opts = {
    'username': 'kgryte',
    'useragent': 'beep-boop-bop'
};

starred( opts, clbk );

function clbk( error, results, info ) {
    if ( info ) {
        console.error( info );
    }
    if ( error ) {
        if ( error instanceof Error ) {
            throw error;
        }
        console.error( error.message );
    } else {
        console.log( results );
    }
}

CLI

Usage

Usage: ghstarred [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.
       --sort method        Sort method: created, updated.
       --direction dir      Sort direction: asc, desc.

Notes

  • In addition to the token option, the token may also be specified by a GITHUB_TOKEN environment variable. The command-line option always takes precedence.
  • Request resources are written to stdout.
  • Rate limit information is written to stderr.

Examples

Setting the access token using the command-line option:

$ DEBUG=* ghstarred --token <token> --username kgryte
# => '[{...},{...},...]'

Setting the access token using an environment variable:

$ DEBUG=* GITHUB_TOKEN=<token> ghstarred --username kgryte
# => '[{...},{...},...]'