Create a GitHub repository.
var createRepo = require( '@stdlib/_tools/github/create-repo' );
Creates a GitHub repository.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
createRepo( 'gamma', opts, clbk );
function clbk( error, repo, 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( repo ) );
// => <repo_data>
}
The function
accepts the following options
:
- token: GitHub access token (required).
- useragent: user agent
string
. - org: organization name. If no organization is specified, the repository is created as a personal repository for the authenticated user.
- desc: repository description. Default:
""
. - homepage: project homepage. Default:
""
. - team: team
id
. Thisoption
is only applicable when creating organization repositories. - gitignore:
.gitignore
template name. - license:
LICENSE
template name. - private:
boolean
indicating whether to create a private repository. Default:false
. - issues:
boolean
indicating whether to enable issues. Default:true
. - projects:
boolean
indicating whether to enable project boards. Default:true
. - wiki:
boolean
indicating whether to enable a wiki. Default:true
. - downloads:
boolean
indicating whether to enable downloads. Default:true
. - init:
boolean
indicating whether to initialize the repository with an emptyREADME
. Default:false
. - allowSquashMerge:
boolean
indicating whether to allow squash-merging.Default:true
. - allowMergeCommit:
boolean
indicating whether to allow merging pull requests with a merge commit. Default:true
. - allowRebaseMerge:
boolean
indicating whether to allow rebase-merging pull requests. Default:true
.
To authenticate with GitHub, set the token
option.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
createRepo( 'erf', opts, clbk );
To specify a user agent, set the useragent
option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'useragent': 'hello-github!'
};
createRepo( 'erfinv', opts, clbk );
By default, the function
creates a repository for the authenticated user. To create a repository in an organization the authenticated user is a member of, set the org
option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'org': 'math-io'
};
createRepo( 'betaln', opts, clbk );
Creates a reusable function
.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'org': 'math-io',
'private': false,
'issues': true,
'wiki': true,
'downloads': true,
'init': false
};
var create = createRepo.factory( opts, clbk );
create( 'beep' );
create( 'boop' );
create( 'bop' );
// ...
The factory method accepts the same options
as createRepo()
.
- 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 createRepo = require( '@stdlib/_tools/github/create-repo' );
var opts = {
'token': '<your_token_goes_here>',
'useragent': 'beep-boop-bop'
};
createRepo( 'beep', opts, clbk );
function clbk( error, repo, info ) {
if ( info ) {
console.error( info );
}
if ( error ) {
if ( error instanceof Error ) {
throw error;
}
console.error( error.message );
} else {
console.log( repo );
}
}
Note: in order to run the example, you will need to obtain an access token and modify the token
option accordingly.
Usage: ghcreaterepo [options] name
Options:
-h, --help Print this message.
-V, --version Print the package version.
--token token GitHub access token.
-ua, --useragent ua User agent.
--org organization GitHub organization.
--desc desc Repository description.
--homepage url Project homepage.
--private Set the repository as private.
--no-issues Disable issues.
--no-projects Disable repository project boards.
--no-wiki Disable repository wiki.
--no-downloads Disable repository downloads.
--no-squash-merge Disable squash-merging.
--no-merge-commit Disable merging pull requests with a merge commit.
--no-rebase-merge Disable rebase-merging pull requests.
--team id Team id (organizations).
--init Auto-initialize a repository with an empty README.
--gitignore template .gitignore template.
--license template License template.
- In addition to the
token
option, the token may also be specified by aGITHUB_TOKEN
environment variable. The command-line option always takes precedence. - Repository information is written to
stdout
. - Rate limit information is written to
stderr
.
Setting the access token using the command-line option:
$ DEBUG=* ghcreaterepo --token <token> beep
# => '{...}'
Setting the access token using an environment variable:
$ DEBUG=* GITHUB_TOKEN=<token> ghcreaterepo beep
# => '{...}'