forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
211 lines (187 loc) · 6.86 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
'use strict';
/**
* @ngdoc function
* @name openshiftConsole.controller:BuildController
* @description
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('BuildController', function ($scope,
$filter,
$routeParams,
BuildsService,
DataService,
ModalsService,
Navigate,
ProjectsService) {
$scope.projectName = $routeParams.project;
$scope.build = null;
$scope.buildConfig = null;
$scope.buildConfigName = $routeParams.buildconfig;
$scope.builds = {};
$scope.alerts = {};
$scope.showSecret = false;
$scope.renderOptions = {
hideFilterWidget: true
};
$scope.breadcrumbs = [];
if ($routeParams.isPipeline) {
$scope.breadcrumbs.push({
title: "Pipelines",
link: "project/" + $routeParams.project + "/browse/pipelines"
});
if ($routeParams.buildconfig) {
$scope.breadcrumbs.push({
title: $routeParams.buildconfig,
link: "project/" + $routeParams.project + "/browse/pipelines/" + $routeParams.buildconfig
});
}
} else {
$scope.breadcrumbs.push({
title: "Builds",
link: "project/" + $routeParams.project + "/browse/builds"
});
if ($routeParams.buildconfig) {
$scope.breadcrumbs.push({
title: $routeParams.buildconfig,
link: "project/" + $routeParams.project + "/browse/builds/" + $routeParams.buildconfig
});
}
}
$scope.breadcrumbs.push({
title: $routeParams.build
});
var watches = [];
var setLogVars = function(build) {
$scope.logCanRun = !(_.includes(['New', 'Pending', 'Error'], build.status.phase));
};
var updateCanBuild = function() {
if (!$scope.buildConfig) {
$scope.canBuild = false;
} else {
$scope.canBuild = BuildsService.canBuild($scope.buildConfig);
}
};
var buildResolved = function(build, action) {
$scope.loaded = true;
$scope.build = build;
setLogVars(build);
var buildNumber = $filter("annotation")(build, "buildNumber");
if (buildNumber) {
$scope.breadcrumbs[2].title = "#" + buildNumber;
}
if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "This build has been deleted."
};
}
};
var buildRejected = function(e) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The build details could not be loaded.",
details: "Reason: " + $filter('getErrorDetails')(e)
};
};
var buildConfigResolved = function(buildConfig, action) {
if (action === "DELETED") {
$scope.alerts["deleted"] = {
type: "warning",
message: "Build configuration " + $scope.buildConfigName + " has been deleted."
};
$scope.buildConfigDeleted = true;
}
$scope.buildConfig = buildConfig;
$scope.buildConfigPaused = BuildsService.isPaused($scope.buildConfig);
updateCanBuild();
};
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
// FIXME: DataService.createStream() requires a scope with a
// projectPromise rather than just a namespace, so we have to pass the
// context into the log-viewer directive.
$scope.projectContext = context;
$scope.logOptions = {};
DataService
.get("builds", $routeParams.build, context)
.then(function(build) {
buildResolved(build);
watches.push(DataService.watchObject("builds", $routeParams.build, context, buildResolved));
watches.push(DataService.watchObject("buildconfigs", $routeParams.buildconfig, context, buildConfigResolved));
}, buildRejected);
$scope.toggleSecret = function() {
$scope.showSecret = true;
};
$scope.cancelBuild = function() {
BuildsService
.cancelBuild($scope.build, $scope.buildConfigName, context)
.then(function resolve(build) {
// TODO: common alerts service to eliminate duplication
$scope.alerts["cancel"] = {
type: "success",
message: "Cancelled build " + build.metadata.name + " of " + $scope.buildConfigName + "."
};
}, function reject(result) {
// TODO: common alerts service to eliminate duplication
$scope.alerts["cancel"] = {
type: "error",
message: "An error occurred cancelling the build.",
details: $filter('getErrorDetails')(result)
};
});
};
var getLinksClonedBuild = function(build) {
// When the build is first cloned, the Jenkins annotations are not
// yet updated, so the Jenkins log link is wrong. Give a link to the
// build instead of the log. Also link to the build if the user
// doesn't have authority to view the log.
if ($filter('isJenkinsPipelineStrategy')($scope.build) ||
!$filter('canI')('builds/log', 'get')) {
return [{
href: Navigate.resourceURL(build),
label: "View Build"
}];
}
var logLink = $filter('buildLogURL')(build);
if (!logLink) {
return [];
}
return [{
href: logLink,
label: "View Log"
}];
};
$scope.cloneBuild = function() {
var name = _.get($scope, 'build.metadata.name');
if (name && $scope.canBuild) {
BuildsService
.cloneBuild(name, context)
.then(function resolve(build) {
// Add a view log link.
var links = getLinksClonedBuild(build);
$scope.alerts["rebuild"] = {
type: "success",
message: "Build " + name + " is being rebuilt as " + build.metadata.name + ".",
links: links
};
}, function reject(result) {
$scope.alerts["rebuild"] = {
type: "error",
message: "An error occurred while rerunning the build.",
details: $filter('getErrorDetails')(result)
};
});
}
};
$scope.showJenkinsfileExamples = function() {
ModalsService.showJenkinsfileExamples();
};
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});