Add copilot-requests permission, gated by feature flag (#335)
* Add copilot-requests permission gated by feature flag This add a new 'copilot-requests' permission to the workflow schema, gated behind the 'allowCopilotRequestsPermission' experimental feature flag. When the flag is disabled (default), `copilot-requests` is filtered out of autocomplete suggestions. When enabled, it appears alongside other permissions like actions, contents, pull-requests, etc. * Update workflow-parser/src/workflow-v1.0.json * Add additional unit test coverage * Fix formatting
This commit is contained in:
@@ -55,7 +55,8 @@ describe("FeatureFlags", () => {
|
||||
"missingInputsQuickfix",
|
||||
"blockScalarChompingWarning",
|
||||
"allowCaseFunction",
|
||||
"allowCronTimezone"
|
||||
"allowCronTimezone",
|
||||
"allowCopilotRequestsPermission"
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,6 +40,12 @@ export interface ExperimentalFeatures {
|
||||
* @default false
|
||||
*/
|
||||
allowCronTimezone?: boolean;
|
||||
|
||||
/**
|
||||
* Enable the copilot-requests permission in workflow permissions.
|
||||
* @default false
|
||||
*/
|
||||
allowCopilotRequestsPermission?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +61,8 @@ const allFeatureKeys: ExperimentalFeatureKey[] = [
|
||||
"missingInputsQuickfix",
|
||||
"blockScalarChompingWarning",
|
||||
"allowCaseFunction",
|
||||
"allowCronTimezone"
|
||||
"allowCronTimezone",
|
||||
"allowCopilotRequestsPermission"
|
||||
];
|
||||
|
||||
export class FeatureFlags {
|
||||
|
||||
@@ -967,3 +967,79 @@ describe("schedule timezone completion", () => {
|
||||
expect(labels).not.toContain("timezone");
|
||||
});
|
||||
});
|
||||
|
||||
describe("permissions copilot-requests completion", () => {
|
||||
it("includes copilot-requests when allowCopilotRequestsPermission is enabled", async () => {
|
||||
const input = `on: push
|
||||
permissions:
|
||||
|`;
|
||||
const result = await complete(...getPositionFromCursor(input), {
|
||||
featureFlags: new FeatureFlags({allowCopilotRequestsPermission: true})
|
||||
});
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
const labels = result.map(x => x.label);
|
||||
expect(labels).toContain("actions");
|
||||
expect(labels).toContain("copilot-requests");
|
||||
});
|
||||
|
||||
it("excludes copilot-requests when allowCopilotRequestsPermission is disabled", async () => {
|
||||
const input = `on: push
|
||||
permissions:
|
||||
|`;
|
||||
const result = await complete(...getPositionFromCursor(input), {
|
||||
featureFlags: new FeatureFlags({allowCopilotRequestsPermission: false})
|
||||
});
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
const labels = result.map(x => x.label);
|
||||
expect(labels).toContain("actions");
|
||||
expect(labels).not.toContain("copilot-requests");
|
||||
});
|
||||
|
||||
it("excludes copilot-requests when no feature flags are provided", async () => {
|
||||
const input = `on: push
|
||||
permissions:
|
||||
|`;
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
const labels = result.map(x => x.label);
|
||||
expect(labels).toContain("actions");
|
||||
expect(labels).not.toContain("copilot-requests");
|
||||
});
|
||||
|
||||
it("includes copilot-requests in job-level permissions when allowCopilotRequestsPermission is enabled", async () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
|`;
|
||||
const result = await complete(...getPositionFromCursor(input), {
|
||||
featureFlags: new FeatureFlags({allowCopilotRequestsPermission: true})
|
||||
});
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
const labels = result.map(x => x.label);
|
||||
expect(labels).toContain("actions");
|
||||
expect(labels).toContain("copilot-requests");
|
||||
});
|
||||
|
||||
it("excludes copilot-requests from job-level permissions when allowCopilotRequestsPermission is disabled", async () => {
|
||||
const input = `on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
|`;
|
||||
const result = await complete(...getPositionFromCursor(input), {
|
||||
featureFlags: new FeatureFlags({allowCopilotRequestsPermission: false})
|
||||
});
|
||||
|
||||
expect(result).not.toBeUndefined();
|
||||
const labels = result.map(x => x.label);
|
||||
expect(labels).toContain("actions");
|
||||
expect(labels).not.toContain("copilot-requests");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -168,6 +168,14 @@ export async function complete(
|
||||
values = values.filter(v => v.label !== "timezone");
|
||||
}
|
||||
|
||||
// Filter `copilot-requests` from permissions completions when the feature flag is disabled
|
||||
if (
|
||||
!config?.featureFlags?.isEnabled("allowCopilotRequestsPermission") &&
|
||||
parent?.definition?.key === "permissions-mapping"
|
||||
) {
|
||||
values = values.filter(v => v.label !== "copilot-requests");
|
||||
}
|
||||
|
||||
// Offer "(switch to list)" / "(switch to mapping)" when the schema allows alternative forms
|
||||
const escapeHatches = getEscapeHatchCompletions(token, keyToken, indentString, newPos, schema);
|
||||
values.push(...escapeHatches);
|
||||
|
||||
@@ -1602,6 +1602,10 @@
|
||||
"type": "permission-level-any",
|
||||
"description": "Repository contents, commits, branches, downloads, releases, and merges."
|
||||
},
|
||||
"copilot-requests": {
|
||||
"type": "permission-level-write-or-no-access",
|
||||
"description": "GitHub Copilot requests."
|
||||
},
|
||||
"deployments": {
|
||||
"type": "permission-level-any",
|
||||
"description": "Deployments and deployment statuses."
|
||||
|
||||
Reference in New Issue
Block a user