Skip to content

Commit

Permalink
fix(ui,api): do not insert an empty workflow if there is no one (#4950)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux committed Feb 4, 2020
1 parent 992f827 commit 596cbee
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 50 deletions.
28 changes: 15 additions & 13 deletions sdk/exportentities/workflow_tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ func (w WorkflowPulled) Tar(ctx context.Context, writer io.Writer) error {
}
}()

bs, err := base64.StdEncoding.DecodeString(w.Workflow.Value)
if err != nil {
return sdk.WithStack(err)
}
if err := tw.WriteHeader(&tar.Header{
Name: fmt.Sprintf(PullWorkflowName, w.Workflow.Name),
Mode: 0644,
Size: int64(len(bs)),
}); err != nil {
return sdk.WrapError(err, "unable to write workflow header for %s", w.Workflow.Name)
}
if _, err := tw.Write(bs); err != nil {
return sdk.WrapError(err, "unable to write workflow value")
if w.Workflow.Value != "" {
bs, err := base64.StdEncoding.DecodeString(w.Workflow.Value)
if err != nil {
return sdk.WithStack(err)
}
if err := tw.WriteHeader(&tar.Header{
Name: fmt.Sprintf(PullWorkflowName, w.Workflow.Name),
Mode: 0644,
Size: int64(len(bs)),
}); err != nil {
return sdk.WrapError(err, "unable to write workflow header for %s", w.Workflow.Name)
}
if _, err := tw.Write(bs); err != nil {
return sdk.WrapError(err, "unable to write workflow value")
}
}

for _, a := range w.Applications {
Expand Down
5 changes: 3 additions & 2 deletions ui/src/app/service/ascode/ascode.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ export class AscodeService {
* @param projectKey
* @param repo
*/
resyncPRAsCode(projectKey: string, appName: string, repo?: string): Observable<any> {
resyncPRAsCode(projectKey: string, appName: string, repo?: string): Observable<boolean> {
let params = new HttpParams();
if (repo) {
params = params.append('repo', repo);
}
params = params.append('appName', appName);

return this._http.post(`/project/${projectKey}/ascode/events/resync`, null, {params})
return this._http.post<boolean>(`/project/${projectKey}/ascode/events/resync`, null, {params})
.map(() => {
this._store.dispatch(new ResyncEvents());
return true;
});
}
}
19 changes: 17 additions & 2 deletions ui/src/app/shared/ascode/events/ascode.event.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
import { AsCodeEvents } from 'app/model/ascode.model';
import { Project } from 'app/model/project.model';
import { AscodeService } from 'app/service/ascode/ascode.service';
import { finalize } from 'rxjs/operators';

@Component({
selector: 'app-ascode-event',
Expand All @@ -11,9 +14,21 @@ export class AsCodeEventComponent {

@Input() events: Array<AsCodeEvents>;
@Input() repo: string;
@Input() appName: string;
@Input() project: Project;

loadingPopupButton = false;

resyncEvents(): void {
constructor(private _ascodeService: AscodeService, private _cd: ChangeDetectorRef) {
}


resyncEvents(): void {
this.loadingPopupButton = true;
this._ascodeService.resyncPRAsCode(this.project.key, this.appName, this.repo)
.pipe(finalize(() => {
this.loadingPopupButton = false;
this._cd.markForCheck();
})).subscribe();
}
}
6 changes: 4 additions & 2 deletions ui/src/app/shared/ascode/events/ascode.event.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="asCodeEvents">
<p>
{{ 'pipeline_from_repository' | translate: {repo: repo} }}
<span *ngIf="repo">{{ 'pipeline_from_repository' | translate: {repo: repo} }}</span>
<span *ngIf="!repo">{{ 'workflow_from_repository_pending' | translate }}</span>
</p>
<ul>
<li *ngFor="let e of events">
Expand All @@ -19,5 +20,6 @@
</ul>
</li>
</ul>
<button class="ui right floated mini green button" (click)="resyncEvents()">{{'btn_resync_repo' | translate }}</button>
<button class="ui right floated mini green button" [disabled]="loadingPopupButton"
[class.loading]="loadingPopupButton" (click)="resyncEvents()">{{'btn_resync_repo' | translate }}</button>
</div>
6 changes: 4 additions & 2 deletions ui/src/app/store/workflow.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,10 @@ export class WorkflowState {
@Action(actionAsCode.ResyncEvents)
refreshAsCodeEvents(ctx: StateContext<WorkflowStateModel>, _) {
const state = ctx.getState();
ctx.dispatch(new actionWorkflow
.GetWorkflow({projectKey: state.projectKey, workflowName: state.workflow.name}));
if (state.workflow) {
ctx.dispatch(new actionWorkflow
.GetWorkflow({projectKey: state.projectKey, workflowName: state.workflow.name}));
}
}

@Action(actionAsCode.AsCodeEvent)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/views/pipeline/show/pipeline.show.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ng-template let-popup #popupFromRepository>
<div class="content infoPopup">
<ng-container *ngIf="pipeline && pipeline.from_repository">
<app-ascode-event [events]="pipeline.ascode_events" [repo]="pipeline.from_repository"></app-ascode-event>
<app-ascode-event [project]="project" [events]="pipeline.ascode_events" [repo]="pipeline.from_repository"></app-ascode-event>
</ng-container>
<ng-container *ngIf="pipeline && !pipeline.from_repository">
<p>{{'pipeline_repository_help_line_1' | translate}}</p>
Expand Down
15 changes: 1 addition & 14 deletions ui/src/app/views/workflow/workflow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { SuiPopup, SuiPopupController, SuiPopupTemplateController } from '@richa
import { Project } from 'app/model/project.model';
import { Workflow } from 'app/model/workflow.model';
import { WorkflowRun } from 'app/model/workflow.run.model';
import { AscodeService } from 'app/service/ascode/ascode.service';
import { WorkflowCoreService } from 'app/service/workflow/workflow.core.service';
import { WorkflowSidebarMode } from 'app/service/workflow/workflow.sidebar.store';
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
Expand Down Expand Up @@ -90,8 +89,7 @@ export class WorkflowComponent {
private _toast: ToastService,
private _translate: TranslateService,
private _store: Store,
private _cd: ChangeDetectorRef,
private _ascodeService: AscodeService
private _cd: ChangeDetectorRef
) {
this.dataRouteSubscription = this._activatedRoute.data.subscribe(datas => {
this.project = datas['project'];
Expand Down Expand Up @@ -237,15 +235,4 @@ export class WorkflowComponent {
this.saveAsCode.show(this.editWorkflow, 'workflow');
}
}

resyncPR(): void {
this.loadingPopupButton = true;
this._ascodeService.resyncPRAsCode(this.project.key,
this.workflow.applications[this.workflow.workflow_data.node.context.application_id].name,
this.workflow.from_repository)
.pipe(finalize(() => this.loadingPopupButton = false))
.subscribe(() => {
this.popupFromlRepository.close();
});
}
}
18 changes: 4 additions & 14 deletions ui/src/app/views/workflow/workflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
</a>
<ng-template let-popup #popupFromRepository>
<div class="content infoPopup">
<ng-container *ngIf="workflow && workflow.from_repository">
<app-ascode-event [events]="workflow.as_code_events" [repo]="workflow.from_repository"></app-ascode-event>
<ng-container *ngIf="workflow && (workflow.from_repository || (workflow.as_code_events && workflow.as_code_events.length > 0))">
<app-ascode-event [events]="workflow.as_code_events" [repo]="workflow.from_repository"
[appName]="workflow.applications[workflow.workflow_data.node.context.application_id].name"
[project]="project"></app-ascode-event>
</ng-container>
<ng-container
*ngIf="workflow && !workflow.from_repository && (!workflow.as_code_events || workflow.as_code_events.length === 0)">
Expand All @@ -37,18 +39,6 @@
</div>
</div>
</ng-container>
<ng-container
*ngIf="workflow && !workflow.from_repository && (workflow.as_code_events && workflow.as_code_events.length > 0)">
<p>{{ 'workflow_from_repository_pending' | translate}}</p>
<ul>
<li *ngFor="let p of workflow.as_code_events">
<a href="{{p.pullrequest_url}}" target="_blank">{{p.pullrequest_url}}</a>
</li>
</ul>
<button class="ui right floated green tiny button" (click)="resyncPR()"
[class.loading]="loadingPopupButton"
[disabled]="loadingPopupButton">{{'workflow_resync' | translate }}</button>
</ng-container>
</div>
</ng-template>
</div>
Expand Down

0 comments on commit 596cbee

Please sign in to comment.