Skip to content

Commit f58d696

Browse files
committed
Move loadRepositoryProperties to properties.ts
1 parent 1f57eb0 commit f58d696

3 files changed

Lines changed: 62 additions & 66 deletions

File tree

lib/entry-points.js

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

src/feature-flags/properties.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import * as github from "@actions/github";
2+
13
import { isDynamicWorkflow } from "../actions-util";
24
import { getRepositoryProperties } from "../api-client";
35
import { Logger } from "../logging";
46
import { RepositoryNwo } from "../repository";
7+
import { Failure, getErrorMessage, Result, Success } from "../util";
58

69
/** The common prefix that we expect all of our repository properties to have. */
710
export const GITHUB_CODEQL_PROPERTY_PREFIX = "github-codeql-";
@@ -234,3 +237,35 @@ const KNOWN_REPOSITORY_PROPERTY_NAMES = new Set<string>(
234237
function isKnownPropertyName(name: string): name is RepositoryPropertyName {
235238
return KNOWN_REPOSITORY_PROPERTY_NAMES.has(name);
236239
}
240+
241+
/**
242+
* Loads [repository properties](https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization) if applicable.
243+
*/
244+
export async function loadRepositoryProperties(
245+
repositoryNwo: RepositoryNwo,
246+
logger: Logger,
247+
): Promise<Result<RepositoryProperties, unknown>> {
248+
// See if we can skip loading repository properties early. In particular,
249+
// repositories owned by users cannot have repository properties, so we can
250+
// skip the API call entirely in that case.
251+
const repositoryOwnerType = github.context.payload.repository?.owner.type;
252+
logger.debug(
253+
`Repository owner type is '${repositoryOwnerType ?? "unknown"}'.`,
254+
);
255+
if (repositoryOwnerType === "User") {
256+
logger.debug(
257+
"Skipping loading repository properties because the repository is owned by a user and " +
258+
"therefore cannot have repository properties.",
259+
);
260+
return new Success({});
261+
}
262+
263+
try {
264+
return new Success(await loadPropertiesFromApi(logger, repositoryNwo));
265+
} catch (error) {
266+
logger.warning(
267+
`Failed to load repository properties: ${getErrorMessage(error)}`,
268+
);
269+
return new Failure(error);
270+
}
271+
}

src/init-action.ts

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as fs from "fs";
22
import * as path from "path";
33

44
import * as core from "@actions/core";
5-
import * as github from "@actions/github";
65
import * as io from "@actions/io";
76
import * as semver from "semver";
87
import { v4 as uuidV4 } from "uuid";
@@ -41,10 +40,7 @@ import {
4140
} from "./diagnostics";
4241
import { EnvVar } from "./environment";
4342
import { Feature, FeatureEnablement, initFeatures } from "./feature-flags";
44-
import {
45-
loadPropertiesFromApi,
46-
RepositoryProperties,
47-
} from "./feature-flags/properties";
43+
import { loadRepositoryProperties } from "./feature-flags/properties";
4844
import {
4945
checkInstallPython311,
5046
checkPacksForOverlayCompatibility,
@@ -62,7 +58,7 @@ import {
6258
OverlayBaseDatabaseDownloadStats,
6359
} from "./overlay/caching";
6460
import { OverlayDatabaseMode } from "./overlay/overlay-database-mode";
65-
import { getRepositoryNwo, RepositoryNwo } from "./repository";
61+
import { getRepositoryNwo } from "./repository";
6662
import { ToolsSource } from "./setup-codeql";
6763
import {
6864
ActionName,
@@ -94,10 +90,7 @@ import {
9490
checkActionVersion,
9591
getErrorMessage,
9692
BuildMode,
97-
Result,
9893
getOptionalEnvVar,
99-
Success,
100-
Failure,
10194
} from "./util";
10295
import { checkWorkflow } from "./workflow";
10396

@@ -805,38 +798,6 @@ async function run(
805798
);
806799
}
807800

808-
/**
809-
* Loads [repository properties](https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization) if applicable.
810-
*/
811-
async function loadRepositoryProperties(
812-
repositoryNwo: RepositoryNwo,
813-
logger: Logger,
814-
): Promise<Result<RepositoryProperties, unknown>> {
815-
// See if we can skip loading repository properties early. In particular,
816-
// repositories owned by users cannot have repository properties, so we can
817-
// skip the API call entirely in that case.
818-
const repositoryOwnerType = github.context.payload.repository?.owner.type;
819-
logger.debug(
820-
`Repository owner type is '${repositoryOwnerType ?? "unknown"}'.`,
821-
);
822-
if (repositoryOwnerType === "User") {
823-
logger.debug(
824-
"Skipping loading repository properties because the repository is owned by a user and " +
825-
"therefore cannot have repository properties.",
826-
);
827-
return new Success({});
828-
}
829-
830-
try {
831-
return new Success(await loadPropertiesFromApi(logger, repositoryNwo));
832-
} catch (error) {
833-
logger.warning(
834-
`Failed to load repository properties: ${getErrorMessage(error)}`,
835-
);
836-
return new Failure(error);
837-
}
838-
}
839-
840801
async function recordZstdAvailability(
841802
config: configUtils.Config,
842803
zstdAvailability: ZstdAvailability,

0 commit comments

Comments
 (0)