8000 fix: allow manual run (#4310) · ovh/cds@cd12774 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cd12774

Browse files
sguiheuxrichardlt
authored andcommitted
fix: allow manual run (#4310)
1 parent 5f39550 commit cd12774

File tree

6 files changed

+123
-13
lines changed

6 files changed

+123
-13
lines changed

engine/api/workflow_trigger.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func (api *API) getWorkflowTriggerConditionHandler() service.Handler {
5757
if errp != nil {
5858
return sdk.WrapError(errp, "getWorkflowTriggerConditionHandler> Unable to load build parameters from workflow run")
5959
}
60+
if len(params) == 0 {
61+
refNode = nil
62+
}
6063
}
6164
if refNode == nil {
6265
refNode = wf.WorkflowData.NodeByID(id)
@@ -82,16 +85,14 @@ func (api *API) getWorkflowTriggerConditionHandler() service.Handler {
8285
return sdk.WrapError(sdk.ErrWorkflowNodeNotFound, "getWorkflowTriggerConditionHandler> Unable to load workflow node")
8386
}
8487

85-
if (wr == nil && refNode.IsLinkedToRepo(wf)) || (wr != nil && refNode.IsLinkedToRepo(&wr.Workflow)) {
86-
if sdk.ParameterFind(&params, "git.repository") == nil {
87-
data.ConditionNames = append(data.ConditionNames, "git.repository")
88-
data.ConditionNames = append(data.ConditionNames, "git.branch")
89-
data.ConditionNames = append(data.ConditionNames, "git.message")
90-
data.ConditionNames = append(data.ConditionNames, "git.author")
91-
data.ConditionNames = append(data.ConditionNames, "git.hash")
92-
data.ConditionNames = append(data.ConditionNames, "git.hash.short")
93-
data.ConditionNames = append(data.ConditionNames, "git.tag")
94-
}
88+
if sdk.ParameterFind(&params, "git.repository") == nil {
89+
data.ConditionNames = append(data.ConditionNames, "git.repository")
90+
data.ConditionNames = append(data.ConditionNames, "git.branch")
91+
data.ConditionNames = append(data.ConditionNames, "git.message")
92+
data.ConditionNames = append(data.ConditionNames, "git.author")
93+
data.ConditionNames = append(data.ConditionNames, "git.hash")
94+
data.ConditionNames = append(data.ConditionNames, "git.hash.short")
95+
data.ConditionNames = append(data.ConditionNames, "git.tag")
9596
}
9697

9798
for _, p := range params {

ui/src/app/model/workflow.model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ export class Workflow {
310310

311311
static getParentNodeIds(workflowRun: WorkflowRun, currentNodeID: number): number[] {
312312
let ancestors = new Array<number>();
313-
314313
let nodes = Workflow.getAllNodes(workflowRun.workflow);
315314
if (nodes) {
316315
loop: for (let i = 0; i < nodes.length; i++) {
@@ -337,6 +336,9 @@ export class Workflow {
337336
}
338337
}
339338
}
339+
if (n.id === currentNodeID && n.type === WNodeType.JOIN) {
340+
ancestors.push(...n.parents.map(p => p.parent_id));
341+
}
340342
}
341343
}
342344
return ancestors;

ui/src/app/shared/workflow/menu/edit-node/menu.edit.node.component.ts

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import {
55
Output
66
} from '@angular/core';
77
import {PermissionValue} from 'app/model/permission.model';
8+
import { PipelineStatus } from 'app/model/pipeline.model';
89
import { Project } from 'app/model/project.model';
910
import {
1011
WNode,
1112
Workflow,
1213
} from 'app/model/workflow.model';
13-
import {WorkflowNodeRun} from 'app/model/workflow.run.model';
14+
import { WorkflowNodeRun, WorkflowRun } from 'app/model/workflow.run.model';
1415
import {AutoUnsubscribe} from 'app/shared/decorator/autoUnsubscribe';
1516
import {IPopup} from 'ng2-semantic-ui';
1617

@@ -27,16 +28,98 @@ export class WorkflowWNodeMenuEditComponent {
2728
@Input() project: Project;
2829
@Input() workflow: Workflow;
2930
@Input() node: WNode;
30-
@Input() noderun: WorkflowNodeRun;
31+
_noderun: WorkflowNodeRun;
32+
@Input('noderun') set noderun(data: WorkflowNodeRun) {
33+
this._noderun = data;
34+
this.runnable = this.getCanBeRun();
35+
}
36+
get noderun() {return this._noderun}
37+
38+
_workflowrun: WorkflowRun;
39+
@Input('workflowrun') set workflowrun(data: WorkflowRun) {
40+
this._workflowrun = data;
41+
this.runnable = this.getCanBeRun();
42+
}
43+
get workflowrun() { return this._workflowrun}
44+
3145
@Input() popup: IPopup;
3246
@Input() readonly = true;
3347
@Output() event = new EventEmitter<string>();
3448
permissionEnum = PermissionValue;
49+
runnable: boolean;
3550

3651
constructor() {}
3752

3853
sendEvent(e: string): void {
3954
this.popup.close();
4055
this.event.emit(e);
4156
}
57+
58+
getCanBeRun(): boolean {
59+
if (!this.workflow) {
60+
return;
61+
}
62+
63+
// Get Env permission
64+
let envForbid = this.node && this.node.context && this.node.context.environment_id > 1
65+
&& this.workflow.environments && this.workflow.environments[this.node.context.environment_id]
66+
&& this.workflow.environments[this.node.context.environment_id].permission
67+
&& this.workflow.environments[this.node.context.environment_id].permission < PermissionValue.READ_EXECUTE;
68+
69+
if (this.workflow && this.workflow.permission < PermissionValue.READ_EXECUTE || envForbid) {
70+
return false;
71+
}
72+
73+
// If we are in a run, check if current node can be run ( compuite by cds api)
74+
if (this.noderun && this.workflowrun && this.workflowrun.nodes) {
75+
let nodesRun = this.workflowrun.nodes[this.noderun.workflow_node_id];
76+
if (nodesRun) {
77+
let nodeRun = nodesRun.find(n => {
78+
return n.id === this.noderun.id;
79+
});
80+
if (nodeRun) {
81+
return nodeRun.can_be_run;
82+
}
83+
}
84+
return false;
85+
}
86+
87+
let workflowrunIsNotActive = this.workflowrun && !PipelineStatus.isActive(this.workflowrun.status);
88+
if (workflowrunIsNotActive && this.noderun) {
89+
return true;
90+
}
91+
92+
if (this.node && this.workflowrun) {
93+
if (workflowrunIsNotActive && !this.noderun &&
94+
this.node.id === this.workflowrun.workflow.workflow_data.node.id) {
95+
return true;
96+
}
97+
98+
if (this.workflowrun) {
99+
let nbNodeFound = 0;
100+
let parentNodes = Workflow.getParentNodeIds(this.workflowrun, this.node.id);
101+
for (let parentNodeId of parentNodes) {
102+
for (let nodeRunId in this.workflowrun.nodes) {
103+
if (!this.workflowrun.nodes[nodeRunId]) {
104+
continue;
105+
}
106+
let nodeRuns = this.workflowrun.nodes[nodeRunId];
107+
if (nodeRuns[0].workflow_node_id === parentNodeId) { // if node id is still the same
108+
if (PipelineStatus.isActive(nodeRuns[0].status)) {
109+
return false;
110+
}
111+
nbNodeFound++;
112+
} else if (!Workflow.getNodeByID(nodeRuns[0].workflow_node_id, this.workflowrun.workflow)) {
113+
// workflow updated so prefer return true
114+
return true;
115+
}
116+
}
117+
}
118+
if (nbNodeFound !== parentNodes.length) { // It means that a parent node isn't already executed
119+
return false;
120+
}
121+
}
122+
}
123+
return true;
124+
}
42125
}

ui/src/app/shared/workflow/menu/edit-node/menu.edit.node.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<div class="menu-node">
22
<div class="ui list">
3+
<ng-container *ngIf="workflowrun">
4+
<a class="item" (click)="sendEvent('run')" [class.disabled]="!runnable">
5+
{{'btn_run' | translate }}
6+
</a>
7+
<hr>
8+
</ng-container>
39
<ng-container *ngIf="!noderun">
410
<a class="item" (click)="sendEvent('pipeline')"
511
[class.disabled]="(workflow.from_repository && workflow.from_repository.length > 0) || readonly">

ui/src/app/shared/workflow/wnode/wnode.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {WorkflowDeleteNodeComponent} from 'app/shared/workflow/modal/delete/work
1515
import {WorkflowHookModalComponent} from 'app/shared/workflow/modal/hook-add/hook.modal.component';
1616
import {WorkflowTriggerComponent} from 'app/shared/workflow/modal/node-add/workflow.trigger.component';
1717
import {WorkflowNodeEditModalComponent} from 'app/shared/workflow/modal/node-edit/node.edit.modal.component';
18+
import { WorkflowNodeRunParamComponent } from 'app/shared/workflow/node/run/node.run.param.component';
1819
import {
1920
AddHookWorkflow,
2021
AddJoinWorkflow,
@@ -42,6 +43,8 @@ export class WorkflowWNodeComponent implements OnInit {
4243

4344
@ViewChild('menu')
4445
menu: WorkflowWNodeMenuEditComponent;
46+
@ViewChild('workflowRunNode')
47+
workflowRunNode: WorkflowNodeRunParamComponent;
4548

4649
// Selected workflow run
4750
workflowRun: WorkflowRun;
@@ -174,6 +177,9 @@ export class WorkflowWNodeComponent implements OnInit {
174177
case 'join_link':
175178
this.linkJoin();
176179
break;
180+
case 'run':
181+
this.run();
182+
break;
177183
case 'delete':
178184
this.openDeleteNodeModal();
179185
break;
@@ -322,4 +328,8 @@ export class WorkflowWNodeComponent implements OnInit {
322328
}
323329
this._workflowCoreService.linkJoinEvent(this.node);
324330
}
331+
332+
run(): void {
333+
this.workflowRunNode.show();
334+
}
325335
}

ui/src/app/shared/workflow/wnode/workflow.node.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<app-workflow-menu-wnode-edit (event)="receivedEvent($event)"
1919
[project]="project"
2020
[workflow]="workflow" [node]="node" [popup]="popup"
21+
[workflowrun]="workflowRun"
2122
[noderun]="currentNodeRun"
2223
[readonly]="readonly" #menu></app-workflow-menu-wnode-edit>
2324
</ng-template>
@@ -35,4 +36,11 @@
3536
<!-- Delete Node -->
3637
<app-workflow-node-delete [loading]="loading" [node]="node" [workflow]="workflow" (deleteEvent)="updateWorkflow($event, workflowDeleteNode.modal)"
3738
#workflowDeleteNode></app-workflow-node-delete>
39+
40+
<ng-container *ngIf="project && node && workflowRun">
41+
<app-workflow-node-run-param [workflow]="workflow" [project]="project" [nodeRun]="currentNodeRun"
42+
[workflowRun]="workflowRun" [nodeToRun]="node" [num]="workflowRun.num" #workflowRunNode>
43+
</app-workflow-node-run-param>
44+
</ng-container>
45+
3846
</ng-container>

0 commit comments

Comments
 (0)
0