Skip to content

Commit

Permalink
Merge pull request #22 from dragouf/development
Browse files Browse the repository at this point in the history
Add build status in PR list page
  • Loading branch information
dragouf authored Nov 22, 2016
2 parents f5d3dbf + 20eb7dd commit fecd6aa
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 48 deletions.
215 changes: 169 additions & 46 deletions extension/chrome/src/js/stash_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -1542,52 +1542,11 @@
}
});

define('bitbucket-plugin/pullrequest-list-page', [
'aui',
'aui/flag',
'jquery',
'lodash',
'bitbucket/util/events',
'bitbucket/util/server',
'bitbucket/util/state',
'bitbucket/util/navbuilder',
'bitbucket/internal/feature/pull-request/pull-request-table',
'bitbucket/internal/widget/searchable-multi-selector',
'bitbucket/internal/feature/user/user-multi-selector',
'bitbucket/internal/widget/avatar-list',
'bitbucket/internal/feature/repository/branch-selector',
'bitbucket/internal/model/revision-reference'
], function (
AJS,
auiFlag,
jQuery,
_,
events,
ajax,
pageState,
nav,
PullRequestsTable,
SearchableMultiSelector,
UserMultiSelector,
avatarList,
BranchSelector,
revisionReference
) {
define('bitbucket-plugin/pullrequest-list-modifier', [
'bitbucket/internal/feature/pull-request/pull-request-table'
], function(PullRequestsTable) {
'use strict';
//////////////////////////////////////////////////// Add filter to Pull Request list
// utilities
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function addPrFilters() {
if(jQuery('#pull-requests-content').length === 0) {
return;
}
jQuery('.spinner').show();
function redefinePullRequestTable() {
//redefined filter builder to include new parameters
PullRequestsTable.prototype.buildUrl = function (start, limit) {
var self = this;
Expand Down Expand Up @@ -1665,6 +1624,156 @@
return builder.build();
};

var originalRowHandler = PullRequestsTable.prototype.handleNewRows
PullRequestsTable.prototype.handleNewRows = function (data, attachmentMethod) {
var self = this;
originalRowHandler.call(self, data, attachmentMethod);
var commitList = data.values.map(function(pr) {
return { commit: pr.fromRef.latestCommit, prId: pr.id }
});

getPRBuildStatus(commitList).done(function(buildDetails){
// add build column
if(self.$table.find('th.build-status-pr-list-col').length == 0) {
var $buildCol = jQuery('<th>', {
class: "build-status-pr-list-col",
title: 'Builds',
scope: 'col',
style: "display: table-cell;",
text: 'Builds'
});
self.$table.find('tr:first').append($buildCol);
}

var rows = self.$table.find('tr.pull-request-row');
rows.each(function(_index, row){
var $row = jQuery(row);
if($row.find('.build-status-pr-list-col-value').length == 0) {
var $buildCell = jQuery('<td>', { class: "build-status-pr-list-col-value" });
$buildCell.data('pullrequestid', $row.data('pullrequestid'));
$row.append($buildCell);
}
});

// add data to build cell
var rows = self.$table.find('tr.pull-request-row');
buildDetails.forEach(function(buildStatus) {
// find row and add build status
var cells = jQuery('td.build-status-pr-list-col-value');
var cell = cells.filter(function(_, td) { return jQuery(td).data('pullrequestid') == buildStatus.prId });
if(cell) {
var $buildInfoLink = jQuery('<a>', {
href:"#",
class:"aui-icon aui-icon-small build-icon",
'data-commit-id': buildStatus.commit
});

var appendIcon = false;
if(buildStatus.inProgress) {
$buildInfoLink.data('data-build-status', 'INPROGRESS');
$buildInfoLink.attr('title', buildStatus.inProgress + ' builds in progress');
$buildInfoLink.addClass('aui-iconfont-time');
$buildInfoLink.addClass('inprogress-build-icon');
appendIcon = true;
} else if(buildStatus.failed) {
$buildInfoLink.data('data-build-status', 'FAILED');
$buildInfoLink.attr('title', buildStatus.failed + ' builds failed');
$buildInfoLink.addClass('aui-iconfont-error');
$buildInfoLink.addClass('failed-build-icon');
appendIcon = true;
} else if(buildStatus.successful > 0) {
$buildInfoLink.data('data-build-status', 'SUCCESSFUL');
$buildInfoLink.attr('title', buildStatus.successful + ' builds passed');
$buildInfoLink.addClass('aui-iconfont-approve');
$buildInfoLink.addClass('successful-build-icon');
appendIcon = true;
}

if(appendIcon) {
cell.html($buildInfoLink);
$buildInfoLink.tooltip();
}
}
});
});
};
}

function getPRBuildStatus(commitList) {
var commitIds = commitList.map(function(pr) { return pr.commit });
return jQuery.ajax('/rest/build-status/latest/commits/stats', {
method: 'POST',
headers: {
Accept : "application/json, text/javascript, */*;",
"Content-Type": "application/json"
},
data: JSON.stringify(commitIds),
dataType: 'json'
})
.then(function(data) {
jQuery.each(data, function(commitId, info){
var commit = commitList.filter(function(cl) { return cl.commit === commitId });
if(commit.length > 0) {
jQuery.extend(commit[0], info);
}
});

return commitList;
});
}

return {
redefinePullRequestTable: redefinePullRequestTable
}
});

define('bitbucket-plugin/pullrequest-list-page', [
'aui',
'aui/flag',
'jquery',
'lodash',
'bitbucket/util/events',
'bitbucket/util/server',
'bitbucket/util/state',
'bitbucket/util/navbuilder',
'bitbucket/internal/feature/pull-request/pull-request-table',
'bitbucket/internal/widget/searchable-multi-selector',
'bitbucket/internal/feature/user/user-multi-selector',
'bitbucket/internal/widget/avatar-list',
'bitbucket/internal/feature/repository/branch-selector',
'bitbucket/internal/model/revision-reference'
], function (
AJS,
auiFlag,
jQuery,
_,
events,
ajax,
pageState,
nav,
PullRequestsTable,
SearchableMultiSelector,
UserMultiSelector,
avatarList,
BranchSelector,
revisionReference
) {
'use strict';
//////////////////////////////////////////////////// Add filter to Pull Request list
// utilities
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function addPrFilters() {
if(jQuery('#pull-requests-content').length === 0) {
return;
}
jQuery('.spinner').show();

function getPullRequestsUrlBuilder(state) {
return nav.rest().currentRepo().allPullRequests().withParams({ state: state });
}
Expand Down Expand Up @@ -1901,6 +2010,7 @@
var pageState;
var loadRequirement = jQuery.Deferred();
var loadAuiFlag = jQuery.Deferred();
var loadPrRequirement = jQuery.Deferred();

try {
WRM.require("wr!" + 'com.atlassian.auiplugin:aui-flag').then(function(d) {
Expand Down Expand Up @@ -1928,7 +2038,20 @@
}
}

jQuery.when(loadRequirement, loadAuiFlag).done(function(){
// improve PR page
try {
WRM.require("wr!" + 'com.atlassian.bitbucket.server.bitbucket-web:pull-request-table').then(function(){
require(['bitbucket-plugin/pullrequest-list-modifier'], function(prListModifier) {
prListModifier.redefinePullRequestTable();
loadPrRequirement.resolve();
});
});
}
catch (_) {
loadPrRequirement.resolve();
}

jQuery.when(loadRequirement, loadAuiFlag, loadPrRequirement).done(function(){
var user = pageState.getCurrentUser();
var project = pageState.getProject();
var repository = pageState.getRepository();
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Bitbucket Server Extension",
"description": "Allow to add group of reviewers for pull request in bitbucket server + other features",
"version": "2.2.8",
"version": "2.2.9",
"permissions": [
"storage",
"alarms",
Expand Down
4 changes: 4 additions & 0 deletions history
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.2.9
============================
- Display build status in PR list page

2.2.8
===================
- feature: add an option to disable check for new notification in background
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.8
2.2.9

0 comments on commit fecd6aa

Please sign in to comment.