bitbucket-rest

A package to access the BitBucket REST API.

This is nodejs module to use the functionalities of repository, deploy-keys, service hooks in bitbucket. Bitbucket's native REST API, both version 1 & version 2 are used for appropriate actions.

To install the most recent release from npm, run:

npm install bitbucket-rest

A simple example to create a bitbucket client.

  var bitbucket = require('bitbucket-rest');                                            
  var client = bitbucket.connectClient({username : 'user', password : 'pass'});
  
  client.getRepoDetails({owner:'owner_name', repo_slug : 'repo_slug'}, function(res){
     callback(res);
  });
  

To create a new repository.

  client.createRepo(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • name name of the repository.
  • description description for the repository.
  • is_private
  • forking_policy fork policy values - no_public_forks, allow_forks, no_forks
  • language
  • has_issues
  • has_wiki
  • scm

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get complete detail about the repository.

  client.getRepoDetails(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To update the details of the repository.

  client.updateRepoDetails(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • name name of the repository.
  • description description for the repository.
  • is_private
  • forking_policy fork policy values - no_public_forks, allow_forks, no_forks
  • language
  • scm

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To delete a repository.

  client.deleteRepo(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 204,
    data : undefined
  }

To fork a repository.

  client.forkRepo(repo, forkRepo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

Parameters of forkRepo:

  • name name of the repository - REQUIRED.
  • description description for the repository.
  • is_private
  • language
  • scm

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get list of forks of a repository.

  client.getRepoForks(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get branches of the repository.

  client.getRepoBranches(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get the main branch of a repository.

  client.getRepoMainBranch(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To add deployment keys to a repository.

  client.addRepoDeployKey(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • label label to represent the key
  • key RSA key generated by ssh keygen - REQUIRED

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get deployment keys of a repository.

  client.getRepoDeployKeys(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get the content of a deployment key of a repository.

  client.getRepoDeployKeyContent(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • pk key_id of the deployment-key - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To delete a deployment key of a repository.

  client.deleteRepoDeployKey(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • pk key_id of the deployment-key - REQUIRED.

This returns following object:

  { 
    status : 204,
    data : undefined
  }

To add a hook service to a repository.

  client.addRepoHook(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • type hook type ex.POST (case sensitive)
  • URL service url for which accepts post hook.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get the list of hook services of a repository.

  client.getRepoHooks(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To get the content of a single hook service of a repository.

  client.getRepoHookContent(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • id hook service id - REQUIRED.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To update a hook service of a repository.

  client.updateRepoHook(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • id hook service id - REQUIRED.
  • URL service url for which accepts post hook.

This returns following object:

  { 
    status : 200,
    data : [object]
  }

To delete a hook service of a repository.

  client.deleteRepoHook(repo, callback)

Parameters of repo:

  • owner owner of the repository - REQUIRED.
  • repo_slug slug of the repository - REQUIRED.
  • id hook service id - REQUIRED.

This returns following object:

  { 
    status : 204,
    data : undefined
  }