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