Socket
Socket
Sign inDemoInstall

bitbucket-api

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

lib/curl-transport.js

89

lib/bitbucket.js

@@ -0,71 +1,6 @@

"use strict";
var EventEmitter = require('events').EventEmitter;
var exec = require('child_process').exec;
var qs = require('querystring');
var connection = require('./curl-transport').connection;
function getParseError(err, stdout, stderr) {
err.outData = stdout;
err.errData = stderr;
return err;
}
function connection(credentials, raw) {
function run(command, cb) {
exec(command, function (error, stdout, stderr) {
try {
var response = {success: true};
if (raw) {
response.raw = stdout;
response.lines = stdout.split('\n');
return cb(error, response);
}
if (stdout.indexOf('Oops! An error occurred.') !== 0) {
response = {success: false, status: 500};
}
if (stdout.indexOf('Not Found') !== 0) {
response = {success: false, status: 404};
}
if (stdout.indexOf('HTTP/1.1 204 NO CONTENT') !== 0) {
response = JSON.parse(stdout);
}
cb(error, response);
} catch (e) {
console.log('=====================');
console.log(e);
console.log('=====================');
console.log(stdout);
console.log('=====================');
console.log(stderr);
console.log('=====================');
cb(e, null);
}
})
.on('error', function (err) {
cb(err, null);
});
}
return {
get: function(url, cb) {
var command = "curl --user " + credentials + " " + url;
run(command, cb);
},
post: function(url, data, cb) {
var command = "curl --user " + credentials + " " + url + " --data " + data;
run(command, cb);
},
put: function (url, data, cb) {
var command = "curl --request PUT --user " + credentials + " " + url + " --data " + data;
run(command, cb);
},
del: function (url, cb) {
var command = "curl --include --request DELETE --user " + credentials + " " + url;
run(command, cb);
}
};
};
function cacheResult(obj, prop, cb) {

@@ -116,3 +51,3 @@ return function (err, result) {

return this.provider.getUrl() + "/repositories/" + this.owner + "/" + this.slug;
}
};
}

@@ -131,9 +66,9 @@

