8000 getFileDiffsWithBasehead(): use CODE_SCANNING_REPOSITORY if present by cklin · Pull Request #2830 · github/codeql-action · GitHub
[go: up one dir, main page]

Skip to content

getFileDiffsWithBasehead(): use CODE_SCANNING_REPOSITORY if present #2830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use getRepositoryNwo()
  • Loading branch information
cklin committed Mar 26, 2025
commit f88459c0a3ae3430060d6464a121d192dbc2cf1a
8 changes: 3 additions & 5 deletions src/analyze-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { EnvVar } from "./environment";
import { Features } from "./feature-flags";
import { Language } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import * as statusReport from "./status-report";
import {
ActionName,
Expand Down Expand Up @@ -251,9 +251,7 @@ async function run() {
logger,
);

const repositoryNwo = parseRepositoryNwo(
util.getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();

const gitHubVersion = await getGitHubVersion();

Expand Down Expand Up @@ -359,7 +357,7 @@ async function run() {
actionsUtil.getRequiredInput("wait-for-processing") === "true"
) {
await uploadLib.waitForProcessing(
parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY")),
getRepositoryNwo(),
uploadResult.sarifID,
getActionsLogger(),
);
Expand Down
9 changes: 4 additions & 5 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { EnvVar } from "./environment";
import { FeatureEnablement, Feature } from "./feature-flags";
import { isScannedLanguage, Language } from "./languages";
import { Logger, withGroupAsync } from "./logging";
import { getRepositoryNwo } from "./repository";
import { DatabaseCreationTimings, EventReport } from "./status-report";
import { ToolsFeature } from "./tools-features";
import { endTracingForCluster } from "./tracer-config";
Expand Down Expand Up @@ -389,15 +390,13 @@ async function getFileDiffsWithBasehead(
branches: PullRequestBranches,
logger: Logger,
): Promise<FileDiff[] | undefined> {
const ownerRepo = util.getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
const owner = ownerRepo[0];
const repo = ownerRepo[1];
const repositoryNwo = getRepositoryNwo();
const basehead = `${branches.base}...${branches.head}`;
try {
const response = await getApiClient().rest.repos.compareCommitsWithBasehead(
{
owner,
repo,
owner: repositoryNwo.owner,
repo: repositoryNwo.repo,
basehead,
per_page: 1,
},
Expand Down
18 changes: 6 additions & 12 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as retry from "@octokit/plugin-retry";
import consoleLogLevel from "console-log-level";

import { getActionVersion, getRequiredInput } from "./actions-util";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import {
ConfigurationError,
getRequiredEnvParam,
Expand Down Expand Up @@ -123,17 +123,15 @@ export async function getGitHubVersion(): Promise<GitHubVersion> {
* Get the path of the currently executing workflow relative to the repository root.
*/
export async function getWorkflowRelativePath(): Promise<string> {
const repo_nwo = getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
const owner = repo_nwo[0];
const repo = repo_nwo[1];
const repo_nwo = getRepositoryNwo();
const run_id = Number(getRequiredEnvParam("GITHUB_RUN_ID"));

const apiClient = getApiClient();
const runsResponse = await apiClient.request(
"GET /repos/:owner/:repo/actions/runs/:run_id?exclude_pull_requests=true",
{
owner,
repo,
owner: repo_nwo.owner,
repo: repo_nwo.repo,
run_id,
},
);
Expand Down Expand Up @@ -218,9 +216,7 @@ export async function listActionsCaches(
key: string,
ref: string,
): Promise<ActionsCacheItem[]> {
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();

return await getApiClient().paginate(
"GET /repos/{owner}/{repo}/actions/caches",
Expand All @@ -235,9 +231,7 @@ export async function listActionsCaches(

/** Delete an Actions cache item by its ID. */
export async function deleteActionsCache(id: number) {
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();

await getApiClient().rest.actions.deleteActionsCacheById({
owner: repositoryNwo.owner,
Expand Down
8 changes: 3 additions & 5 deletions src/autobuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { EnvVar } from "./environment";
import { Feature, featureConfig, Features } from "./feature-flags";
import { isTracedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import { ToolsFeature } from "./tools-features";
import { BuildMode, getRequiredEnvParam } from "./util";
import { BuildMode } from "./util";

export async function determineAutobuildLanguages(
codeql: CodeQL,
Expand Down Expand Up @@ -117,9 +117,7 @@ export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
const envVar = featureConfig[Feature.CppDependencyInstallation].envVar;
const featureName = "C++ automatic installation of dependencies";
const gitHubVersion = await getGitHubVersion();
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();
const features = new Features(
gitHubVersion,
repositoryNwo,
Expand Down
6 changes: 2 additions & 4 deletions src/init-action-post-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Config } from "./config-utils";
import { EnvVar } from "./environment";
import { Feature, FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
import { RepositoryNwo, parseRepositoryNwo } from "./repository";
import { RepositoryNwo, getRepositoryNwo } from "./repository";
import { JobStatus } from "./status-report";
import * as uploadLib from "./upload-lib";
import {
Expand Down Expand Up @@ -255,9 +255,7 @@ async function removeUploadedSarif(
const client = getApiClient();

try {
const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();

// Wait to make sure the analysis is ready for download before requesting it.
await delay(5000);
Expand Down
13 changes: 3 additions & 10 deletions src/init-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as debugArtifacts from "./debug-artifacts";
import { Features } from "./feature-flags";
import * as initActionPostHelper from "./init-action-post-helper";
import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import {
StatusReportBase,
sendStatusReport,
Expand All @@ -26,12 +26,7 @@ import {
ActionName,
getJobStatusDisplayName,
} from "./status-report";
import {
checkDiskUsage,
checkGitHubVersionInRange,
getRequiredEnvParam,
wrapError,
} from "./util";
import { checkDiskUsage, checkGitHubVersionInRange, wrapError } from "./util";

interface InitPostStatusReport
extends StatusReportBase,
Expand All @@ -52,9 +47,7 @@ async function runWrapper() {
const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);

const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();
const features = new Features(
gitHubVersion,
repositoryNwo,
Expand Down
6 changes: 2 additions & 4 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import { Language } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import { OverlayDatabaseMode } from "./overlay-database-utils";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import { ToolsSource } from "./setup-codeql";
import {
ActionName,
Expand Down Expand Up @@ -281,9 +281,7 @@ async function run() {
checkGitHubVersionInRange(gitHubVersion, logger);
checkActionVersion(getActionVersion(), gitHubVersion);

const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();

const features = new Features(
gitHubVersion,
Expand Down
8 changes: 4 additions & 4 deletions src/status-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DocUrl } from "./doc-url";
import { EnvVar } from "./environment";
import { getRef } from "./git-utils";
import { Logger } from "./logging";
import { getRepositoryNwo } from "./repository";
import {
ConfigurationError,
isHTTPError,
Expand Down Expand Up @@ -393,16 +394,15 @@ export async function sendStatusReport<S extends StatusReportBase>(
return;
}

const nwo = getRequiredEnvParam("GITHUB_REPOSITORY");
const [owner, repo] = nwo.split("/");
const nwo = getRepositoryNwo();
const client = getApiClient();

try {
await client.request(
"PUT /repos/:owner/:repo/code-scanning/analysis/status",
{
owner,
repo,
owner: nwo.owner,
repo: nwo.repo,
data: statusReportJSON,
},
);
Expand Down
8 changes: 2 additions & 6 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as fingerprints from "./fingerprints";
import * as gitUtils from "./git-utils";
import { initCodeQL } from "./init";
import { Logger } from "./logging";
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
import { getRepositoryNwo, RepositoryNwo } from "./repository";
import { ToolsFeature } from "./tools-features";
import * as util from "./util";
import {
Expand Down Expand Up @@ -624,11 +624,7 @@ export async function uploadFiles(
logger.debug(`Number of results in upload: ${numResultInSarif}`);

// Make the upload
const sarifID = await uploadPayload(
payload,
parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY")),
logger,
);
const sarifID = await uploadPayload(payload, getRepositoryNwo(), logger);

logger.endGroup();

Expand Down
9 changes: 3 additions & 6 deletions src/upload-sarif-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getActionVersion, getTemporaryDirectory } from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { Features } from "./feature-flags";
import { Logger, getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { getRepositoryNwo } from "./repository";
import {
createStatusReportBase,
sendStatusReport,
Expand All @@ -20,7 +20,6 @@ import {
checkActionVersion,
checkDiskUsage,
getErrorMessage,
getRequiredEnvParam,
initializeEnvironment,
isInTestMode,
wrapError,
Expand Down Expand Up @@ -63,9 +62,7 @@ async function run() {
// Make inputs accessible in the `post` step.
actionsUtil.persistInputs();

const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY"),
);
const repositoryNwo = getRepositoryNwo();
const features = new Features(
gitHubVersion,
repositoryNwo,
Expand Down Expand Up @@ -100,7 +97,7 @@ async function run() {
core.debug("In test mode. Waiting for processing is disabled.");
} else if (actionsUtil.getRequiredInput("wait-for-processing") === "true") {
await upload_lib.waitForProcessing(
parseRepositoryNwo(getRequiredEnvParam("GITHUB_REPOSITORY")),
getRepositoryNwo(),
uploadResult.sarifID,
logger,
);
Expand Down
0