Skip to content

Commit

Permalink
Showing 13 changed files with 16 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
@@ -3,7 +3,7 @@
## [UNRELEASED]

- Display a better error message when encountering a workflow that runs the `codeql-action/init` action multiple times. [#876](https://github.com/github/codeql-action/pull/876)
- Add better error message is the workflow does not have security-events write permissions. [#882](https://github.com/github/codeql-action/pull/882)
- Add better error message is the workflow does not have the `security-events: write` permission. [#882](https://github.com/github/codeql-action/pull/882)

## 1.0.29 - 21 Jan 2022

5 changes: 0 additions & 5 deletions lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze-action.js.map

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions lib/feature-flags.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init-action.js.map
6 changes: 0 additions & 6 deletions src/analyze-action.ts
@@ -111,12 +111,6 @@ async function run() {
repositoryNwo,
logger
);
// We currently perform an API request in both the `init` and `analyze` Actions to determine
// what feature flags are enabled. At the time of writing, this redundant API call is acceptable
// to us, but if we wanted to avoid it, we could do so by serializing the feature flags as part
// of the config file.
void featureFlags.preloadFeatureFlags();

await runFinalize(outputDir, threads, memory, config, logger);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
runStats = await runQueries(
20 changes: 0 additions & 20 deletions src/feature-flags.test.ts
@@ -102,26 +102,6 @@ test("Feature flags are disabled if they're not returned in API response", async
});
});

test("Feature flags exception is propagated if the API request errors", async (t) => {
await withTmpDir(async (tmpDir) => {
setupActionsVars(tmpDir, tmpDir);

const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRunnerLogger(true)
);

mockFeatureFlagApiEndpoint(500, {});

await t.throwsAsync(async () => featureFlags.preloadFeatureFlags(), {
message:
"Encountered an error while trying to load feature flags: Error: some error message",
});
});
});

const FEATURE_FLAGS = [
"database_uploads_enabled",
"ml_powered_queries_enabled",
19 changes: 6 additions & 13 deletions src/feature-flags.ts
@@ -42,10 +42,6 @@ export class GitHubFeatureFlags implements FeatureFlags {
return response;
}

async preloadFeatureFlags(): Promise<void> {
await this.getApiResponse();
}

private async getApiResponse(): Promise<FeatureFlagsApiResponse> {
const loadApiResponse = async () => {
// Do nothing when not running against github.com
@@ -66,15 +62,12 @@ export class GitHubFeatureFlags implements FeatureFlags {
);
return response.data;
} catch (e) {
if (
e instanceof Error &&
e.message.includes("Resource not accessible by integration")
) {
throw new Error(
`Resource not accessible by integration. This usually means that your ` +
`workflow is missing the required security-events write permissions. ` +
`See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions ` +
`for more information.`
if (util.isHTTPError(e) && e.status === 403) {
this.logger.warning(
"This run of the CodeQL Action does not have permission to access Code Scanning API endpoints. " +
"As a result, it will not be opted into any experimental features. " +
"This could be because the Action is running on a pull request from a fork. If not, " +
`please ensure the Action has the 'security-events: write' permission. Details: ${e}`
);
} else {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.
2 changes: 0 additions & 2 deletions src/init-action.ts
@@ -145,8 +145,6 @@ async function run() {
);

try {
await featureFlags.preloadFeatureFlags();

const workflowErrors = await validateWorkflow();

if (

0 comments on commit f18151c

Please sign in to comment.