Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kicumkicum committed Jun 17, 2016
2 parents e8958db + ef4b688 commit f496f6d
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 145 deletions.
4 changes: 4 additions & 0 deletions .closure-linter.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--strict
--jsdoc
--disable=5,222
--max_line_length=120
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,md}]
charset = utf-8

# Indentation override for all JS under lib directory
[src/**.js]
indent_style = tab

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml,manifest.json}]
indent_style = space
indent_size = 2
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# v0.4.0 (18.06.2016)

## Feature
* [#38](https://github.com/kicumkicum/bond/issues/38)
Get branches from bitbucket api
* [#39](https://github.com/kicumkicum/bond/issues/39)
Show branches in redmine issue
* [#55](https://github.com/kicumkicum/bond/issues/55)
Show only opened branches in redmine issue

## Improvement
* [#50](https://github.com/kicumkicum/bond/issues/50)
Add configuration for editorconfig

# v0.3.0 (11.06.2016)

## Feature
Expand Down
4 changes: 3 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"config.js",
"/src/models/abstract.js",
"/src/models/bitbucket/links.js",
"/src/models/bitbucket/owner.js",
"/src/models/bitbucket/project.js",
"/src/models/bitbucket/repository.js",
"/src/models/bitbucket/pull-request.js",
"/src/models/bitbucket/branch.js",
Expand Down Expand Up @@ -37,5 +39,5 @@
"storage",
"tabs"
],
"version": "0.3.0"
"version": "0.4.0"
}
2 changes: 2 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<script src="config.js"></script>
<script src="/src/models/abstract.js"></script>
<script src="/src/models/bitbucket/links.js"></script>
<script src="/src/models/bitbucket/owner.js"></script>
<script src="/src/models/bitbucket/project.js"></script>
<script src="/src/models/bitbucket/repository.js"></script>
<script src="/src/models/bitbucket/pull-request.js"></script>
<script src="/src/models/bitbucket/branch.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bond",
"version": "0.3.0",
"version": "0.4.0",
"description": "Bond you redmine projects and bitbucket repo.",
"main": "config.js",
"directories": {
Expand Down
20 changes: 20 additions & 0 deletions src/api/abstract-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ api.AbstractApi.prototype.getAllElementsWithAttribute = function(attribute, opt_

return matchingElements;
};


/**
* @param {...string} var_args
* @return {string}
* @protected
*/
api.AbstractApi.prototype._createUrl = function(var_args) {
var url = Array.prototype.join.call(arguments, '/');
url = url.replace('//', '/');

while (url.indexOf('//') > -1) {
url = url.replace('//', '/');
}

url = url.replace('http:/', 'http://');
url = url.replace('https:/', 'https://');

return url;
};
123 changes: 50 additions & 73 deletions src/api/bitbucket-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ goog.require('models.bitbucket.Repository');
goog.require('utils.parser');



/**
* @constructor
* @extends {api.AbstractApi}
*/
api.Bitbucket = function() {
this._url = 'https://bitbucket.org/api/2.0/';
this._realUrl = 'https://bitbucket.org';
this._maxPageLength = 50;
this._cachedPulls = [];
};
goog.inherits(api.Bitbucket, api.AbstractApi);


/**
* @param {string} url
* @param {Object} headers
* @return {IThenable<Array<*>>}
*/
api.Bitbucket.prototype.cyclicalRequest = function(url, headers) {
api.Bitbucket.prototype.cyclicalRequest = function(url) {
var result = [];
var request = function(url) {
return this.request(url, headers)
return this._request(url)
.then(function(response) {
result = result.concat(response['values']);

Expand All @@ -45,81 +45,35 @@ api.Bitbucket.prototype.cyclicalRequest = function(url, headers) {

/**
* @param {string} owner
* @param {string} repo
* @param {string} repoName
* @return {IThenable.<Array.<models.bitbucket.Branch>>}
*/
api.Bitbucket.prototype.getBranches = function(owner, repo) {
var getBranches = function(tabId) {
chrome.tabs.executeScript(tabId, {file: "/src/injections/get-branches-from-page.js"}, function() {
if (chrome.extension.lastError) {
var message = 'There was an error injecting script : \n' + chrome.extension.lastError.message;
console.log('error', message);
api.Bitbucket.prototype.getBranches = function(owner, repoName) {
return this.getRepo(owner, repoName)
.then(function(repo) {
var url = repo.links.getHref('branches');

if (url) {
return this.cyclicalRequest(url);
} else {
return Promise.reject();
}
});
};

//todo http://stackoverflow.com/questions/11684454/getting-the-source-html-of-the-current-page-from-chrome-extension
var url = utils.parser.joinUrl(this._realUrl, owner, repo, 'branches');

//window.open(url);
//chrome.tabs.query({'url': url}, function(tabs) {
// getBranches(tabs[0].id);
//});

return this.getHTML(url)
.then(function(html) {
return utils.parser.getBranchesFromHTML(html);
})
.then(function(branchesNames) {
return branchesNames.map(function(branchName) {
var url = utils.parser.joinUrl(this._realUrl, owner, repo, 'branch', branchName);
return new models.bitbucket.Branch({
name: branchName,
links: {
html: {
href: url
}
}
});
}, this);
}.bind(this));
//chrome.cookies.getAll({domain: 'bitbucket.org'}, function(cookies) {
// console.log(cookies);
// for (var i = 0; i < cookies.length; i++) {
// var newCookie = {
// 'url': "http" + (cookies[i].secure ? "s" : "") + "://" + cookies[i].domain + cookies[i].path,
// 'name': cookies[i].name,
// 'value': cookies[i].value,
// 'domain': cookies[i].domain,
// 'path': cookies[i].path,
// 'secure': cookies[i].secure,
// 'httpOnly': cookies[i].httpOnly,
// 'expirationDate': cookies[i].expirationDate,
// 'storeId': cookies[i].storeId
// };
// chrome.cookies.set(newCookie);
// }
// return this.getHTML(url)
// .then(function(html) {
// console.log(html);
// return this.getAllElementsWithAttribute('data-branch-name', doc);
//}.bind(this));
//}.bind(this));


};


/**
* @param {string} owner
* @param {string} repo
* @return {IThenable.<models.bitbucket.PullRequest>}
*/
api.Bitbucket.prototype.getPullRequests = function(owner, repo) {
var url = this._url + 'repositories/' + owner + '/' + repo + '/pullrequests/?state=merged,open' +
'&pagelen=' + this._maxPageLength;
var httpHeader = {'Authorization': 'Basic ' + config.token};
var url = this._createUrl(
this._url, 'repositories', owner, repo, 'pullrequests/?state=merged,open&pagelen=' + this._maxPageLength);

var request = function(url) {
return this
.request(url, httpHeader)
._request(url)
.then(function(response) {
var responsePulls = response['values'].map(function(pull) {
return new models.bitbucket.PullRequest(pull);
Expand All @@ -129,7 +83,7 @@ api.Bitbucket.prototype.getPullRequests = function(owner, repo) {
responsePulls = responsePulls.filter(function(responsePull) {
return this._cachedPulls.every(function(pull) {
return pull.id !== responsePull.id;
})
});
}, this);

this._cachedPulls = this._cachedPulls.concat(responsePulls);
Expand All @@ -140,7 +94,7 @@ api.Bitbucket.prototype.getPullRequests = function(owner, repo) {
}.bind(this))
.then(function(url) {
if (url) {
return request(url, httpHeader);
return request(url);
} else {
return this._cachedPulls;
}
Expand All @@ -156,10 +110,8 @@ api.Bitbucket.prototype.getPullRequests = function(owner, repo) {
* @return {IThenable<Array>}
*/
api.Bitbucket.prototype.getRepositories = function(owner) {
var url = this._url + 'teams/' + owner + '/repositories';
var httpHeader = {'Authorization': 'Basic ' + config.token};

return this.cyclicalRequest(url, httpHeader)
var url = this._createUrl(this._url, 'teams', owner, 'repositories');
return this.cyclicalRequest(url)
.then(function(response) {
return response.map(function(repo) {
return new models.bitbucket.Repository(repo);
Expand All @@ -168,7 +120,32 @@ api.Bitbucket.prototype.getRepositories = function(owner) {
};


/**
* @param {string} owner
* @param {string} repo
* @return {IThenable<models.bitbucket.Repository>}
*/
api.Bitbucket.prototype.getRepo = function(owner, repo) {
var url = this._createUrl(this._url, 'repositories', owner, repo);
return this._request(url)
.then(function(data) {
return new models.bitbucket.Repository(data);
});
};


/**
* @param {string} url
* @return {IThenable<*>}
* @private
*/
api.Bitbucket.prototype._request = function(url) {
var httpHeader = {'Authorization': 'Basic ' + config.token};
return this.request(url, httpHeader);
};


/**
* @type {Array<models.bitbucket.PullRequest>}
*/
api.Bitbucket.prototype._cachedPulls = [];
api.Bitbucket.prototype._cachedPulls;
36 changes: 13 additions & 23 deletions src/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var Application = function() {
/**
* @param {number} ticket
* @param {string} redmineProjectId
* @return {IThenable<Application.TabData>}
* @protected
*/
Application.prototype._loadData = function(ticket, redmineProjectId) {
Expand All @@ -38,12 +39,14 @@ Application.prototype._loadData = function(ticket, redmineProjectId) {

return Promise.all([
this._services.syncer.getBitbucketPullRequests({ticket: ticket}, bitbucketInfo),
this._services.syncer.getBitbucketBranches(bitbucketInfo.owner, bitbucketInfo.repo)
])
this._services.syncer.getBitbucketBranches(bitbucketInfo.owner, bitbucketInfo.repo, ticket.toString())
]);
}.bind(this))
.then(function(result) {
this._data[ticket].pullrequests = result[0];
this._data[ticket].branches = result[1];
this._data[ticket].branches = result[1].filter(function(branch) {
return !branch.heads || branch.heads.length;
});

return this._data[ticket];
}.bind(this));
Expand Down Expand Up @@ -79,7 +82,7 @@ Application.prototype._onTabUpdate = function(tabId, changeInfo, tab) {
.getRedmineProjectId(url)
.then(this._loadData.bind(this, issue))
.then(function() {
this._injectCreateBranchButton(tabId, issue, (this._data[issue] || {}).bitbucketInfo);
this._injectCreateBranchButton(tabId, issue, (this._data[issue] || {}).bitbucketInfo, (this._data[issue] || {}).branches);
setTimeout(function() {
this._addPullRequestsList(tabId, url);
}.bind(this), 300);
Expand All @@ -100,13 +103,6 @@ Application.prototype._onTabUpdate = function(tabId, changeInfo, tab) {
* @protected
*/
Application.prototype._addPullRequestsList = function(tabId, url) {
chrome.tabs.executeScript(tabId, {file: '/src/injections/create-pull-request-list.js'}, function() {
if (chrome.extension.lastError) {
var message = 'There was an error injecting script : \n' + chrome.extension.lastError.message;
console.log(message);
}
});

var ticket = utils.parser.getTicket(url);
return this._injectPullRequestsToList(tabId, this._data[ticket] || {});
};
Expand Down Expand Up @@ -142,12 +138,12 @@ Application.prototype._injectPullRequestsToList = function(tabId, tabData) {
* @param {service.Syncer.BitbucketInfo} bitbucketInfo
* @private
*/
Application.prototype._injectCreateBranchButton = function(tabId, issue, bitbucketInfo) {
Application.prototype._injectCreateBranchButton = function(tabId, issue, bitbucketInfo, branches) {
chrome.tabs.executeScript(tabId, {
code: 'var issue = ' + issue + ', bitbucketInfo = ' + JSON.stringify(bitbucketInfo)
code: 'var issue = ' + issue + ', bitbucketInfo = ' + JSON.stringify(bitbucketInfo) + ', branches = ' + JSON.stringify(branches)
}, function() {
chrome.tabs.executeScript(tabId, {
file: '/src/injections/create-branch-button.js'
file: '/src/injections/create-branch-list.js'

}, function() {
if (chrome.extension.lastError) {
Expand Down Expand Up @@ -177,12 +173,6 @@ Application.prototype._highlightTicketNumber = function(tabId) {
};


/**
* @type {Object.<string, ?Application.TabData>}
*/
Application.prototype._tabs;


/**
* @type {{
* syncer: service.Syncer
Expand All @@ -200,16 +190,16 @@ Application.prototype._providers;


/**
* @type {Object.<string, service.Syncer.BitbucketInfo>}
* @type {Application.TabData}
*/
Application.prototype._data;


/**
* @typedef {{
* @typedef {Object.<string, {
* ticket: (string|undefined),
* branches: (Array.<string>|undefined),
* pullrequests: (Array.<string>|undefined)
* }}
* }>}
*/
Application.TabData;
Loading

0 comments on commit f496f6d

Please sign in to comment.