Skip to content

Commit 6746b07

Browse files
Merge ownerName and repositoryName into one field because we no longer need to be able to specify them independently
1 parent 426ab98 commit 6746b07

3 files changed

Lines changed: 24 additions & 52 deletions

File tree

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,14 @@ import { ReleasesApiConsumer } from "./releases-api-consumer";
3636
*/
3737

3838
/**
39-
* Default value for the owner name of the extension-managed distribution on GitHub.
40-
*
41-
* We set the default here rather than as a default config value so that this default is invoked
42-
* upon blanking the setting.
39+
* Repository name with owner of the stable version of the extension-managed distribution on GitHub.
4340
*/
44-
const DEFAULT_DISTRIBUTION_OWNER_NAME = "github";
41+
const STABLE_DISTRIBUTION_REPOSITORY_NWO = "github/codeql-cli-binaries";
4542

4643
/**
47-
* Default value for the repository name of the extension-managed distribution on GitHub.
48-
*
49-
* We set the default here rather than as a default config value so that this default is invoked
50-
* upon blanking the setting.
44+
* Repository name with owner of the nightly version of the extension-managed distribution on GitHub.
5145
*/
52-
const DEFAULT_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-binaries";
53-
54-
/**
55-
* Owner name of the nightly version of the extension-managed distribution on GitHub.
56-
*/
57-
const NIGHTLY_DISTRIBUTION_OWNER_NAME = "dsp-testing";
58-
59-
/**
60-
* Repository name of the nightly version of the extension-managed distribution on GitHub.
61-
*/
62-
const NIGHTLY_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-nightlies";
46+
const NIGHTLY_DISTRIBUTION_REPOSITORY_NWO = "dsp-testing/codeql-cli-nightlies";
6347

