Skip to content

Commit 0a75581

Browse files
committed
Check that we are on dotcom
1 parent 7f73f8c commit 0a75581

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

src/feature-flags/properties.test.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as api from "../api-client";
55
import { getRunnerLogger } from "../logging";
66
import { parseRepositoryNwo } from "../repository";
77
import { setupTests } from "../testing-utils";
8+
import * as util from "../util";
89

910
import * as properties from "./properties";
1011

@@ -20,7 +21,13 @@ test("loadPropertiesFromApi throws if response data is not an array", async (t)
2021
const logger = getRunnerLogger(true);
2122
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
2223
await t.throwsAsync(
23-
properties.loadPropertiesFromApi(logger, mockRepositoryNwo),
24+
properties.loadPropertiesFromApi(
25+
{
26+
type: util.GitHubVariant.DOTCOM,
27+
},
28+
logger,
29+
mockRepositoryNwo,
30+
),
2431
);
2532
});
2633

@@ -34,10 +41,39 @@ test("loadPropertiesFromApi throws if response data contains unexpected objects"
3441
const logger = getRunnerLogger(true);
3542
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
3643
await t.throwsAsync(
37-
properties.loadPropertiesFromApi(logger, mockRepositoryNwo),
44+
properties.loadPropertiesFromApi(
45+
{
46+
type: util.GitHubVariant.DOTCOM,
47+
},
48+
logger,
49+
mockRepositoryNwo,
50+
),
3851
);
3952
});
4053

54+
test("loadPropertiesFromApi returns empty object if not on dotcom", async (t) => {
55+
sinon.stub(api, "getRepositoryProperties").resolves({
56+
headers: {},
57+
status: 200,
58+
url: "",
59+
data: [
60+
{ property_name: "github-codeql-extra-queries", value: "+queries" },
61+
{ property_name: "unknown-property", value: "something" },
62+
] satisfies properties.RepositoryProperty[],
63+
});
64+
const logger = getRunnerLogger(true);
65+
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
66+
const response = await properties.loadPropertiesFromApi(
67+
{
68+
type: util.GitHubVariant.GHES,
69+
version: "",
70+
},
71+
logger,
72+
mockRepositoryNwo,
73+
);
74+
t.deepEqual(response, {});
75+
});
76+
4177
test("loadPropertiesFromApi loads known properties", async (t) => {
4278
sinon.stub(api, "getRepositoryProperties").resolves({
4379
headers: {},
@@ -51,6 +87,9 @@ test("loadPropertiesFromApi loads known properties", async (t) => {
5187
const logger = getRunnerLogger(true);
5288
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
5389
const response = await properties.loadPropertiesFromApi(
90+
{
91+
type: util.GitHubVariant.DOTCOM,
92+
},
5493
logger,
5594
mockRepositoryNwo,
5695
);

src/feature-flags/properties.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getRepositoryProperties } from "../api-client";
22
import { Logger } from "../logging";
33
import { RepositoryNwo } from "../repository";
4+
import { GitHubVariant, GitHubVersion } from "../util";
45

56
/**
67
* Enumerates repository property names that have some meaning to us.
@@ -37,9 +38,16 @@ export type RepositoryProperties = Partial<
3738
* @returns Returns a partial mapping from `RepositoryPropertyName` to values.
3839
*/
3940
export async function loadPropertiesFromApi(
41+
gitHubVersion: GitHubVersion,
4042
logger: Logger,
4143
repositoryNwo: RepositoryNwo,
4244
): Promise<RepositoryProperties> {
45+
// TODO: To be safe for now; later we should replace this with a version check once we know
46+
// which version of GHES we expect this to be supported by.
47+
if (gitHubVersion.type !== GitHubVariant.DOTCOM) {
48+
return {};
49+
}
50+
4351
try {
4452
const response = await getRepositoryProperties(repositoryNwo);
4553
const remoteProperties = response.data as GitHubPropertiesResponse;

src/init-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async function run() {
202202
Feature.UseRepositoryProperties,
203203
);
204204
const repositoryProperties = enableRepoProps
205-
? await loadPropertiesFromApi(logger, repositoryNwo)
205+
? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo)
206206
: {};
207207

208208
const jobRunUuid = uuidV4();

0 commit comments

Comments
 (0)