Skip to content

Commit 7cbb19e

Browse files
committed
Refactor minimalInitCodeQL out of combineSarifFilesUsingCLI
1 parent c4dca28 commit 7cbb19e

File tree

5 files changed

+144
-129
lines changed

5 files changed

+144
-129
lines changed

lib/analyze-action.js

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 28 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as actionsUtil from "./actions-util";
1111
import * as analyses from "./analyses";
1212
import * as api from "./api-client";
1313
import { getGitHubVersion, wrapApiConfigurationError } from "./api-client";
14-
import { CodeQL, getCodeQL } from "./codeql";
14+
import { getCodeQL, type CodeQL } from "./codeql";
1515
import { getConfig } from "./config-utils";
1616
import { readDiffRangesJsonFile } from "./diff-informed-analysis-utils";
1717
import { EnvVar } from "./environment";
@@ -183,6 +183,42 @@ async function shouldDisableCombineSarifFiles(
183183
return true;
184184
}
185185

186+
/**
187+
* Initialises a `CodeQL` instance that we can use to combine SARIF files.
188+
*/
189+
export async function minimalInitCodeQL(
190+
logger: Logger,
191+
gitHubVersion: GitHubVersion,
192+
features: FeatureEnablement,
193+
): Promise<CodeQL> {
194+
logger.info(
195+
"Initializing CodeQL since the 'init' Action was not called before this step.",
196+
);
197+
198+
const apiDetails = {
199+
auth: actionsUtil.getRequiredInput("token"),
200+
externalRepoAuth: actionsUtil.getOptionalInput("external-repository-token"),
201+
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
202+
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
203+
};
204+
205+
const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
206+
gitHubVersion.type,
207+
);
208+
209+
const initCodeQLResult = await initCodeQL(
210+
undefined, // There is no tools input on the upload action
211+
apiDetails,
212+
actionsUtil.getTemporaryDirectory(),
213+
gitHubVersion.type,
214+
codeQLDefaultVersionInfo,
215+
features,
216+
logger,
217+
);
218+
219+
return initCodeQLResult.codeql;
220+
}
221+
186222
// Takes a list of paths to sarif files and combines them together using the
187223
// CLI `github merge-results` command when all SARIF files are produced by
188224
// CodeQL. Otherwise, it will fall back to combining the files in the action.
@@ -239,34 +275,7 @@ async function combineSarifFilesUsingCLI(
239275
codeQL = await getCodeQL(config.codeQLCmd);
240276
tempDir = config.tempDir;
241277
} else {
242-
logger.info(
243-
"Initializing CodeQL since the 'init' Action was not called before this step.",
244-
);
245-
246-
const apiDetails = {
247-
auth: actionsUtil.getRequiredInput("token"),
248-
externalRepoAuth: actionsUtil.getOptionalInput(
249-
"external-repository-token",
250-
),
251-
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
252-
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
253-
};
254-
255-
const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
256-
gitHubVersion.type,
257-
);
258-
259-
const initCodeQLResult = await initCodeQL(
260-
undefined, // There is no tools input on the upload action
261-
apiDetails,
262-
tempDir,
263-
gitHubVersion.type,
264-
codeQLDefaultVersionInfo,
265-
features,
266-
logger,
267-
);
268-
269-
codeQL = initCodeQLResult.codeql;
278+
codeQL = await minimalInitCodeQL(logger, gitHubVersion, features);
270279
}
271280

272281
const baseTempDir = path.resolve(tempDir, "combined-sarif");

0 commit comments

Comments
 (0)