return "https://" + this.root + "/" + this.version;
}
};
}
BitBucket.prototype.getRepository = function(repository, cb) {
if (!repository.slug) {return cb(new Error('Repository slug is required.'), null);}
if (!repository.owner) {return cb(new Error('Repository owner is required.'), null);}
if (!cb) {return cb(new Error('Callback is required.'), null);}
BitBucket.prototype.getRepository = function (repository, cb) {
if (!repository.slug) { return cb(new Error('Repository slug is required.'), null); }
if (!repository.owner) { return cb(new Error('Repository owner is required.'), null); }
if (!cb) { return cb(new Error('Callback is required.'), null); }
var self = this;

@@ -146,3 +81,3 @@ var url = self.getUrl() + "/repositories/" + repository.owner + "/" + repository.slug;

BitBucket.prototype.repositories = function(cb) {
BitBucket.prototype.repositories = function (cb) {
var self = this;

@@ -172,3 +107,3 @@ var url = self.getUrl() + "/user/repositories/";

};
}
};

@@ -237,3 +172,3 @@ Repository.prototype.issue = function (issueId) {

Repository.prototype.milestones = function() {
Repository.prototype.milestones = function () {
var self = this;

@@ -264,3 +199,3 @@ var url = self.getUrl() + "/issues/milestones/";

Repository.prototype.versions = function() {
Repository.prototype.versions = function () {
var self = this;

@@ -267,0 +202,0 @@ var url = self.getUrl() + "/issues/versions/";

@@ -5,3 +5,3 @@ {

"description": "A package to access the BitBucket Api.",
"version": "0.0.3",
"version": "0.0.4",
"repository": {

@@ -8,0 +8,0 @@ "url": "https://hgarcia@bitbucket.org/hgarcia/node-bitbucket-api.git"

## Intro
A very simple to use library to hook into the BitBucket api.
At the moment it covers issues and all related objects + getting a list of repositories and a single one.
At the moment it covers issues and all related objects as well as getting repository and sources information.
The Api is in flux and you should expect changes coming in the future.

@@ -26,8 +26,20 @@

All the tests at the moment are integration tests and will attempt to connect with BitBucket.
False errors may happen due to default timeout for running tests with mocha (2000 ms).
It should be fine in most scenarios.
If you want to run the tests with a 15 seconds timeout instead of the default of 2 seconds.
False errors may happen due to timeout scenarios but it should be fine in most cases. The test are run with a 15 secs timeout.
If you want to run the tests with a different timeout run then directly with mocha and the -t option, giving it the timeout in milliseconds.
mocha /tests -t 15000
## Changelog
#### 0.0.4
* Improve code structure and prepare to support multiple connection transports
* Improve API: removing {succes: false} on error situations and returning Errors in the callback
#### 0.0.3
* Added support for sources
## Api

@@ -37,3 +49,3 @@

Takes an object with a `username and a `password keys
Takes an object with a `username` and a `password` keys
Returns a BitBucket object

@@ -64,9 +76,9 @@

Takes a callback of the form `cb(err, result) result is an array of the repositories the user has access to.
Takes a callback of the form `cb(err, result)` result is an array of the repositories the user has access to.
getRepository(options, cb)
Takes an option parameter with the `owner and `slug keys for the repository to get. To get details for the repository of this module the owner will be `hgarcia and the slug will be `node-bitbucket-api.
Takes an option parameter with the `owner` and `slug` keys for the repository to get. To get details for the repository of this module the owner will be `hgarcia` and the slug will be `node-bitbucket-api`.
The call back takes the for of `cb(err, repo) where repo is a `Repository object.
The call back takes the for of `cb(err, repo)` where repo is a `Repository` object.

@@ -119,24 +131,24 @@ ### Repository

Returns an `Issues object
Returns an `Issues` object
issue(issueId)
Takes the `id of an issue and returns an `Issue object.
Takes the `id` of an issue and returns an `Issue` object.
milestones()
Returns a `Milestones object
Returns a `Milestones` object
versions()
Returns a `Versions object
Returns a `Versions` object
components()
Returns a `Components object
Returns a `Components` object
sources(path, revision)
Takes the path to a folder (defaults to "/") or file and optionally the revision or branch name (defaults to master). Returns a `Sources object.
If `path ends on "/" the API considers that you are looking for a directory instead of a file.
Takes the path to a folder (defaults to "/") or file and optionally the revision or branch name (defaults to master). Returns a `Sources` object.
If `path` ends on "/" the API considers that you are looking for a directory instead of a file.

@@ -152,3 +164,3 @@ ### Milestones, Versions, Components

Takes a string as the name for the new object and a callback;
The callback takes the form `cb(err, obj) where obj is a literal with the data for the newly created object with the id.
The callback takes the form `cb(err, obj)` where obj is a literal with the data for the newly created object with the id.

@@ -158,7 +170,7 @@ getById(id, cb)

Takes the id of the object to get and a callback.
The callback takes the form `cb(err, obj) where obj is a literal with the data for the requested object.
The callback takes the form `cb(err, obj)` where obj is a literal with the data for the requested object.
getAll(cb)
Takes a callback of the form `cb(err, results) where results is an array with all the objects of that type in the repository.
Takes a callback of the form `cb(err, results)` where results is an array with all the objects of that type in the repository.

@@ -168,7 +180,8 @@ update(id, name, cb)

Takes the id of the object, a string as the new name for the object and a callback.
The callback takes the form `cb(err, obj) where obj is a literal with the data for the modified object.
The callback takes the form `cb(err, obj)` where obj is a literal with the data for the modified object.
remove(id, cb)
Takes the id of the object to remove and a callback.
The callback takes the form `cb(err, result) where result contains a boolean `success key.
The callback takes the form `cb(err, result)` where result contains a boolean `success` key.

@@ -185,11 +198,9 @@ ### Issues

The callback takes the form `cb(err, obj) where obj is a literal with the data returned by the API.
The callback takes the form `cb(err, obj)` where obj is a literal with the data returned by the API.
raw(cb)
The callback takes the form `cb(err, obj) where contains a data and a lines properties. This only works for text files.
The callback takes the form `cb(err, obj)` where obj contains a data and a lines properties. This only works for text files.
obj.data //Contains a string with the file raw content
obj.lines //Contains an array with the string split by '\n' characters.
If there is an error the obj will contain `success:false and a `status key.

@@ -45,3 +45,2 @@ var should = require("should");

repo.sources('/').raw(function (err, result) {
result.success.should.be.ok;
result.lines.length.should.be.above(1);

@@ -48,0 +47,0 @@ result.raw.should.include('app');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc