Address fedback
This commit is contained in:
@@ -707,7 +707,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- run: echo \${{ job.container.| }}
|
- run: echo \${{ job.container.| }}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
expect(result.map(x => x.label)).toEqual(["id", "network"]);
|
expect(result.map(x => x.label)).toEqual(["id", "network"]);
|
||||||
});
|
});
|
||||||
@@ -727,7 +727,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- run: echo \${{ job.services.| }}
|
- run: echo \${{ job.services.| }}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
expect(result.map(x => x.label)).toEqual(["nginx", "redis"]);
|
expect(result.map(x => x.label)).toEqual(["nginx", "redis"]);
|
||||||
});
|
});
|
||||||
@@ -748,7 +748,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- run: echo \${{ job.services.nginx.| }}
|
- run: echo \${{ job.services.nginx.| }}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
expect(result.map(x => x.label)).toEqual(["id", "network", "ports"]);
|
expect(result.map(x => x.label)).toEqual(["id", "network", "ports"]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {data} from "@github/actions-expressions";
|
import {data} from "@github/actions-expressions";
|
||||||
import {isMapping, isSequence, isString} from "@github/actions-workflow-parser";
|
import {isMapping, isSequence} from "@github/actions-workflow-parser";
|
||||||
import { MappingToken } from "@github/actions-workflow-parser/templates/tokens/mapping-token";
|
import {MappingToken} from "@github/actions-workflow-parser/templates/tokens/mapping-token";
|
||||||
import {WorkflowContext} from "../context/workflow-context";
|
import {WorkflowContext} from "../context/workflow-context";
|
||||||
|
|
||||||
export function getJobContext(workflowContext: WorkflowContext): data.Dictionary {
|
export function getJobContext(workflowContext: WorkflowContext): data.Dictionary {
|
||||||
@@ -8,7 +8,7 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
|
|||||||
const jobContext = new data.Dictionary();
|
const jobContext = new data.Dictionary();
|
||||||
const job = workflowContext.job;
|
const job = workflowContext.job;
|
||||||
if (!job) {
|
if (!job) {
|
||||||
return jobContext
|
return jobContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container
|
// Container
|
||||||
@@ -24,7 +24,7 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
|
|||||||
const servicesContext = new data.Dictionary();
|
const servicesContext = new data.Dictionary();
|
||||||
for (const service of jobServices) {
|
for (const service of jobServices) {
|
||||||
if (!isMapping(service.value)) {
|
if (!isMapping(service.value)) {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
const serviceContext = createContainerContext(service.value, true);
|
const serviceContext = createContainerContext(service.value, true);
|
||||||
servicesContext.add(service.key.toString(), serviceContext);
|
servicesContext.add(service.key.toString(), serviceContext);
|
||||||
@@ -40,30 +40,28 @@ export function getJobContext(workflowContext: WorkflowContext): data.Dictionary
|
|||||||
|
|
||||||
function createContainerContext(container: MappingToken, isServices: boolean): data.Dictionary {
|
function createContainerContext(container: MappingToken, isServices: boolean): data.Dictionary {
|
||||||
const containerContext = new data.Dictionary();
|
const containerContext = new data.Dictionary();
|
||||||
for (const token of container) {
|
for (const {key, value} of container) {
|
||||||
if (isSequence(token.value)) {
|
if (isSequence(value)) {
|
||||||
// service ports are the only thing that is part of the job context
|
// service ports are the only thing that is part of the job context
|
||||||
if (token.key.toString() !== "ports") {
|
if (key.toString() !== "ports") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const ports = new data.Dictionary()
|
const ports = new data.Dictionary();
|
||||||
for (const item of token.value) {
|
for (const item of value) {
|
||||||
// We can determine the context mapping fully only if the port is defined
|
// We can determine the context mapping fully only if the port is defined
|
||||||
// as a mapping (i.e. <port1>:<port2>), single ports are assigned randomly
|
// as a mapping (i.e. <port1>:<port2>), single ports are assigned randomly
|
||||||
const portParts = item.toString().split(":")
|
const portParts = item.toString().split(":");
|
||||||
if (isServices && portParts.length === 2) {
|
if (isServices && portParts.length === 2) {
|
||||||
ports.add(portParts[1], new data.StringData(portParts[0]));
|
ports.add(portParts[1], new data.StringData(portParts[0]));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// If the port isn't a mapping, just use null
|
// If the port isn't a mapping, just use null
|
||||||
ports.add(portParts[0], new data.Null());
|
ports.add(portParts[0], new data.Null());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
containerContext.add(token.key.toString(), ports);
|
containerContext.add(key.toString(), ports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
containerContext.add("id", new data.Null());
|
containerContext.add("id", new data.Null());
|
||||||
containerContext.add("network", new data.Null());
|
containerContext.add("network", new data.Null());
|
||||||
return containerContext;
|
return containerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user