6448
/**
6549
* Range of versions of the CLI that are compatible with the extension.
@@ -505,32 +489,22 @@ class ExtensionSpecificDistributionManager {
505489

506490
private createReleasesApiConsumer(): ReleasesApiConsumer {
507491
return new ReleasesApiConsumer(
508-
this.distributionOwnerName,
509-
this.distributionRepositoryName,
492+
this.distributionRepositoryNwo,
510493
this.config.personalAccessToken,
511494
);
512495
}
513496

514-
private get distributionOwnerName(): string {
515-
if (this.config.channel === "nightly") {
516-
return NIGHTLY_DISTRIBUTION_OWNER_NAME;
517-
} else {
518-
return DEFAULT_DISTRIBUTION_OWNER_NAME;
519-
}
520-
}
521-
522-
private get distributionRepositoryName(): string {
497+
private get distributionRepositoryNwo(): string {
523498
if (this.config.channel === "nightly") {
524-
return NIGHTLY_DISTRIBUTION_REPOSITORY_NAME;
499+
return NIGHTLY_DISTRIBUTION_REPOSITORY_NWO;
525500
} else {
526-
return DEFAULT_DISTRIBUTION_REPOSITORY_NAME;
501+
return STABLE_DISTRIBUTION_REPOSITORY_NWO;
527502
}
528503
}
529504

530505
private get usingNightlyReleases(): boolean {
531506
return (
532-
this.distributionOwnerName === NIGHTLY_DISTRIBUTION_OWNER_NAME &&
533-
this.distributionRepositoryName === NIGHTLY_DISTRIBUTION_REPOSITORY_NAME
507+
this.distributionRepositoryNwo === NIGHTLY_DISTRIBUTION_REPOSITORY_NWO
534508
);
535509
}
536510

extensions/ql-vscode/src/codeql-cli/releases-api-consumer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export class ReleasesApiConsumer {
1414
private readonly defaultHeaders: { [key: string]: string } = {};
1515

1616
constructor(
17-
private readonly ownerName: string,
18-
private readonly repoName: string,
17+
private readonly repositoryNwo: string,
1918
personalAccessToken?: string,
2019
) {
2120
// Specify version of the GitHub API
@@ -32,7 +31,7 @@ export class ReleasesApiConsumer {
3231
includePrerelease = false,
3332
additionalCompatibilityCheck?: (release: GithubRelease) => boolean,
3433
): Promise<Release> {
35-
const apiPath = `/repos/${this.ownerName}/${this.repoName}/releases`;
34+
const apiPath = `/repos/${this.repositoryNwo}/releases`;
3635
const allReleases: GithubRelease[] = await (
3736
await this.makeApiCall(apiPath)
3837
).json();
@@ -90,7 +89,7 @@ export class ReleasesApiConsumer {
9089
public async streamBinaryContentOfAsset(
9190
asset: ReleaseAsset,
9291
): Promise<fetch.Response> {
93-
const apiPath = `/repos/${this.ownerName}/${this.repoName}/releases/assets/${asset.id}`;
92+
const apiPath = `/repos/${this.repositoryNwo}/releases/assets/${asset.id}`;
9493

9594
return await this.makeApiCall(apiPath, {
9695
accept: "application/octet-stream",

extensions/ql-vscode/test/unit-tests/codeql-cli/releases-api-consumer.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
} from "../../../src/codeql-cli/releases-api-consumer";
99

1010
describe("Releases API consumer", () => {
11-
const owner = "someowner";
12-
const repo = "somerepo";
11+
const repositoryNwo = "someowner/somerepo";
1312
const unconstrainedVersionRange = new Range("*");
1413

1514
describe("picking the latest release", () => {
@@ -75,7 +74,7 @@ describe("Releases API consumer", () => {
7574

7675
class MockReleasesApiConsumer extends ReleasesApiConsumer {
7776
protected async makeApiCall(apiPath: string): Promise<fetch.Response> {
78-
if (apiPath === `/repos/${owner}/${repo}/releases`) {
77+
if (apiPath === `/repos/${repositoryNwo}/releases`) {
7978
return Promise.resolve(
8079
new fetch.Response(JSON.stringify(sampleReleaseResponse)),
8180
);
@@ -85,7 +84,7 @@ describe("Releases API consumer", () => {
8584
}
8685

8786
it("picked release is non-prerelease with the highest semver", async () => {
88-
const consumer = new MockReleasesApiConsumer(owner, repo);
87+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
8988

9089
const latestRelease = await consumer.getLatestRelease(
9190
unconstrainedVersionRange,
@@ -95,7 +94,7 @@ describe("Releases API consumer", () => {
9594
});
9695

9796
it("picked release is non-prerelease with highest id", async () => {
98-
const consumer = new MockReleasesApiConsumer(owner, repo);
97+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
9998

10099
const latestRelease = await consumer.getLatestRelease(
101100
unconstrainedVersionRange,
@@ -105,22 +104,22 @@ describe("Releases API consumer", () => {
105104
});
106105

107106
it("version of picked release is within the version range", async () => {
108-
const consumer = new MockReleasesApiConsumer(owner, repo);
107+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
109108

110109
const latestRelease = await consumer.getLatestRelease(new Range("2.*.*"));
111110
expect(latestRelease.id).toBe(1);
112111
});
113112

114113
it("fails if none of the releases are within the version range", async () => {
115-
const consumer = new MockReleasesApiConsumer(owner, repo);
114+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
116115

117116
await expect(
118117
consumer.getLatestRelease(new Range("5.*.*")),
119118
).rejects.toThrowError();
120119
});
121120

122121
it("picked release passes additional compatibility test if an additional compatibility test is specified", async () => {
123-
const consumer = new MockReleasesApiConsumer(owner, repo);
122+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
124123

125124
const latestRelease = await consumer.getLatestRelease(
126125
new Range("2.*.*"),
@@ -133,7 +132,7 @@ describe("Releases API consumer", () => {
133132
});
134133

135134
it("fails if none of the releases pass the additional compatibility test", async () => {
136-
const consumer = new MockReleasesApiConsumer(owner, repo);
135+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
137136

138137
await expect(
139138
consumer.getLatestRelease(new Range("2.*.*"), true, true, (release) =>
@@ -145,7 +144,7 @@ describe("Releases API consumer", () => {
145144
});
146145

147146
it("picked release is the most recent prerelease when includePrereleases is set", async () => {
148-
const consumer = new MockReleasesApiConsumer(owner, repo);
147+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
149148

150149
const latestRelease = await consumer.getLatestRelease(
151150
unconstrainedVersionRange,
@@ -156,7 +155,7 @@ describe("Releases API consumer", () => {
156155
});
157156

158157
it("ignores invalid semver and picks (pre-)release with highest id", async () => {
159-
const consumer = new MockReleasesApiConsumer(owner, repo);
158+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
160159

161160
const latestRelease = await consumer.getLatestRelease(
162161
undefined,
@@ -183,7 +182,7 @@ describe("Releases API consumer", () => {
183182

184183
class MockReleasesApiConsumer extends ReleasesApiConsumer {
185184
protected async makeApiCall(apiPath: string): Promise<fetch.Response> {
186-
if (apiPath === `/repos/${owner}/${repo}/releases`) {
185+
if (apiPath === `/repos/${repositoryNwo}/releases`) {
187186
const responseBody: GithubRelease[] = [
188187
{
189188
assets: expectedAssets,
@@ -203,7 +202,7 @@ describe("Releases API consumer", () => {
203202
}
204203
}
205204

206-
const consumer = new MockReleasesApiConsumer(owner, repo);
205+
const consumer = new MockReleasesApiConsumer(repositoryNwo);
207206

208207
const assets = (await consumer.getLatestRelease(unconstrainedVersionRange))
209208
.assets;

0 commit comments

Comments
 (0)