Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dalejo96 committed Dec 20, 2023
1 parent 305da2f commit 021344e
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 38 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
],
"import/no-duplicates": "error",
"import/no-import-module-exports": "error",
"import/no-namespace": "error",
"import/no-relative-packages": "error",
"import/no-unresolved": "error",
"import/no-useless-path-segments": "error",
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"exit": true,
"extension": ["ts"],
"recursive": true,
"require": ["ts-node/register","test/hooks.ts"],
"require": ["ts-node/register", "test/hooks.ts"],
"slow": 1000,
"spec": ["test/**/*.test.*"],
"timeout": 5000
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"axios": "^1.6.0"
},
"devDependencies": {
"@stackbuilders/assertive-ts": "^1.4.0",
"@assertive-ts/core": "^2.0.0",
"@types/mocha": "^10.0.1",
"@types/semantic-release": "^20.0.1",
"@types/sinon": "^17.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { getCabalFilename } from "./utils/prepare";
import { readFile, writeFile } from "fs/promises";
import { resolve } from "path";

export const versionPattern = /version:\s+(\S+)/;
export const VERSION_PATTERN = /version:\s+(\S+)/;

export const readAndWriteNewCabal = async (fullCabalPath: string, newVersion: string): Promise<void> => {
const versionContents = await readFile(fullCabalPath, "utf8");
const newContents = versionContents.replace(versionPattern, `version: ${newVersion}`);
const newContents = versionContents.replace(VERSION_PATTERN, `version: ${newVersion}`);
await writeFile(fullCabalPath, newContents, "utf8");
};

Expand Down
6 changes: 3 additions & 3 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { PluginConfig } from "./types/pluginConfig";
import { runExecCommand } from "./utils/exec";

export const HACKAGE_PACKAGES_URL = "https://hackage.haskell.org/package";
export const CANDIDATES = "candidates/";
export const CANDIDATES_PATH = "candidates/";

export const postReleaseCandidate = async (
sdistPath: string,
packageName: string,
hackageToken?: string,
): Promise<number | undefined> => {
const url = `${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}`;
const url = `${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES_PATH}`;
try {
const headers = {
Accept: "text/plain",
Expand All @@ -26,7 +26,7 @@ export const postReleaseCandidate = async (

return req.status;
} catch (e: unknown) {
throw new Error(`You do not have access to POST a file to ${url}, ${String((e as Error).message)}`);
throw e instanceof Error ? new Error(`You do not have access to POST a file to ${url}, ${e.message}`) : e;
}
};

Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions test/integration/prepare.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { expect } from "@stackbuilders/assertive-ts";
import { expect } from "@assertive-ts/core";
import Sinon from "sinon";

import { prepare } from "../../src/prepare";
import { PluginConfig } from "../../src/types/pluginConfig";
// eslint-disable-next-line import/no-namespace
import * as exec from "../../src/utils/exec";
import { semanticContext, contextWithoutRelease } from "../utils";
import { semanticContext, contextWithoutRelease } from "../helpers/context";

const pluginConfig: PluginConfig = {
cabalFile: "test/fixtures/test-1-package.cabal",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/verifyConditions.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "@stackbuilders/assertive-ts";
import { expect } from "@assertive-ts/core";

import { PluginConfig } from "../../src/types/pluginConfig";
import { EnvVarError } from "../../src/utils/EnvVarError";
import { verifyConditions } from "../../src/verifyConditions";
import { semanticContext } from "../utils";
import { semanticContext } from "../helpers/context";

const pluginConfig: PluginConfig = {
cabalFile: "test-1-package.cabal",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/EnvVarError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "@stackbuilders/assertive-ts";
import { expect } from "@assertive-ts/core";

import { EnvVarError } from "../../src/utils/EnvVarError";

Expand Down
10 changes: 5 additions & 5 deletions test/unit/prepare.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "@stackbuilders/assertive-ts";
import { expect } from "@assertive-ts/core";

import { readAndWriteNewCabal } from "../../src/prepare";

import { readFile, writeFile } from "fs/promises";

describe("readAndWriteNewCabal", () => {
const fakeCabalPath = "./test/fixtures/test-1-package.cabal";
const fakeNewVersion = "0.0.7";
const cabalContent = "name: test-1-package\nversion: 0.0.1";
const fakeCabalPath = "./test/fixtures/test-1-package.cabal";
const fakeNewVersion = "0.0.7";
const cabalContent = "name: test-1-package\nversion: 0.0.1";

describe("readAndWriteNewCabal", () => {
afterEach(async () => {
await writeFile(fakeCabalPath, cabalContent, "utf8");
});
Expand Down
12 changes: 4 additions & 8 deletions test/unit/publish.test..ts → test/unit/publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "@stackbuilders/assertive-ts";
import { expect } from "@assertive-ts/core";
import axios from "axios";
import sinon from "sinon";

import { CANDIDATES, HACKAGE_PACKAGES_URL, postReleaseCandidate } from "../../src/publish";
import { CANDIDATES_PATH, HACKAGE_PACKAGES_URL, postReleaseCandidate } from "../../src/publish";

const sdistPath = "sdist/path";
const packageName = "my-hackage-package";
Expand All @@ -16,7 +16,7 @@ describe("postReleaseCandidate", () => {

expect(statusCode).toBeEqual(200);
expect(axiosPostStub.calledOnce).toBeTruthy();
expect(axiosPostStub.firstCall.args[0]).toBeEqual(`${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}`);
expect(axiosPostStub.firstCall.args[0]).toBeEqual(`${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES_PATH}`);
});

it("throws an error on unsuccessful request", async () => {
Expand All @@ -25,11 +25,7 @@ describe("postReleaseCandidate", () => {

const request = postReleaseCandidate(sdistPath, packageName, hackageToken);

await expect(request).toBeRejectedWith(
new Error(
`You do not have access to POST a file to ${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}, ${errorMsg}`,
),
);
await expect(request).toBeRejected();
expect(axiosPostStub.calledOnce).toBeTruthy();
});
});
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ __metadata:
languageName: node
linkType: hard

"@assertive-ts/core@npm:^2.0.0":
version: 2.0.0
resolution: "@assertive-ts/core@npm:2.0.0"
dependencies:
"@cometlib/dedent": ^0.8.0-es.10
fast-deep-equal: ^3.1.3
checksum: 93b76098dbbf919af486c8be7a2ef96a9493499070e5431fe41dc79849c3fb309df14565b2f4903b657620198c38fc776b6a53b2907a53b0260fdaba7397b0b5
languageName: node
linkType: hard

"@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.21.4":
version: 7.22.5
resolution: "@babel/code-frame@npm:7.22.5"
Expand Down Expand Up @@ -764,21 +774,11 @@ __metadata:
languageName: node
linkType: hard

"@stackbuilders/assertive-ts@npm:^1.4.0":
version: 1.4.0
resolution: "@stackbuilders/assertive-ts@npm:1.4.0"
dependencies:
"@cometlib/dedent": ^0.8.0-es.10
fast-deep-equal: ^3.1.3
checksum: 89d787a9f55f57e0baf164a08b2210266dbd483be284cf4d2f4d20e1403aced432abbe786c7f439b4ecdd4bd7ba2410bfedf2240162203b36860572736c4c591
languageName: node
linkType: hard

"@stackbuilders/semantic-release-hackage@workspace:.":
version: 0.0.0-use.local
resolution: "@stackbuilders/semantic-release-hackage@workspace:."
dependencies:
"@stackbuilders/assertive-ts": ^1.4.0
"@assertive-ts/core": ^2.0.0
"@types/mocha": ^10.0.1
"@types/semantic-release": ^20.0.1
"@types/sinon": ^17.0.2
Expand Down

0 comments on commit 021344e

Please sign in to comment.