Skip to content

Commit

Permalink
feat(git): pre-populate git trigger source
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Apr 4, 2017
1 parent c0f13d3 commit a6d1fb9
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {IScope, module} from 'angular';
import {has, trim} from 'lodash';

import {SETTINGS} from 'core/config/settings';
import {IGitTrigger} from 'core/domain/ITrigger';
import {SERVICE_ACCOUNT_SERVICE, ServiceAccountService} from 'core/serviceAccount/serviceAccount.service';

class GitTriggerController {

public fiatEnabled = false;
public serviceAccounts: string[] = [];
public gitTriggerTypes = SETTINGS.gitSources || ['stash', 'github', 'bitbucket'];
public displayText: any = {
'pipeline.config.git.project': {
'bitbucket': 'Team or User',
'github': 'Organization or User',
'stash': 'Project',
},
'pipeline.config.git.slug': {
'bitbucket': 'Repo name',
'github': 'Project',
'stash': 'Repo name'
},
'vm.trigger.project': {
'bitbucket': 'Team or User name, i.e. spinnaker for bitbucket.org/spinnaker/echo',
'github': 'Organization or User name, i.e. spinnaker for github.com/spinnaker/echo',
'stash': 'Project name, i.e. SPKR for stash.mycorp.com/projects/SPKR/repos/echo'
},
'vm.trigger.slug': {
'bitbucket': 'Repository name (not the url), i.e, echo for bitbucket.org/spinnaker/echo',
'github': 'Project name (not the url), i.e, echo for github.com/spinnaker/echo',
'stash': 'Repository name (not the url), i.e, echo for stash.mycorp.com/projects/SPKR/repos/echo'
}
};

static get $inject() { return ['trigger', '$scope', 'serviceAccountService']; }
constructor(public trigger: IGitTrigger, private $scope: IScope, private serviceAccountService: ServiceAccountService) {
this.initialize();
}

public updateBranch(): void {
if (trim(this.trigger.branch) === '') {
this.trigger.branch = null;
}
}

public initialize() {
if (has(this.$scope.application, 'attributes.repoProjectKey') && !this.trigger.source) {
const attributes: any = this.$scope.application.attributes;
this.trigger.source = attributes.repoType;
this.trigger.project = attributes.repoProjectKey;
this.trigger.slug = attributes.repoSlug;
}
this.serviceAccountService.getServiceAccounts().then(accounts => {
this.serviceAccounts = accounts || [];
});
if (this.gitTriggerTypes.length === 1) {
this.trigger.source = this.gitTriggerTypes[0];
}
}
}

export const GIT_TRIGGER = 'spinnaker.core.pipeline.trigger.git';
module(GIT_TRIGGER, [
SERVICE_ACCOUNT_SERVICE,
require('../../pipelineConfigProvider'),
]).config((pipelineConfigProvider: any) => {
pipelineConfigProvider.registerTrigger({
label: 'Git',
description: 'Executes the pipeline on a git push',
key: 'git',
controller: 'GitTriggerCtrl',
controllerAs: 'vm',
templateUrl: require('./gitTrigger.html'),
popoverLabelUrl: require('./gitPopoverLabel.html'),
validators: [
{
type: 'serviceAccountAccess',
message: `You do not have access to the service account configured in this pipeline's git trigger.
You will not be able to save your edits to this pipeline.`,
preventSave: true,
}
]
});
}).controller('GitTriggerCtrl', GitTriggerController);
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<ng-form name="cronForm">
<div class="form-group" ng-if="gitTriggerTypes.length > 1">
<ng-form name="gitTriggerForm">
<div class="form-group" ng-if="vm.gitTriggerTypes.length > 1">
<label class="col-md-3 sm-label-right">
Repo Type
<help-field key="pipeline.config.git.repotype"></help-field>
</label>
<div class="col-md-6">
<select
class="form-control input-sm"
ng-options="repoType for repoType in gitTriggerTypes"
ng-options="repoType for repoType in vm.gitTriggerTypes"
ng-model="vm.trigger.source">
<option value="">Select Repo Type</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 sm-label-right">
{{ displayText['pipeline.config.git.project'][vm.trigger.source] }}
{{ vm.displayText['pipeline.config.git.project'][vm.trigger.source] }}
<help-field key="pipeline.config.git.project"></help-field>
</label>

Expand All @@ -24,22 +24,22 @@
ng-model="vm.trigger.project"
name="project"
required
placeholder="{{ displayText['vm.trigger.project'][vm.trigger.source] }}"
placeholder="{{ vm.displayText['vm.trigger.project'][vm.trigger.source] }}"
/>
</div>
</div>
<div class="form-group">
<label class="col-md-3 sm-label-right">
{{ displayText['pipeline.config.git.slug'][vm.trigger.source] }}
{{ vm.displayText['pipeline.config.git.slug'][vm.trigger.source] }}
<help-field key="pipeline.config.git.slug"></help-field>
</label>
<div class="col-md-9">
<input type="text" class="form-control input-sm"
ng-model="vm.trigger.slug"
name="slug"
required
placeholder="{{ displayText['vm.trigger.slug'][vm.trigger.source] }}"
pattern="^((?!\:\/\/).)*$"
placeholder="{{ vm.displayText['vm.trigger.slug'][vm.trigger.source] }}"
pattern="^((?!://).)*$"
/>
</div>
</div>
Expand All @@ -49,7 +49,7 @@
<help-field key="pipeline.config.git.trigger.branch"></help-field>
</div>
<div class="col-md-9">
<input type="text" class="form-control input-sm" ng-model="trigger.branch"/>
<input type="text" class="form-control input-sm" ng-model="vm.trigger.branch" ng-change="vm.updateBranch()"/>
</div>
</div>
<div class="form-group" ng-if="vm.trigger.source === 'github'">
Expand All @@ -58,7 +58,7 @@
<help-field key="pipeline.config.git.trigger.githubSecret"></help-field>
</div>
<div class="col-md-9">
<input type="text" class="form-control input-sm" ng-model="trigger.secret"/>
<input type="text" class="form-control input-sm" ng-model="vm.trigger.secret"/>
</div>
</div>
<div class="form-group" ng-if="vm.fiatEnabled">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict';

const angular = require('angular');

import {RUN_AS_USER_SELECTOR_COMPONENT} from './runAsUserSelector.component';
import {TRAVIS_TRIGGER} from './travis/travisTrigger.module';

let angular = require('angular');
import {GIT_TRIGGER} from './git/git.trigger';

module.exports = angular.module('spinnaker.core.pipeline.config.trigger', [
require('../stages/stage.module.js'),
require('./cron/cronTrigger.module.js'),
require('./docker/dockerTrigger.module.js'),
require('./git/gitTrigger.module.js'),
GIT_TRIGGER,
require('./jenkins/jenkinsTrigger.module.js'),
TRAVIS_TRIGGER,
require('./pipeline/pipelineTrigger.module.js'),
Expand Down

0 comments on commit a6d1fb9

Please sign in to comment.