Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 231ccb6

Browse files
MarkDeMariaMarkDeMaria
authored and
MarkDeMaria
committedJan 13, 2017
Allow editing of build hooks on build configuration page
-Single-select tag for Command, Script, and Args, Command+Args, Script+Args -Whatever option is currently-selected upon hitting 'Save' will overwrite anything else. For example, if post commit has a command in it, and you hit save on the Args page, the command will be deleted and the args saved. -Checkbox shows/hides the build hook editor. Leaving it unchcked and selecting "Save" with anything saved in the post commit section of the YAML will be deleted, as the user has indicated they do not wish to have any build hooks
1 parent 865715f commit 231ccb6

File tree

9 files changed

+811
-39
lines changed

9 files changed

+811
-39
lines changed
 

‎app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ <h1>JavaScript Required</h1>
140140
<script src="bower_components/ace-builds/src-min-noconflict/mode-yaml.js"></script>
141141
<script src="bower_components/ace-builds/src-min-noconflict/theme-dreamweaver.js"></script>
142142
<script src="bower_components/ace-builds/src-min-noconflict/theme-eclipse.js"></script>
143+
<script src="bower_components/ace-builds/src-min-noconflict/mode-sh.js"></script>
143144
<script src="bower_components/angular-ui-ace/ui-ace.js"></script>
144145
<script src="bower_components/clipboard/dist/clipboard.js"></script>
145146
<script src="bower_components/ansi_up/ansi_up.js"></script>

‎app/scripts/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ window.OPENSHIFT_CONSTANTS = {
5151
"builds": "architecture/core_concepts/builds_and_image_streams.html#builds",
5252
"image-streams": "architecture/core_concepts/builds_and_image_streams.html#image-streams",
5353
"storage": "architecture/additional_concepts/storage.html",
54+
"build-hooks": "dev_guide/builds.html#build-hooks",
5455
// default should remain last, add new links above
5556
"default": "welcome/index.html"
5657
},

‎app/scripts/controllers/edit/buildConfig.js

+75-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ angular.module('openshiftConsole')
5555
"title": "Inline"
5656
}];
5757
$scope.view = {
58-
advancedOptions: false
58+
advancedOptions: false,
59+
hasHooks: false
5960
};
6061
$scope.breadcrumbs = [
6162
{
@@ -117,6 +118,75 @@ angular.module('openshiftConsole')
117118
"SerialLatestOnly"
118119
];
119120

121+
$scope.buildHookTypes = [{
122+
id: "command",
123+
label: "Command"
124+
}, {
125+
id: "script",
126+
label: "Shell Script"
127+
}, {
128+
id: "args",
129+
label: "Arguments to default image entry point"
130+
}, {
131+
id: "commandArgs",
132+
label: "Command with arguments"
133+
}, {
134+
id: "scriptArgs",
135+
label: "Shell script with arguments"
136+
}];
137+
138+
$scope.buildHookSelection = {
139+
type: {}
140+
};
141+
142+
var getInitialBuildHookSelection = function() {
143+
var hasArgs = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.args'));
144+
var hasCommand = !_.isEmpty(_.get($scope, 'buildConfig.spec.postCommit.command'));
145+
var hasScript = !!_.get($scope, 'buildConfig.spec.postCommit.script');
146+
$scope.view.hasHooks = hasArgs || hasCommand || hasScript;
147+
148+
if (hasArgs && hasCommand) {
149+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'commandArgs' });
150+
} else if (hasArgs && hasScript) {
151+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'scriptArgs' });
152+
} else if (hasArgs) {
153+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'args' });
154+
} else if (hasScript) {
155+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'script' });
156+
} else {
157+
$scope.buildHookSelection.type = _.find($scope.buildHookTypes, { id: 'command' });
158+
}
159+
};
160+
161+
var clearIncompatibleBuildHookFields = function() {
162+
if ($scope.view.hasHooks) {
163+
switch ($scope.buildHookSelection.type.id) {
164+
case "script":
165+
delete $scope.updatedBuildConfig.spec.postCommit.command;
166+
delete $scope.updatedBuildConfig.spec.postCommit.args;
167+
break;
168+
case "command":
169+
delete $scope.updatedBuildConfig.spec.postCommit.script;
170+
delete $scope.updatedBuildConfig.spec.postCommit.args;
171+
break;
172+
case "args":
173+
delete $scope.updatedBuildConfig.spec.postCommit.script;
174+
delete $scope.updatedBuildConfig.spec.postCommit.command;
175+
break;
176+
case "scriptArgs":
177+
delete $scope.updatedBuildConfig.spec.postCommit.command;
178+
break;
179+
case "commandArgs":
180+
delete $scope.updatedBuildConfig.spec.postCommit.script;
181+
break;
182+
}
183+
} else {
184+
$scope.updatedBuildConfig.spec.postCommit.command = [];
185+
$scope.updatedBuildConfig.spec.postCommit.args = [];
186+
$scope.updatedBuildConfig.spec.postCommit.script = "";
187+
}
188+
};
189+
120190
AlertMessageService.getAlerts().forEach(function(alert) {
121191
$scope.alerts[alert.name] = alert.data;
122192
});
@@ -143,6 +213,8 @@ angular.module('openshiftConsole')
143213
// success
144214
function(buildConfig) {
145215
$scope.buildConfig = buildConfig;
216+
getInitialBuildHookSelection();
217+
146218
$scope.updatedBuildConfig = angular.copy($scope.buildConfig);
147219
$scope.buildStrategy = buildStrategy($scope.updatedBuildConfig);
148220
$scope.strategyType = $scope.buildConfig.spec.strategy.type;
@@ -180,7 +252,7 @@ angular.module('openshiftConsole')
180252
}
181253

