Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ To get branches from a user repo rather than a project repo, use user's slug as
client.branches.get('~userslug', repoKey); // Promise
```

### tags

Get all tags for a repo.

```
client.tags.get(projectKey, repoKey); // Promise
```

To get tags from a user repo rather than a project repo, use user's slug as the project key, prepended by '~'.

```
client.tags.get('~userslug', repoKey); // Promise
```

### pull requests

Get all pull requests for a repo.
Expand Down Expand Up @@ -191,3 +205,4 @@ client.users.getUser(userSlug); // Promise
- /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests [GET]
- /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks [GET]
- /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/enabled [PUT]
- /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags [GET]
9 changes: 9 additions & 0 deletions lib/api/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = function (client) {
return {
get: function (projectKey, repoKey, options) {
return client.getCollection('projects/' + projectKey + '/repos/' + repoKey + '/tags', options);
}
};
};
1 change: 1 addition & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var Client = function (baseUrl, auth) {
this.projects = require('./api/projects')(this);
this.repos = require('./api/repos')(this);
this.branches = require('./api/branches')(this);
this.tags = require('./api/tags')(this);
this.prs = require('./api/prs')(this);
this.users = require('./api/users')(this);
this.hooks = require('./api/hooks')(this);
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require('./prs/get.spec');
require('./hooks/get.spec');
require('./hooks/post.spec');
require('./branches/get.spec');
require('./tags/get.spec');
require('./users/get.spec');
require('./settings/get.spec');
45 changes: 45 additions & 0 deletions test/mocks/tags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"size": 5,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": "refs/tags/release-0.1.0",
"displayId": "release-0.1.0",
"type": "TAG",
"latestCommit": "abc",
"latestChangeset": "def",
"hash": "abc"
},
{
"id": "refs/tags/release-0.1.1",
"displayId": "release-0.1.1",
"type": "TAG",
"latestCommit": "abc",
"latestChangeset": "def",
"hash": "abc"
},{
"id": "refs/tags/release-0.1.2",
"displayId": "release-0.1.2",
"type": "TAG",
"latestCommit": "abc",
"latestChangeset": "def",
"hash": "abc"
},{
"id": "refs/tags/release-0.2.0",
"displayId": "release-0.2.0",
"type": "TAG",
"latestCommit": "abc",
"latestChangeset": "def",
"hash": "abc"
},{
"id": "refs/tags/release-0.2.1",
"displayId": "release-0.2.1",
"type": "TAG",
"latestCommit": "abc",
"latestChangeset": "def",
"hash": "abc"
}
],
"start": 0
}
35 changes: 35 additions & 0 deletions test/tags/get.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var assert = require('assert');
var sinon = require('sinon');
var BitbucketClient = require('../../index.js').Client;
var request = require('request-promise');
var Promise = require('bluebird');

describe('Tags', function () {
var requestGet, bitbucketClient;
var oauth = require('../mocks/oauth');

beforeEach(function () {
bitbucketClient = new BitbucketClient('http://localhost/', oauth);
requestGet = sinon.stub(request, 'get');
});

afterEach(function () {
request.get.restore();
});

it('should get list of tags by project for a repo', function (done) {
// Mock the HTTP Client get.
var expected = require('../mocks/tags.json');
requestGet.returns(Promise.resolve(expected));

// Test repos.get API.
bitbucketClient.tags.get('PRJ', 'my-repo')
.then(function (tags) {
assert.equal(tags.size, 5);
assert.deepEqual(tags.values[ 0 ], expected.values[ 0 ]);
assert.equal(requestGet.getCall(0).args[ 0 ].uri, 'http://localhost/projects/PRJ/repos/my-repo/tags?limit=1000');

done();
});
});
});