This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/triggered-build-description.js
Joseph Schorr 99c986df6c Fix display of triggered builds if their trigger has been deleted
Before this change, if a build was triggered by a build trigger that was subsequently deleted, we'd display "Manually triggered" for the build in the UI, even though we have sufficient metadata to show *nearly the same* normal build information. After this change, if we have said trigger metadata, we still display as much as we can.

Fixes https://jira.coreos.com/browse/QUAY-855
2018-05-14 15:30:52 -04:00

69 lines
2 KiB
JavaScript

/**
* An element which displays information about a build that was triggered from an outside source.
*/
angular.module('quay').directive('triggeredBuildDescription', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/triggered-build-description.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'build': '=build'
},
controller: function($scope, $element, KeyService, TriggerService) {
$scope.TriggerService = TriggerService;
$scope.showLongDescription = false;
$scope.toggleLongDescription = function() {
$scope.showLongDescription = !$scope.showLongDescription;
};
$scope.hasLongDescription = function(message) {
if (!message) { return ''; }
return message.length >= 80 || message.split('\n').length > 1;
};
$scope.getMessageSummary = function(message) {
if (!message) { return ''; }
var lines = message.split('\n');
return lines[0].substring(0, 79).trim();
};
$scope.getMessageLongDescription = function(message) {
if (!message) { return ''; }
var lines = message.split('\n');
if (lines[0].length >= 80) {
lines[0] = lines[0].substring(80);
} else {
lines.splice(0, 1);
}
return lines.join('\n').trim();
};
$scope.$watch('build', function(build) {
if (!build) { return; }
var triggerMetadata = build.trigger_metadata || {};
if (triggerMetadata.commit_info) {
$scope.infoDisplay = 'fullcommit';
return;
}
if (!build.trigger) {
$scope.infoDisplay = build.manual_user ? 'manual+user' : 'manual';
return;
}
if (build.trigger.build_source && TriggerService.getCommitSHA(triggerMetadata)) {
$scope.infoDisplay = 'commitsha';
return;
}
$scope.infoDisplay = 'source';
});
}
};
return directiveDefinitionObject;
});