From 54d7927248b57ef52f13586a0accecc1c75fceeb Mon Sep 17 00:00:00 2001 From: "Laurent, David | ISDOD" Date: Mon, 27 Jun 2016 15:15:53 +0900 Subject: [PATCH 1/4] - add build status in PR list page --- extension/chrome/src/js/stash_page.js | 96 +++++++++++++++++++++++++++ extension/chrome/src/manifest.json | 2 +- history | 4 ++ version | 2 +- 4 files changed, 102 insertions(+), 2 deletions(-) diff --git a/extension/chrome/src/js/stash_page.js b/extension/chrome/src/js/stash_page.js index 63fe665..f8a8077 100644 --- a/extension/chrome/src/js/stash_page.js +++ b/extension/chrome/src/js/stash_page.js @@ -1665,6 +1665,79 @@ 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 } + }); + addPRBuildStatus(commitList).done(function(buildDetails){ + // add build column + if(self.$table.find('th.build-status-pr-list-col').length == 0) { + var $buildCol = jQuery('', { + class: "build-status-pr-list-col", + title: 'Builds', + scope: 'col', + style: "display: table-cell;", + text: 'Builds' + }); + pullRequestTable.$table.find('tr:first').append($buildCol); + } + + var rows = pullRequestTable.$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('', { class: "build-status-pr-list-col-value" }); + $buildCell.data('pullrequestid', $row.data('pullrequestid')); + $row.append($buildCell); + } + }); + + // add data to build cell + var rows = pullRequestTable.$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('', { + 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 getPullRequestsUrlBuilder(state) { return nav.rest().currentRepo().allPullRequests().withParams({ state: state }); } @@ -1889,6 +1962,29 @@ $approversInput.data('select2').blur(); } + function addPRBuildStatus(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 { addPrFilters: addPrFilters } diff --git a/extension/chrome/src/manifest.json b/extension/chrome/src/manifest.json index a400146..0c490d5 100644 --- a/extension/chrome/src/manifest.json +++ b/extension/chrome/src/manifest.json @@ -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", diff --git a/history b/history index abe97f8..34be995 100644 --- a/history +++ b/history @@ -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 diff --git a/version b/version index 23a63f5..a6333e4 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.2.8 +2.2.9 From 700ffa885d6c450f52532e90b248f77edeee9e5c Mon Sep 17 00:00:00 2001 From: "Laurent, David | ISDOD" Date: Tue, 28 Jun 2016 13:03:24 +0900 Subject: [PATCH 2/4] - fix typo --- extension/chrome/src/js/stash_page.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/chrome/src/js/stash_page.js b/extension/chrome/src/js/stash_page.js index f8a8077..7fd70f3 100644 --- a/extension/chrome/src/js/stash_page.js +++ b/extension/chrome/src/js/stash_page.js @@ -1682,10 +1682,10 @@ style: "display: table-cell;", text: 'Builds' }); - pullRequestTable.$table.find('tr:first').append($buildCol); + self.$table.find('tr:first').append($buildCol); } - var rows = pullRequestTable.$table.find('tr.pull-request-row'); + 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) { @@ -1696,7 +1696,7 @@ }); // add data to build cell - var rows = pullRequestTable.$table.find('tr.pull-request-row'); + 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'); From 21389e0d8c39da96cb62ddfc503fd5b5950dbf3c Mon Sep 17 00:00:00 2001 From: "Laurent, David | ISDOD" Date: Tue, 28 Jun 2016 13:15:51 +0900 Subject: [PATCH 3/4] - naming --- extension/chrome/src/js/stash_page.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extension/chrome/src/js/stash_page.js b/extension/chrome/src/js/stash_page.js index 7fd70f3..53359ea 100644 --- a/extension/chrome/src/js/stash_page.js +++ b/extension/chrome/src/js/stash_page.js @@ -1672,7 +1672,8 @@ var commitList = data.values.map(function(pr) { return { commit: pr.fromRef.latestCommit, prId: pr.id } }); - addPRBuildStatus(commitList).done(function(buildDetails){ + + getPRBuildStatus(commitList).done(function(buildDetails){ // add build column if(self.$table.find('th.build-status-pr-list-col').length == 0) { var $buildCol = jQuery('', { @@ -1962,7 +1963,7 @@ $approversInput.data('select2').blur(); } - function addPRBuildStatus(commitList) { + function getPRBuildStatus(commitList) { var commitIds = commitList.map(function(pr) { return pr.commit }); return jQuery.ajax('/rest/build-status/latest/commits/stats', { method: 'POST', From 20eb7ddab7eab70568a942305e62d41120df405e Mon Sep 17 00:00:00 2001 From: "Laurent, David | ISDOD" Date: Tue, 28 Jun 2016 14:00:03 +0900 Subject: [PATCH 4/4] - add build status of pr inbox available everywhere --- extension/chrome/src/js/stash_page.js | 164 +++++++++++++++----------- 1 file changed, 95 insertions(+), 69 deletions(-) diff --git a/extension/chrome/src/js/stash_page.js b/extension/chrome/src/js/stash_page.js index 53359ea..ae6a93e 100644 --- a/extension/chrome/src/js/stash_page.js +++ b/extension/chrome/src/js/stash_page.js @@ -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; @@ -1738,6 +1697,82 @@ }); }); }; + } + + 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 }); @@ -1963,29 +1998,6 @@ $approversInput.data('select2').blur(); } - 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 { addPrFilters: addPrFilters } @@ -1998,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) { @@ -2025,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();