Merge ownerName and repositoryName into one field because we no longer need to be able to specify them independently
This commit is contained in:
@@ -36,30 +36,14 @@ import { ReleasesApiConsumer } from "./releases-api-consumer";
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default value for the owner name of the extension-managed distribution on GitHub.
|
||||
*
|
||||
* We set the default here rather than as a default config value so that this default is invoked
|
||||
* upon blanking the setting.
|
||||
* Repository name with owner of the stable version of the extension-managed distribution on GitHub.
|
||||
*/
|
||||
const DEFAULT_DISTRIBUTION_OWNER_NAME = "github";
|
||||
const STABLE_DISTRIBUTION_REPOSITORY_NWO = "github/codeql-cli-binaries";
|
||||
|
||||
/**
|
||||
* Default value for the repository name of the extension-managed distribution on GitHub.
|
||||
*
|
||||
* We set the default here rather than as a default config value so that this default is invoked
|
||||
* upon blanking the setting.
|
||||
* Repository name with owner of the nightly version of the extension-managed distribution on GitHub.
|
||||
*/
|
||||
const DEFAULT_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-binaries";
|
||||
|
||||
/**
|
||||
* Owner name of the nightly version of the extension-managed distribution on GitHub.
|
||||
*/
|
||||
const NIGHTLY_DISTRIBUTION_OWNER_NAME = "dsp-testing";
|
||||
|
||||
/**
|
||||
* Repository name of the nightly version of the extension-managed distribution on GitHub.
|
||||
*/
|
||||
const NIGHTLY_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-nightlies";
|
||||
const NIGHTLY_DISTRIBUTION_REPOSITORY_NWO = "dsp-testing/codeql-cli-nightlies";
|
||||
|
||||
/**
|
||||
* Range of versions of the CLI that are compatible with the extension.
|
||||
@@ -505,32 +489,22 @@ class ExtensionSpecificDistributionManager {
|
||||
|
||||
private createReleasesApiConsumer(): ReleasesApiConsumer {
|
||||
return new ReleasesApiConsumer(
|
||||
this.distributionOwnerName,
|
||||
this.distributionRepositoryName,
|
||||
this.distributionRepositoryNwo,
|
||||
this.config.personalAccessToken,
|
||||
);
|
||||
}
|
||||
|
||||
private get distributionOwnerName(): string {
|
||||
private get distributionRepositoryNwo(): string {
|
||||
if (this.config.channel === "nightly") {
|
||||
return NIGHTLY_DISTRIBUTION_OWNER_NAME;
|
||||
return NIGHTLY_DISTRIBUTION_REPOSITORY_NWO;
|
||||
} else {
|
||||
return DEFAULT_DISTRIBUTION_OWNER_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
private get distributionRepositoryName(): string {
|
||||
if (this.config.channel === "nightly") {
|
||||
return NIGHTLY_DISTRIBUTION_REPOSITORY_NAME;
|
||||
} else {
|
||||
return DEFAULT_DISTRIBUTION_REPOSITORY_NAME;
|
||||
return STABLE_DISTRIBUTION_REPOSITORY_NWO;
|
||||
}
|
||||
}
|
||||
|
||||
private get usingNightlyReleases(): boolean {
|
||||
return (
|
||||
this.distributionOwnerName === NIGHTLY_DISTRIBUTION_OWNER_NAME &&
|
||||
this.distributionRepositoryName === NIGHTLY_DISTRIBUTION_REPOSITORY_NAME
|
||||
this.distributionRepositoryNwo === NIGHTLY_DISTRIBUTION_REPOSITORY_NWO
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ export class ReleasesApiConsumer {
|
||||
private readonly defaultHeaders: { [key: string]: string } = {};
|
||||
|
||||
constructor(
|
||||
private readonly ownerName: string,
|
||||
private readonly repoName: string,
|
||||
private readonly repositoryNwo: string,
|
||||
personalAccessToken?: string,
|
||||
) {
|
||||
// Specify version of the GitHub API
|
||||
@@ -32,7 +31,7 @@ export class ReleasesApiConsumer {
|
||||
includePrerelease = false,
|
||||
additionalCompatibilityCheck?: (release: GithubRelease) => boolean,
|
||||
): Promise<Release> {
|
||||
const apiPath = `/repos/${this.ownerName}/${this.repoName}/releases`;
|
||||
const apiPath = `/repos/${this.repositoryNwo}/releases`;
|
||||
const allReleases: GithubRelease[] = await (
|
||||
await this.makeApiCall(apiPath)
|
||||
).json();
|
||||
@@ -90,7 +89,7 @@ export class ReleasesApiConsumer {
|
||||
public async streamBinaryContentOfAsset(
|
||||
asset: ReleaseAsset,
|
||||
): Promise<fetch.Response> {
|
||||
const apiPath = `/repos/${this.ownerName}/${this.repoName}/releases/assets/${asset.id}`;
|
||||
const apiPath = `/repos/${this.repositoryNwo}/releases/assets/${asset.id}`;
|
||||
|
||||
return await this.makeApiCall(apiPath, {
|
||||
accept: "application/octet-stream",
|
||||
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
} from "../../../src/codeql-cli/releases-api-consumer";
|
||||
|
||||
describe("Releases API consumer", () => {
|
||||
const owner = "someowner";
|
||||
const repo = "somerepo";
|
||||
const repositoryNwo = "someowner/somerepo";
|
||||
const unconstrainedVersionRange = new Range("*");
|
||||
|
||||
describe("picking the latest release", () => {
|
||||
@@ -75,7 +74,7 @@ describe("Releases API consumer", () => {
|
||||
|
||||
class MockReleasesApiConsumer extends ReleasesApiConsumer {
|
||||
protected async makeApiCall(apiPath: string): Promise<fetch.Response> {
|
||||
if (apiPath === `/repos/${owner}/${repo}/releases`) {
|
||||
if (apiPath === `/repos/${repositoryNwo}/releases`) {
|
||||
return Promise.resolve(
|
||||
new fetch.Response(JSON.stringify(sampleReleaseResponse)),
|
||||
);
|
||||
@@ -85,7 +84,7 @@ describe("Releases API consumer", () => {
|
||||
}
|
||||
|
||||
it("picked release is non-prerelease with the highest semver", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(
|
||||
unconstrainedVersionRange,
|
||||
@@ -95,7 +94,7 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("picked release is non-prerelease with highest id", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(
|
||||
unconstrainedVersionRange,
|
||||
@@ -105,14 +104,14 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("version of picked release is within the version range", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(new Range("2.*.*"));
|
||||
expect(latestRelease.id).toBe(1);
|
||||
});
|
||||
|
||||
it("fails if none of the releases are within the version range", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
await expect(
|
||||
consumer.getLatestRelease(new Range("5.*.*")),
|
||||
@@ -120,7 +119,7 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("picked release passes additional compatibility test if an additional compatibility test is specified", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(
|
||||
new Range("2.*.*"),
|
||||
@@ -133,7 +132,7 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("fails if none of the releases pass the additional compatibility test", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
await expect(
|
||||
consumer.getLatestRelease(new Range("2.*.*"), true, true, (release) =>
|
||||
@@ -145,7 +144,7 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("picked release is the most recent prerelease when includePrereleases is set", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(
|
||||
unconstrainedVersionRange,
|
||||
@@ -156,7 +155,7 @@ describe("Releases API consumer", () => {
|
||||
});
|
||||
|
||||
it("ignores invalid semver and picks (pre-)release with highest id", async () => {
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const latestRelease = await consumer.getLatestRelease(
|
||||
undefined,
|
||||
@@ -183,7 +182,7 @@ describe("Releases API consumer", () => {
|
||||
|
||||
class MockReleasesApiConsumer extends ReleasesApiConsumer {
|
||||
protected async makeApiCall(apiPath: string): Promise<fetch.Response> {
|
||||
if (apiPath === `/repos/${owner}/${repo}/releases`) {
|
||||
if (apiPath === `/repos/${repositoryNwo}/releases`) {
|
||||
const responseBody: GithubRelease[] = [
|
||||
{
|
||||
assets: expectedAssets,
|
||||
@@ -203,7 +202,7 @@ describe("Releases API consumer", () => {
|
||||
}
|
||||
}
|
||||
|
||||
const consumer = new MockReleasesApiConsumer(owner, repo);
|
||||
const consumer = new MockReleasesApiConsumer(repositoryNwo);
|
||||
|
||||
const assets = (await consumer.getLatestRelease(unconstrainedVersionRange))
|
||||
.assets;
|
||||
|
||||
Reference in New Issue
Block a user