182254
if (imageOptions.type === "ImageStreamImage") {
183-
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
255+
isimage = (imageData.namespace || buildConfig.metadata.namespace) + "/" + imageData.name;
184256
} else {
185257
isimage = "";
186258
}
@@ -414,6 +486,7 @@ angular.module('openshiftConsole')
414486

415487
$scope.save = function() {
416488
$scope.disableInputs = true;
489+
clearIncompatibleBuildHookFields();
417490
// Update Configuration
418491
buildStrategy($scope.updatedBuildConfig).forcePull = $scope.options.forcePull;
419492

‎app/views/edit/build-config.html

+67-7
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ <h3>Source Configuration</h3>
115115
<div ui-ace="{
116116
mode: 'dockerfile',
117117
theme: 'dreamweaver',
118-
onLoad: aceLoaded,
119118
rendererOptions: {
120119
fadeFoldWidgets: true,
121120
showPrintMargin: false
@@ -275,7 +274,6 @@ <h3 ng-class="{ 'with-divider': !sources.none }">Jenkins Pipeline Configuration<
275274
<div ui-ace="{
276275
mode: 'groovy',
277276
theme: 'eclipse',
278-
onLoad: aceLoaded,
279277
rendererOptions: {
280278
fadeFoldWidgets: true,
281279
showPrintMargin: false
@@ -416,8 +414,6 @@ <h3 class="with-divider">Image Configuration</h3>
416414
</dl>
417415
</div>
418416

419-
420-
421417
<div ng-if="!(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
422418
<h3 class="with-divider">Environment Variables<span class="help action-inline">
423419
<a href="">
@@ -523,8 +519,8 @@ <h3 class="with-divider">Run Policy
523519
{{type | sentenceCase}}
524520
</ui-select-choices>
525521
</ui-select>
526-
527522
</div>
523+
528524
<div ng-switch="updatedBuildConfig.spec.runPolicy">
529525
<div class="help-block" ng-switch-when="Serial">Builds triggered from this Build Configuration will run one at the time, in the order they have been triggered.</div>
530526
<div class="help-block" ng-switch-when="Parallel">Builds triggered from this Build Configuration will run all at the same time. The order in which they will finish is not guaranteed.</div>
@@ -533,8 +529,72 @@ <h3 class="with-divider">Run Policy
533529
</div>
534530
</div>
535531

536-
<div>
537-
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} Advanced Options</a>
532+
<div ng-if="view.advancedOptions && !(updatedBuildConfig | isJenkinsPipelineStrategy)" class="section">
533+
<h3 class="with-divider">Build Hooks
534+
<span class="help action-inline">
535+
<a href="{{'build-hooks' | helpLink}}" aria-hidden="true" target="_blank"><span class="learn-more-inline">Learn More&nbsp;<i class="fa fa-external-link"></i></span></a>
536+
</span>
537+
</h3>
538+
539+
<div class="checkbox">
540+
<label>
541+
<input type="checkbox" ng-model="view.hasHooks" id="enable-build-hooks">
542+
Run build hooks after image is built
543+
</label>
544+
<div class="help-block">
545+
Build hooks allow you to run commands at the end of the build to verify the image.
546+
</div>
547+
</div>
548+
549+
<div ng-show="view.hasHooks">
550+
<div class="form-group">
551+
<h4>Hook Types</h4>
552+
<ui-select
553+
ng-model="buildHookSelection.type"
554+
title="Choose a type of build hook">
555+
<ui-select-match>{{$select.selected.label}}</ui-select-match>
556+
<ui-select-choices repeat="type in buildHookTypes">
557+
{{type.label}}
558+
</ui-select-choices>
559+
</ui-select>
560+
</div>
561+
562+
<fieldset>
563+
<div ng-show="buildHookSelection.type.id === 'script' || buildHookSelection.type.id === 'scriptArgs'">
564+
<h4>Script</h4>
565+
<div
566+
ui-ace="{
567+
mode: 'sh',
568+
theme: 'eclipse',
569+
rendererOptions: {
570+
fadeFoldWidgets: true,
571+
showPrintMargin: false
572+
}
573+
}"
574+
ng-model="updatedBuildConfig.spec.postCommit.script"
575+
class="ace-bordered ace-inline mar-top-md">
576+
</div>
577+
</div>
578+
579+
<div ng-show="buildHookSelection.type.id === 'command' || buildHookSelection.type.id === 'commandArgs'">
580+
<h4>Command</h4>
581+
<edit-command
582+
args="updatedBuildConfig.spec.postCommit.command">
583+
</edit-command>
584+
</div>
585+
586+
<div ng-show="buildHookSelection.type.id === 'args' || buildHookSelection.type.id === 'commandArgs' || buildHookSelection.type.id === 'scriptArgs' ">
587+
<h4>Arguments</h4>
588+
<edit-command
589+
args="updatedBuildConfig.spec.postCommit.args">
590+
</edit-command>
591+
</div>
592+
</fieldset>
593+
</div>
594+
</div>
595+
596+
<div class="gutter-top">
597+
<a href="" ng-click="view.advancedOptions = !view.advancedOptions" role="button">{{view.advancedOptions ? 'Hide' : 'Show'}} advanced options</a>
538598
</div>
539599
<div class="buttons gutter-top-bottom">
540600
<button

‎bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
"src-min-noconflict/mode-groovy.js",
106106
"src-min-noconflict/mode-yaml.js",
107107
"src-min-noconflict/theme-dreamweaver.js",
108-
"src-min-noconflict/theme-eclipse.js"
108+
"src-min-noconflict/theme-eclipse.js",
109+
"src-min-noconflict/mode-sh.js"
109110
]
110111
}
111112
}

‎dist.java/java/libs-badc905293.js

+77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.