Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Deploy: Add Public GitLab Repository support #3239

Merged
merged 17 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,595 changes: 2,197 additions & 2,398 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"rxjs": "^6.2.0",
"rxjs-spy": "^7.0.2",
"rxjs-websockets": "~6.0.0",
"ts-md5": "^1.2.4",
"web-animations-js": "^2.3.1",
"xterm": "^3.5.0",
"zone.js": "~0.8.26"
Expand Down Expand Up @@ -121,4 +122,4 @@
"tslint": "~5.10.0",
"typescript": "~2.9.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ const initialState = {
uaaSetup: {},
user: {},
cloudFoundryInfo: {},
githubRepo: {},
githubBranches: {},
githubCommits: {},
gitRepo: {},
gitBranches: {},
gitCommits: {},
environmentVars: {},
stats: {},
summary: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { generateTestApplicationServiceProvider } from '../../test-framework/app
import { generateTestEntityServiceProvider } from '../../test-framework/entity-service.helper';
import { ApplicationService } from './application.service';
import { ApplicationEnvVarsHelper } from './application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { GitSCMService } from '../../shared/data-services/scm/scm.service';

describe('ApplicationService', () => {

Expand All @@ -37,7 +38,8 @@ describe('ApplicationService', () => {
ApplicationEnvVarsHelper,
EntityMonitorFactory,
PaginationMonitorFactory,
{ provide: GITHUB_API_URL, useFactory: getGitHubAPIURL }
{ provide: GITHUB_API_URL, useFactory: getGitHubAPIURL },
GitSCMService
]
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { generateTestEntityServiceProvider } from '../../../../test-framework/en
import { createBasicStoreModule } from '../../../../test-framework/store-test-helper';
import { ApplicationEnvVarsHelper } from './../application-tabs-base/tabs/build-tab/application-env-vars.service';
import { ApplicationTabsBaseComponent } from './application-tabs-base.component';
import { HttpModule, Http, ConnectionBackend } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { GITHUB_API_URL, getGitHubAPIURL } from '../../../../core/github.helpers';

describe('ApplicationTabsBaseComponent', () => {
let component: ApplicationTabsBaseComponent;
Expand All @@ -34,7 +37,8 @@ describe('ApplicationTabsBaseComponent', () => {
BrowserAnimationsModule,
RouterTestingModule,
MDAppModule,
createBasicStoreModule()
createBasicStoreModule(),
HttpModule
],
providers: [
generateTestEntityServiceProvider(
Expand All @@ -44,7 +48,13 @@ describe('ApplicationTabsBaseComponent', () => {
),
generateTestApplicationServiceProvider(cfId, appId),
ApplicationStateService,
ApplicationEnvVarsHelper
ApplicationEnvVarsHelper,
Http,
{
provide: ConnectionBackend,
useClass: MockBackend
},
{ provide: GITHUB_API_URL, useFactory: getGitHubAPIURL }
]
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CfUserService } from './../../../../shared/data-services/cf-user.service';

import { Component, Inject, NgZone, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store } from '@ngrx/store';
Expand Down Expand Up @@ -34,6 +33,8 @@ import {
} from '../../../../core/extension/extension-service';
import { CurrentUserPermissions } from '../../../../core/current-user-permissions.config';
import { CurrentUserPermissionsService } from '../../../../core/current-user-permissions.service';
import { GitSCMService, GitSCMType } from './../../../../shared/data-services/scm/scm.service';


// Confirmation dialogs
const appStopConfirmation = new ConfirmationDialogConfig(
Expand Down Expand Up @@ -79,7 +80,8 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
private confirmDialog: ConfirmationDialogService,
private endpointsService: EndpointsService,
private ngZone: NgZone,
private currentUserPermissionsService: CurrentUserPermissionsService
private currentUserPermissionsService: CurrentUserPermissionsService,
scmService: GitSCMService
) {
const endpoints$ = store.select(endpointEntitiesSelector);
this.breadcrumbs$ = applicationService.waitForAppEntity$.pipe(
Expand All @@ -98,17 +100,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
}),
first()
);
this.applicationService.applicationStratProject$
.pipe(first())
.subscribe(stratProject => {
if (
stratProject &&
stratProject.deploySource &&
stratProject.deploySource.type === 'github'
) {
this.tabLinks.push({ link: 'github', label: 'GitHub' });
}
});

this.endpointsService.hasMetrics(applicationService.cfGuid).subscribe(hasMetrics => {
if (hasMetrics) {
this.tabLinks.push({
Expand Down Expand Up @@ -137,6 +129,20 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {

// Add any tabs from extensions
this.tabLinks = this.tabLinks.concat(getTabsFromExtensions(StratosTabType.Application));

this.applicationService.applicationStratProject$
.pipe(first())
.subscribe(stratProject => {
if (
stratProject &&
stratProject.deploySource &&
(stratProject.deploySource.type === 'github' || stratProject.deploySource.type === 'gitscm')
) {
const gitscm = stratProject.deploySource.scm || stratProject.deploySource.type;
const scm = scmService.getSCM(gitscm as GitSCMType);
this.tabLinks.push({ link: 'gitscm', label: scm.getLabel() });
}
});
}

public breadcrumbs$: Observable<IHeaderBreadcrumb[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface EnvVarStratosProjectSource {
type: string;
timestamp: number;
project?: string;
scm?: string;
branch?: string;
url?: string;
commit?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</mat-card-content>
</mat-card>
</app-tile>
<app-tile *ngIf="(applicationService.applicationStratProject$ | async)?.deploySource as deploySource; else notDeployedFromStratos">
<app-tile *ngIf="(deploySource$ | async) as deploySource; else notDeployedFromStratos" id="app-build-tab-deployment-info">
<mat-card>
<mat-card-header>
<mat-card-title>Deployment Info</mat-card-title>
Expand All @@ -89,8 +89,8 @@
{{(applicationService.applicationStratProject$| async)?.deploySource.url}}
</div>
</app-metadata-item>
<app-metadata-item *ngSwitchCase="'github'" iconFont="stratos-icons" icon="github" label="GitHub">
<a href="{{ deploySource.url }}/commit/{{ deploySource.commit }}"
<app-metadata-item *ngSwitchCase="'gitscm'" [iconFont]="deploySource.icon.fontName" [icon]="deploySource.icon.iconName" [label]="deploySource.label">
<a href="{{ deploySource.commitURL }}"
rel="noopener noreferrer" target="_blank">
{{ deploySource.commit | slice:0:8 }}
</a>
Expand All @@ -106,7 +106,7 @@
</mat-card>
</app-tile>
<ng-template #notDeployedFromStratos>
<app-tile>
<app-tile id="app-build-tab-deployment-info">
<mat-card>
<mat-card-header>
<mat-card-title>No Deployment Info</mat-card-title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { ApplicationService } from '../../../../application.service';
import { ApplicationEnvVarsHelper } from './application-env-vars.service';
import { BuildTabComponent } from './build-tab.component';
import { ViewBuildpackComponent } from './view-buildpack/view-buildpack.component';
import { HttpModule, Http, ConnectionBackend } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { GITHUB_API_URL, getGitHubAPIURL } from '../../../../../../core/github.helpers';

describe('BuildTabComponent', () => {
let component: BuildTabComponent;
Expand All @@ -37,13 +40,20 @@ describe('BuildTabComponent', () => {
{
initialState
}
)
),
HttpModule
],
providers: [
{ provide: ApplicationService, useClass: ApplicationServiceMock },
AppStoreModule,
ApplicationStateService,
ApplicationEnvVarsHelper
ApplicationEnvVarsHelper,
Http,
{
provide: ConnectionBackend,
useClass: MockBackend
},
{ provide: GITHUB_API_URL, useValue: null }
]
})
.compileComponents();
Expand All @@ -57,6 +67,10 @@ describe('BuildTabComponent', () => {
fixture.detectChanges();
}));

afterEach(() => {
fixture.destroy();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { GitSCMType } from './../../../../../../shared/data-services/scm/scm.service';
import { GitHubSCM } from './../../../../../../shared/data-services/scm/github-scm';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { combineLatest, distinct, map } from 'rxjs/operators';
import { combineLatest, distinct, map, tap } from 'rxjs/operators';

import { EntityInfo } from '../../../../../../store/types/api.types';
import { AppSummary } from '../../../../../../store/types/app-metadata.types';
import { getFullEndpointApiUrl } from '../../../../../endpoints/endpoint-helpers';
import { ApplicationMonitorService } from '../../../../application-monitor.service';
import { ApplicationData, ApplicationService } from '../../../../application.service';
import { GitSCMService } from '../../../../../../shared/data-services/scm/scm.service';


@Component({
Expand All @@ -20,7 +23,7 @@ import { ApplicationData, ApplicationService } from '../../../../application.ser
export class BuildTabComponent implements OnInit {


constructor(public applicationService: ApplicationService) { }
constructor(public applicationService: ApplicationService, private scmService: GitSCMService) { }

cardTwoFetching$: Observable<boolean>;

Expand All @@ -30,6 +33,8 @@ export class BuildTabComponent implements OnInit {

sshStatus$: Observable<string>;

deploySource$: Observable<any>;

ngOnInit() {
this.cardTwoFetching$ = this.applicationService.application$.pipe(
combineLatest(
Expand All @@ -49,5 +54,28 @@ export class BuildTabComponent implements OnInit {
}
})
);

this.deploySource$ = this.applicationService.applicationStratProject$.pipe(
map(project => {
if (!!project) {
const deploySource = { ... project.deploySource } as any;

// Legacy
if (deploySource.type === 'github') {
deploySource.type = 'gitscm';
deploySource.scm = 'github';
}

const scmType = deploySource.scm as GitSCMType;
const scm = this.scmService.getSCM(scmType);
deploySource.label = scm.getLabel();
deploySource.commitURL = scm.getCommitURL(deploySource.project, deploySource.commit);
deploySource.icon = scm.getIcon();
return deploySource;
} else {
return null;
}
})
);
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<app-tile-grid class="github-tab" *ngIf="stratosProject$ | async as stratosProject">
<app-tile-grid class="gitscm-tab" *ngIf="stratosProject$ | async as stratosProject">
<app-tile-group>
<app-tile>
<mat-card>
<mat-card-header>
<mat-card-title>Deployment Information</mat-card-title>
</mat-card-header>
<mat-card-content>
<div class="github-tab__deployment">
<div class="gitscm-tab__deployment">
<app-metadata-item label="Repository">
<a href="{{(gitHubRepo$ | async)?.html_url}}" target="_blank">{{stratosProject.deploySource.project }}</a>
<a href="{{(gitSCMRepo$ | async)?.html_url}}" target="_blank">{{stratosProject.deploySource.project }}</a>
</app-metadata-item>
<app-metadata-item label="Branch">
<a href="{{(gitHubRepo$ | async)?.html_url}}/tree/{{ stratosProject.deploySource.branch}}" target="_blank">
<a href="{{(gitSCMRepo$ | async)?.html_url}}/tree/{{ stratosProject.deploySource.branch}}" target="_blank">
{{ stratosProject.deploySource.branch}}
</a>
</app-metadata-item>
<div class="github-tab__deployment__commit">
<div class="gitscm-tab__deployment__commit">
<div>
<app-metadata-item label="Commit">
<a href="{{(commit$ | async)?.html_url}}" target="_blank">{{ stratosProject.deploySource.commit | limitTo: 8}}</a>
</app-metadata-item>
</div>
<div class="github-tab__deployment__commit-warning" *ngIf="!(isHead$ | async) && (initialised$ | async)">
<div class="gitscm-tab__deployment__commit-warning" *ngIf="!(isHead$ | async) && (initialised$ | async)">
<div>
<mat-icon color="warn">warning</mat-icon>
</div>
<div class="github-tab__deployment__commit-warning__msg">The {{ stratosProject.deploySource.branch}} branch has been updated since this app was deployed. Redeploy to update</div>
<div class="gitscm-tab__deployment__commit-warning__msg">The {{ stratosProject.deploySource.branch}} branch has been updated since this app was deployed. Redeploy to update</div>
</div>
</div>
<app-metadata-item label="Deployed:">{{ stratosProject.deploySource.timestamp * 1000 | date:'medium' }}</app-metadata-item>
Expand All @@ -40,18 +40,19 @@
</mat-card-header>
<mat-card-content>

<div *ngIf="gitHubRepo$ | async as githubRepo">
<div class="github-tab__avatar">
<img src={{githubRepo.owner.avatar_url}}>
<div *ngIf="gitSCMRepo$ | async as gitSCMRepo">
<div class="gitscm-tab__avatar">
<img src={{gitSCMRepo.owner.avatar_url}}>
</div>
<div>
<app-metadata-item label="Full Name">
<a href="{{ githubRepo.html_url }}" target="_blank">{{ githubRepo.full_name }}</a>
<a href="{{ gitSCMRepo.html_url }}" target="_blank">{{ gitSCMRepo.full_name }}</a>
</app-metadata-item>
<app-metadata-item label="Owner">{{ githubRepo.owner.login }}</app-metadata-item>
<app-metadata-item label="Description">{{ githubRepo.description }}</app-metadata-item>
<app-metadata-item label="Created:">{{ githubRepo.created_at | date:'medium' }}</app-metadata-item>
<app-metadata-item label="Last Pushed:">{{ githubRepo.pushed_at | date:'medium' }}</app-metadata-item>
<app-metadata-item label="Owner">{{ gitSCMRepo.owner.login || gitSCMRepo.owner.name }}</app-metadata-item>
<app-metadata-item label="Description">{{ gitSCMRepo.description }}</app-metadata-item>
<app-metadata-item label="Created:">{{ gitSCMRepo.created_at | date:'medium' }}</app-metadata-item>
<app-metadata-item *ngIf="gitSCMRepo.pushed_at" label="Last Pushed:">{{ gitSCMRepo.pushed_at | date:'medium' }}</app-metadata-item>
<app-metadata-item *ngIf="gitSCMRepo.last_activity_at" label="Last Actvity:">{{ gitSCMRepo.last_activity_at | date:'medium' }}</app-metadata-item>
</div>
</div>
</mat-card-content>
Expand All @@ -64,7 +65,7 @@
</mat-card-header>
<mat-card-content>
<div *ngIf="commit$ | async as commitInfo">
<div class="github-tab__avatar">
<div class="gitscm-tab__avatar">
<img src={{commitInfo.author.avatar_url}}>
</div>
<div>
Expand All @@ -82,5 +83,5 @@
</mat-card>
</app-tile>
</app-tile-group>
<app-list *ngIf="gitHubRepo$ | async as githubRepo"></app-list>
<app-list *ngIf="gitSCMRepo$ | async as gitSCMRepo"></app-list>
</app-tile-grid>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.github-tab {
.gitscm-tab {
&__deployment {
&__commit-warning {
display: flex;
Expand All @@ -8,7 +8,7 @@
padding-left: 24px;
}
}
.github-tab__avatar {
.gitscm-tab__avatar {
img {
float: right;
height: 84px;
Expand Down
Loading