Skip to content

Commit

Permalink
feat(netflix): allow user to pick commit for git trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Apr 13, 2017
1 parent 4f1ddc8 commit a6c7c51
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/core/domain/ITrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IGitTrigger extends ITrigger {
project: string;
slug: string;
branch: string;
hash?: string;
type: 'git';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ module.exports = angular.module('spinnaker.core.pipeline.config.configProvider',
}, (stage) => [stage ? stage.type : '', stage ? stage.cloudProvider || stage.cloudProviderType || 'aws' : ''].join(':'));

function getTriggerConfig(type) {
var matches = getTriggerTypes().filter(function(triggerType) { return triggerType.key === type; });
return matches.length ? matches[0] : null;
return getTriggerTypes().find((triggerType) => triggerType.key === type);
}

function overrideManualExecutionHandler(triggerType, handlerName) {
const triggerConfig = triggerTypes.find(t => t.key === triggerType);
if (triggerConfig) {
triggerConfig.manualExecutionHandler = handlerName;
}
}

this.registerTrigger = registerTrigger;
Expand Down Expand Up @@ -183,6 +189,7 @@ module.exports = angular.module('spinnaker.core.pipeline.config.configProvider',
getConfigurableStageTypes: getConfigurableStageTypes,
getExecutionTransformers: getExecutionTransformers,
registerTransformer: registerTransformer,
overrideManualExecutionHandler: overrideManualExecutionHandler,
};
};

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IPipelineValidationResults {

export interface IValidatorConfig {
type: string;
message?: string;
skipValidation?: (pipeline: IPipeline, stage: IStage) => boolean;
preventSave?: boolean;
}
Expand All @@ -28,6 +29,7 @@ export interface ITriggerTypeConfig extends IStageOrTriggerTypeConfig {
}

export interface IStageTypeConfig extends IStageOrTriggerTypeConfig {
executionDetailsUrl: string;
defaultTimeoutMs?: number;
}

Expand All @@ -36,7 +38,6 @@ export interface IStageOrTriggerTypeConfig {
description: string;
key: string;
templateUrl: string;
executionDetailsUrl: string;
popoverLabelUrl?: string;
controller: string;
controllerAs: string;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/modules/netflix/ci/ci.dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let angular = require('angular');
module.exports = angular
.module('spinnaker.netflix.ci.dataSource', [
APPLICATION_DATA_SOURCE_REGISTRY,
require('./build.read.service'),
require('./services/build.read.service'),
])
.run(function($q, applicationDataSourceRegistry, buildService) {

Expand Down
5 changes: 4 additions & 1 deletion app/scripts/modules/netflix/ci/ci.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
let angular = require('angular');

import {CI_STATES} from './ci.states';
import {NETFLIX_CI_TRIGGER_HANDLER_COMPONENT} from './trigger/ci.trigger.handler.component';
import {NETFLIX_GIT_MANUAL_EXECUTION_HANDLER} from './trigger/manualExecution.handler';

require('./ci.less');

module.exports = angular
.module('spinnaker.netflix.ci', [
CI_STATES,
NETFLIX_CI_TRIGGER_HANDLER_COMPONENT,
NETFLIX_GIT_MANUAL_EXECUTION_HANDLER,
require('./ci.dataSource'),
require('./ci.controller'),
require('./build.read.service'),
require('./detail/detail.controller'),
require('./detail/detailTab/detailTab.controller'),
]);
2 changes: 1 addition & 1 deletion app/scripts/modules/netflix/ci/detail/detail.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const angular = require('angular');
module.exports = angular
.module('spinnaker.netflix.ci.detail.controller', [
require('angular-ui-router'),
require('../build.read.service.js'),
require('../services/build.read.service'),
SCHEDULER_FACTORY,
])
.controller('CiDetailCtrl', function ($scope, $state, $stateParams, buildService, schedulerFactory, app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const angular = require('angular');
module.exports = angular
.module('spinnaker.netflix.ci.detail.detailTab.controller', [
require('angular-ui-router'),
require('../../build.read.service.js'),
require('../../services/build.read.service'),
SCHEDULER_FACTORY,
])
.controller('CiDetailTabCtrl', function ($scope, $state, $stateParams, buildService, schedulerFactory, app) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let angular = require('angular');

import {API_SERVICE} from 'core/api/api.service';
import {CI_FILTER_MODEL} from './ci.filter.model';
import {CI_FILTER_MODEL} from '../ci.filter.model';
import {ORCHESTRATED_ITEM_TRANSFORMER} from 'core/orchestratedItem/orchestratedItem.transformer';
import {SETTINGS} from 'core/config/settings';

Expand Down
62 changes: 62 additions & 0 deletions app/scripts/modules/netflix/ci/services/scm.read.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {IPromise, module} from 'angular';

import {Api, API_SERVICE} from 'core/api/api.service';

export interface IOrganization {
id: string;
displayName: string;
}

export interface IRepository {
name: string;
}

export interface ICommit {
id: string;
displayId: string;
message: string;
author: {username: string, email: string};
authoredTs: number;
}

export interface IBranch {
id: string;
displayId: string;
latestCommitId: string;
'default': boolean;
}

export interface ITag {
id: string;
displayId: string;
commitId: string;
}

export class ScmReadService {

static get $inject() { return ['API']; }
constructor(private API: Api) {}

public getOrganizations(type = 'stash', limit = 1000): IPromise<IOrganization[]> {
return this.API.all('scm', type).withParams({limit}).getList().then((r: any) => r.data);
}

public getRepositories(org: string, type = 'stash', limit = 1000): IPromise<IRepository[]> {
return this.API.all('scm', type, 'orgs', org, 'repos').withParams({limit}).getList().then((r: any) => r.data);
}

public getCommits(org: string, repository: string, type = 'stash', limit = 250): IPromise<ICommit[]> {
return this.API.all('scm', type, 'orgs', org, 'repos', repository, 'commits').withParams({limit}).getList().then((r: any) => r.data);
}

public getBranches(org: string, repository: string, type = 'stash', limit = 100): IPromise<IBranch[]> {
return this.API.all('scm', type, 'orgs', org, 'repos', repository, 'branches').withParams({limit}).getList().then((r: any) => r.data);
}

public getTags(org: string, repository: string, type = 'stash', limit = 200): IPromise<ITag[]> {
return this.API.all('scm', type, 'orgs', org, 'repos', repository, 'tags').withParams({limit}).getList().then((r: any) => r.data);
}
}

export const SCM_SERVICE = 'spinnaker.netflix.ci.scm.read.service';
module(SCM_SERVICE, [API_SERVICE]).service('scmReader', ScmReadService);
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<div ng-if="$ctrl.showOptions">
<div class="form-group">
<label class="col-md-4 sm-label-right">Build from</label>
<div class="col-md-6">
<select class="form-control input-sm"
ng-model="$ctrl.viewState.buildSource"
ng-change="$ctrl.buildSourceChanged()"
ng-options="option for option in $ctrl.buildSources"></select>
</div>
</div>
<div class="form-group" ng-if="$ctrl.viewState.buildSource === 'branch'">
<label class="col-md-4 sm-label-right">Branch</label>
<div class="col-md-6" ng-if="$ctrl.viewState.branches.loading">
<p class="form-control-static text-center">
<span class="glyphicon glyphicon-asterisk glyphicon-spinning"></span>
</p>
</div>
<div class="col-md-6" ng-if="$ctrl.viewState.branches.loadError">Error loading branches!</div>
<div class="col-md-6" ng-if="!$ctrl.viewState.branches.loadError">
<ui-select class="form-control input-sm"
ng-model="$ctrl.command.trigger.branch"
on-select="$ctrl.branchSelected($item)"
ng-if="$ctrl.branches.length">
<ui-select-match placeholder="Select...">
<span>
<strong>{{$select.selected.displayId}}</strong>
<span ng-if="$select.selected.default">(default branch)</span>
</span>
</ui-select-match>
<ui-select-choices repeat="branch.displayId as branch in $ctrl.branches | filter: $select.search">
<div>
<strong>{{branch.displayId}}</strong>
<span ng-if="branch.default">(default branch)</span>
<div>
Latest commit: {{branch.latestCommitId}}
</div>
</div>
</ui-select-choices>
</ui-select>
</div>
</div>

<div class="form-group" ng-if="$ctrl.viewState.buildSource === 'commit'">
<label class="col-md-4 sm-label-right">Commit</label>
<div class="col-md-6" ng-if="$ctrl.viewState.commits.loading">
<p class="form-control-static text-center">
<span class="glyphicon glyphicon-asterisk glyphicon-spinning"></span>
</p>
</div>
<div class="col-md-6" ng-if="$ctrl.viewState.commits.loadError">Error loading commits!</div>
<div class="col-md-6" ng-if="!$ctrl.viewState.commits.loadError">
<ui-select class="form-control input-sm"
ng-model="$ctrl.command.trigger.hash"
ng-if="$ctrl.commits.length">
<ui-select-match placeholder="Select...">
<span>
<strong>{{$select.selected.displayId}}</strong>
({{$select.selected.author.username}})
<span ng-bind="$select.selected.message"></span>
</span>
</ui-select-match>
<ui-select-choices repeat="commit.id as commit in $ctrl.commits | filter: $select.search">
<div>
<strong>{{commit.displayId}}</strong> ({{commit.author.username}})
<div>
<span ng-bind="commit.message"></span>
<div class="text-right">{{commit.authoredTs | timestamp}}</div>
</div>
</div>
</ui-select-choices>
</ui-select>
</div>
</div>

<div class="form-group" ng-if="$ctrl.viewState.buildSource === 'tag'">
<label class="col-md-4 sm-label-right">Tag</label>
<div class="col-md-6" ng-if="$ctrl.viewState.tags.loading">
<p class="form-control-static text-center">
<span class="glyphicon glyphicon-asterisk glyphicon-spinning"></span>
</p>
</div>
<div class="col-md-6" ng-if="$ctrl.viewState.tags.loadError">Error loading tags!</div>
<div class="col-md-6" ng-if="!$ctrl.viewState.tags.loadError">
<ui-select class="form-control input-sm"
ng-model="$ctrl.command.trigger.hash"
ng-if="$ctrl.tags.length">
<ui-select-match placeholder="Select...">
<span>
<strong>{{$select.selected.displayId}}</strong>
<span ng-if="$select.selected.default">(default branch)</span>
</span>
</ui-select-match>
<ui-select-choices repeat="tag.commitId as tag in $ctrl.tags | filter: $select.search">
<div>
<strong>{{tag.displayId}}</strong>
</div>
</ui-select-choices>
</ui-select>
</div>
</div>
</div>
Loading

0 comments on commit a6c7c51

Please sign in to comment.