Merge pull request #176 from github/elbrenn/called-secret-complete
Convert secrets, complete secrets in called workflow
This commit is contained in:
@@ -540,6 +540,28 @@ jobs:
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("secrets", async () => {
|
||||
const input = `
|
||||
on:
|
||||
workflow_call:
|
||||
secrets:
|
||||
secret1:
|
||||
required: true
|
||||
description: "first secret"
|
||||
secret2:
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/deploy@v100
|
||||
with:
|
||||
deploy-key: \${{ secrets.|
|
||||
`;
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input), {contextProviderConfig});
|
||||
expect(result.map(x => x.label)).toEqual(["GITHUB_TOKEN", "secret1", "secret2"]);
|
||||
});
|
||||
|
||||
describe("github context", () => {
|
||||
it("includes expected keys", async () => {
|
||||
const input = `
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import {DescriptionDictionary} from "@github/actions-expressions";
|
||||
import {WorkflowContext} from "../context/workflow-context";
|
||||
import {Mode} from "./default";
|
||||
|
||||
export type ContextProviderConfig = {
|
||||
getContext: (
|
||||
name: string,
|
||||
defaultContext: DescriptionDictionary | undefined,
|
||||
workflowContext: WorkflowContext
|
||||
workflowContext: WorkflowContext,
|
||||
mode: Mode
|
||||
) => Promise<DescriptionDictionary | undefined>;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import {getJobContext} from "./job";
|
||||
import {getJobsContext} from "./jobs";
|
||||
import {getMatrixContext} from "./matrix";
|
||||
import {getNeedsContext} from "./needs";
|
||||
import {getSecretsContext} from "./secrets";
|
||||
import {getStepsContext} from "./steps";
|
||||
import {getStrategyContext} from "./strategy";
|
||||
|
||||
@@ -39,7 +40,7 @@ export async function getContext(
|
||||
continue;
|
||||
}
|
||||
|
||||
value = (await config?.getContext(contextName, value, workflowContext)) || value;
|
||||
value = (await config?.getContext(contextName, value, workflowContext, mode)) || value;
|
||||
|
||||
context.add(contextName, value, getDescription(RootContext, contextName));
|
||||
}
|
||||
@@ -81,11 +82,7 @@ function getDefaultContext(name: string, workflowContext: WorkflowContext, mode:
|
||||
});
|
||||
|
||||
case "secrets":
|
||||
return new DescriptionDictionary({
|
||||
key: "GITHUB_TOKEN",
|
||||
value: new data.StringData("***"),
|
||||
description: getDescription("secrets", "GITHUB_TOKEN")
|
||||
});
|
||||
return getSecretsContext(workflowContext, mode);
|
||||
|
||||
case "steps":
|
||||
return getStepsContext(workflowContext);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import {data, DescriptionDictionary} from "@github/actions-expressions";
|
||||
import {StringData} from "@github/actions-expressions/data/string";
|
||||
import {WorkflowContext} from "../context/workflow-context";
|
||||
import {Mode} from "./default";
|
||||
import {getDescription} from "./descriptions";
|
||||
|
||||
export function getSecretsContext(workflowContext: WorkflowContext, mode: Mode): DescriptionDictionary {
|
||||
const d = new DescriptionDictionary({
|
||||
key: "GITHUB_TOKEN",
|
||||
value: new data.StringData("***"),
|
||||
description: getDescription("secrets", "GITHUB_TOKEN")
|
||||
});
|
||||
|
||||
if (mode === Mode.Completion) {
|
||||
const eventsConfig = workflowContext?.template?.events;
|
||||
if (eventsConfig?.workflow_call?.secrets) {
|
||||
for (const [name, value] of Object.entries(eventsConfig.workflow_call.secrets)) {
|
||||
d.add(name, new StringData(""), value.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
Reference in New Issue
Block a user