From 5ae870f267e03b8fc5ee5c55160d3ad1f695cf1e Mon Sep 17 00:00:00 2001 From: Callum White Date: Mon, 27 Nov 2017 11:54:46 +0000 Subject: [PATCH] work on browserstack info, removed column for law engine --- src/app/pages/dashboard/chartJs1DCtrl.js | 98 ++++++++++++++ src/app/pages/dashboard/chartJs3DCtrl.js | 17 ++- src/app/pages/dashboard/dashboard.html | 59 +++++++-- src/browserstack_php.php | 160 +++++++++++++++++++++++ src/sass/app/_dashboard.scss | 4 + 5 files changed, 322 insertions(+), 16 deletions(-) create mode 100644 src/browserstack_php.php diff --git a/src/app/pages/dashboard/chartJs1DCtrl.js b/src/app/pages/dashboard/chartJs1DCtrl.js index ed2a7f3..a159e4e 100644 --- a/src/app/pages/dashboard/chartJs1DCtrl.js +++ b/src/app/pages/dashboard/chartJs1DCtrl.js @@ -95,8 +95,106 @@ }); } + function getBrowserStackData() { + var queryParams1 = [ + 'type=builds' + ]; + + var queryParams2 = [ + 'type=buildSessions' + ]; + + $http({ + method: 'GET', + url: 'http://localhost:3001/browserstack_php.php' + '?' + queryParams1.join('&') + }).then(function (data) { + queryParams2.push('buildId=' + data.data.results[0].automation_build.hashed_id); + + $http({ + method: 'GET', + url: 'http://localhost:3001/browserstack_php.php' + '?' + queryParams2.join('&') + }).then(function (response) { + $scope.behatResults = { + failed: 0, + passed: 0, + windows: { + chrome: { + name: 'Chrome', + passed: 0, + failed: 0, + percentage: 0 + }, + firefox: { + name: 'Firefox', + passed: 0, + failed: 0, + percentage: 0 + }, + ie: { + name: 'Internet Explorer', + passed: 0, + failed: 0, + percentage: 0 + }, + edge: { + name: 'Microsoft Edge', + passed: 0, + failed: 0, + percentage: 0 + } + }, + mac: { + chrome: { + name: 'Chrome', + passed: 0, + failed: 0, + percentage: 0 + }, + firefox: { + name: 'Firefox', + passed: 0, + failed: 0, + percentage: 0 + }, + safari: { + name: 'Safari', + passed: 0, + failed: 0, + percentage: 0 + } + } + }; + function calcPercentage(browser) { + $scope.behatResults.windows[browser].percentage = (($scope.behatResults.windows[browser].passed / ($scope.behatResults.windows[browser].passed + $scope.behatResults.windows[browser].failed)) * 100).toFixed(2); + } + + function browserTestLog(test, status) { + if (test.os === 'Windows') { + $scope.behatResults.windows[test.browser][status] += 1; + + calcPercentage(test.browser); + } + } + + response.data.results.forEach(function (test) { + var session = test.automation_session; + + if ((session.status === 'done' && session.reason === 'UI_STOPPED') || session.status === 'passed') { + $scope.behatResults.passed += 1; + browserTestLog(session, 'passed') + } else if (session.status !== 'running') { + $scope.behatResults.failed += 1; + browserTestLog(session, 'failed') + } + }); + }); + }); + } + $interval(getPivotalStories, 120000); + $interval(getBrowserStackData, 300000); getPivotalStories(); + getBrowserStackData(); } })(); \ No newline at end of file diff --git a/src/app/pages/dashboard/chartJs3DCtrl.js b/src/app/pages/dashboard/chartJs3DCtrl.js index 9764922..e20b7a9 100644 --- a/src/app/pages/dashboard/chartJs3DCtrl.js +++ b/src/app/pages/dashboard/chartJs3DCtrl.js @@ -47,17 +47,24 @@ }).then(function (response) { getPivotalStories().then(function (data) { $scope.workInProgress = []; - users = response.data; + users = {}; stories = data.data; - users.forEach(function (user) { + response.data.forEach(function (user) { var items = $filter('filter')(stories, {owned_by_id: user.person.id}); - items.forEach(function (ignore, index) { - items[index].owner = user.person; + users[user.person.id] = user.person; + }); + + + stories.forEach(function (story, index) { + story.owners = []; + + story.owner_ids.forEach(function (ownerId) { + story.owners.push(users[ownerId]); }); - $scope.workInProgress = $scope.workInProgress.concat(items); + $scope.workInProgress.push(story); }); }); }); diff --git a/src/app/pages/dashboard/dashboard.html b/src/app/pages/dashboard/dashboard.html index 8930636..969540c 100644 --- a/src/app/pages/dashboard/dashboard.html +++ b/src/app/pages/dashboard/dashboard.html @@ -1,5 +1,5 @@
-
+
@@ -16,23 +16,60 @@
-
-
-
-
- - +
+
+
+
+
+

Failed

+

{{behatResults.failed}}

+
+
+
+
+

Passed

+

{{behatResults.passed}}

+
+
+
+
+ +
+ +
+
+
+

Windows

+ +
+
    +
  • + {{results.name}}{{results.percentage}}% +
  • +
+
+
+
+

Mac

+ +
+
    +
  • + {{results.name}}{{results.percentage}}% +
  • +
+
+
+
-
+
-
{{story.owner.name}} #{{story.id}}
+
{{owner.name}} #{{story.id}}

{{story.name}}

diff --git a/src/browserstack_php.php b/src/browserstack_php.php new file mode 100644 index 0000000..6707843 --- /dev/null +++ b/src/browserstack_php.php @@ -0,0 +1,160 @@ +token = $token; + } + + public function get($request_uri, $data = NULL, $headers = array(), $parse_body = TRUE) + { + return self::request('GET', $request_uri, $data, $headers, $parse_body); + } + + private function request($method, $request_uri, $data = NULL, $headers = array(), $parse_body = TRUE) + { + if (NULL !== $this->token) { + $headers[] = 'Authorization: Basic ' . $this->token; + } + + // Force to JSON for now - ideally this needs to look at the current Output::$outputFormat to ensure returned data is consistent + $headers[] = 'Accept: application/json'; + return self::makeRequest($method, $request_uri, $data, $headers, $parse_body); + } + + private function makeRequest($method, $request_uri, $data = NULL, $headers = array(), $parse_body = TRUE) + { + $returnValue = FALSE; + + $request_url = $this->apiRoot . ltrim($request_uri, '/'); + + $response = HTTP_Request_Helper::request($method, $request_url, $data, $headers); + + if (FALSE !== $response) { + $returnValue = array(); + $returnValue['status'] = $response['status']; + $returnValue['headers'] = $response['headers']; + $returnValue['body'] = json_decode($response['body'], TRUE); + } else { + $returnValue = array(); + $returnValue['status'] = 504; + $returnValue['headers'] = array(); + $returnValue['body'] = ''; + } + + return $returnValue; + } +} + +class BrowserStackClient extends BrowserStackAPI_Helper +{ + + public function __construct($username, $password) + { + $token = $this->generateToken($username, $password); + $this->setAccessToken($token); + } + + public function buildSessions($buildId) + { + return $this->get('automate/builds/' . $buildId . '/sessions.json'); + } + + public function builds() + { + return $this->get('automate/builds.json'); + } + + private function generateToken($user, $password) + { + return base64_encode($user . ':' . $password); + } +} + +$user = 'danneh1'; +$password = '5gXqwjkDjBtTiLVmvsLV'; +$browserStackClient = new BrowserStackClient($user, $password); + +$buildId = '7ecd9b26fd193d25102ef8e45acad32b02127615'; + +if ($_GET['type'] == 'builds') { + $response = $browserStackClient->builds(); + if (isset($response['body']) && is_array($response['body'])) { + echo json_encode(['results' => $response['body']]); + } else { + echo json_encode(['errors' => ['No results found for builds.']]); + } +} else if (isset($_GET['type']) && $_GET['type'] == 'buildSessions' && isset($_GET['buildId'])) { + $buildId = $_GET['buildId']; + $response = $browserStackClient->buildSessions($buildId); + + if (isset($response['body']) && is_array($response['body'])) { + echo json_encode(['results' => $response['body']]); + } else { + if (!$buildId) { + echo json_encode(['errors' => ['GET parameter of buildId is required for buildSessions query.']]); + } else { + echo json_encode(['errors' => ['No results found for build sessions.']]); + } + } +} else { + echo json_encode(['errors' => ['GET parameter of builds of buildSessions is required.']]); +} +?> \ No newline at end of file diff --git a/src/sass/app/_dashboard.scss b/src/sass/app/_dashboard.scss index 592a94b..d5353ac 100644 --- a/src/sass/app/_dashboard.scss +++ b/src/sass/app/_dashboard.scss @@ -20,4 +20,8 @@ .blurCalendar{ height: 475px; +} + +.list-of-words:not(:nth-last-child(2)):after { + content: ", "; } \ No newline at end of file