fix retrigger/cancel to use request id

This commit is contained in:
Cameron Dawson 2014-05-21 15:11:10 -07:00
Родитель 21c8d34664
Коммит 10b193765d
3 изменённых файлов: 33 добавлений и 31 удалений

Просмотреть файл

@ -8,22 +8,22 @@ treeherder.factory('thBuildApi', [
var selfServeUrl = "https://secure.pub.build.mozilla.org/buildapi/self-serve/";
return {
retriggerJob: function(repoName, buildId) {
retriggerJob: function(repoName, requestId) {
$http({
url: selfServeUrl + repoName + "/build",
url: selfServeUrl + repoName + "/request",
method: "POST",
data: "build_id=" + buildId,
data: "request_id=" + requestId,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
withCredentials: true
}).
success(function(data) {
thNotify.send("job " + buildId + " retriggered");
}).
error(function(data) {
thNotify.send("job " + buildId + " retrigger FAILED", "danger");
}).then(
function(data) {
thNotify.send("job with request of " + requestId + " retriggered");
},
function(data) {
thNotify.send("job with request of " + requestId + " retrigger FAILED", "danger");
});
},
cancelJob: function(repoName, requestId) {
@ -35,6 +35,12 @@ treeherder.factory('thBuildApi', [
"Content-Type": "application/x-www-form-urlencoded"
},
withCredentials: true
}).
success(function(data) {
thNotify.send("job with request of " + requestId + " cancelled");
}).
error(function(data) {
thNotify.send("job with request of " + requestId + " cancel FAILED", "danger");
});
},
cancelAll: function(repoName, revision) {

Просмотреть файл

@ -107,23 +107,10 @@ treeherder.controller('PluginCtrl', [
}
});
$scope.canRetrigger = function() {
if ($scope.job && $scope.artifacts) {
if ($scope.job.state === "pending" && $scope.artifacts.buildapi_pending) {
return true;
} else if (($scope.job.state === "running" ||
$scope.job.state === "completed") && $scope.artifacts.buildapi_running) {
return true;
}
}
return false;
};
$scope.canCancel = function() {
if ($scope.job && $scope.artifacts) {
if ($scope.job.state === "pending" && $scope.artifacts.buildapi_pending) {
return true;
} else if ($scope.job.state === "pending" && $scope.artifacts.buildapi_pending) {
if (($scope.job.state === "pending" || $scope.job.state === "running") &&
($scope.artifacts.buildapi_pending || $scope.artifacts.buildapi_running)) {
return true;
}
}
@ -134,20 +121,29 @@ treeherder.controller('PluginCtrl', [
* Get the build_id needed to cancel or retrigger from the currently
* selected job.
*/
var getBuildId = function() {
if ($scope.job.state === 'pending') {
var getRequestId = function() {
if ($scope.artifacts.buildapi_pending) {
return $scope.artifacts.buildapi_pending.blob.id;
} else if ($scope.job.state === 'running' || $scope.job.state === 'completed') {
return $scope.artifacts.buildapi_running.blob.id;
} else if ($scope.artifacts.buildapi_running &&
$scope.artifacts.buildapi_running.blob.request_ids.length > 0) {
return $scope.artifacts.buildapi_running.blob.request_ids[0];
} else if ($scope.artifacts.buildapi_complete &&
$scope.artifacts.buildapi_complete.blob.request_ids.length > 0) {
return $scope.artifacts.buildapi_complete.blob.request_ids[0];
} else {
// this is super unlikely since we'd need to have at least one of those
// artifacts to even create the job in treeherder. This is just a fallback...
thNotify.send("Unable to get request id for retrigger/cancel", "danger", true);
return null;
}
};
$scope.retriggerJob = function() {
thBuildApi.retriggerJob($scope.repoName, getBuildId());
thBuildApi.retriggerJob($scope.repoName, getRequestId());
};
$scope.cancelJob = function() {
thBuildApi.cancelJob($scope.repoName, getBuildId());
thBuildApi.cancelJob($scope.repoName, getRequestId());
};
$scope.cancelAll = function(resultsetId) {

Просмотреть файл

@ -10,7 +10,7 @@
<span class="fa fa-stop"></span>
</a>
</li>
<li ng-show="canRetrigger()">
<li>
<a title="Retrigger job"
href=""
target="_blank"