Skip to content

Commit a9d2572

Browse files
fix: custom config path (#119)
* fix: custom config path * lint fix * Update src/hooks/post.ts Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 663e5c0 commit a9d2572

File tree

4 files changed

+80
-26
lines changed

4 files changed

+80
-26
lines changed

src/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { FormatKind } from "./util/variant.ts";
44

55
export interface IContext {
66
output?: string;
7+
8+
// For an unknown reason, this one particular arg is coming through as 'c' instead of 'config'
9+
// All of the other options are coming through as their full names.
10+
// Therefore, we need to support both 'c' and 'config' for now.
11+
c?: string;
712
config?: string;
813
githubDir: string;
914
hooks: {

src/hooks/post.test.ts

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from "../../deps/semver.ts";
2-
import { resolvesNext, stub } from "../../deps/std.ts";
2+
import { assertEquals, resolvesNext, stub } from "../../deps/std.ts";
33
import { YAML } from "../../deps/yaml.ts";
44
import { IContext } from "../context.ts";
55
import { postVersionHook } from "./post.ts";
@@ -13,27 +13,73 @@ Deno.test("yml or yaml", async () => {
1313
regexp: async () => await undefined,
1414
},
1515
};
16-
stub(
17-
Deno,
18-
"stat",
19-
resolvesNext<Deno.FileInfo>([
20-
Object.assign(new Deno.errors.NotFound("not found")), // version.yml, nah
21-
{
22-
isFile: true,
23-
} as Deno.FileInfo, // version.yaml, yah
24-
]),
25-
);
26-
stub(
27-
Deno,
28-
"readTextFile",
29-
resolvesNext([
30-
"1.0.0",
31-
YAML.stringify({
32-
on: { post: [{ kind: "patch", file: "test/example.csproj" }] },
33-
}),
34-
]),
35-
);
36-
stub(context.hooks, "patch");
37-
stub(context.hooks, "replace");
38-
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
16+
const stubs = [
17+
stub(
18+
Deno,
19+
"stat",
20+
resolvesNext<Deno.FileInfo>([
21+
Object.assign(new Deno.errors.NotFound("not found")), // version.yml, nah
22+
{
23+
isFile: true,
24+
} as Deno.FileInfo, // version.yaml, yah
25+
]),
26+
),
27+
stub(
28+
Deno,
29+
"readTextFile",
30+
resolvesNext([
31+
"1.0.0",
32+
YAML.stringify({
33+
on: { post: [{ kind: "patch", file: "test/example.csproj" }] },
34+
}),
35+
]),
36+
),
37+
stub(context.hooks, "patch"),
38+
stub(context.hooks, "replace"),
39+
];
40+
try {
41+
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
42+
} finally {
43+
stubs.forEach((s) => s.restore());
44+
}
45+
});
46+
47+
Deno.test("custom config", async () => {
48+
const context: IContext = {
49+
config: ".github/version-test.yml",
50+
githubDir: ".github",
51+
hooks: {
52+
patch: async () => await undefined,
53+
replace: async () => await undefined,
54+
regexp: async () => await undefined,
55+
},
56+
};
57+
let configPath: string | URL = "";
58+
const stubs = [
59+
stub(
60+
Deno,
61+
"stat",
62+
resolvesNext<Deno.FileInfo>([
63+
{ isFile: true } as Deno.FileInfo,
64+
]),
65+
),
66+
stub(
67+
Deno,
68+
"readTextFile",
69+
async (path, _opts) => {
70+
configPath = path;
71+
return await YAML.stringify({
72+
on: { post: [] },
73+
});
74+
},
75+
),
76+
stub(context.hooks, "patch"),
77+
stub(context.hooks, "replace"),
78+
];
79+
try {
80+
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
81+
assertEquals(configPath, ".github/version-test.yml");
82+
} finally {
83+
stubs.forEach((s) => s.restore());
84+
}
3985
});

src/hooks/post.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ export async function postVersionHook(
5757
}
5858

5959
async function getVersionConfig(context: IContext) {
60-
const { config, githubDir } = context;
61-
const paths = config ? [config] : [
60+
const { c: configShorthand, config, githubDir } = context;
61+
const configPath = config ?? configShorthand;
62+
const paths = configPath ? [configPath] : [
6263
[githubDir, "version.yml"].filter((p) => p).join("/"),
6364
[githubDir, "version.yaml"].filter((p) => p).join("/"),
6465
];

test/node/.github/version-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
on:
2+
post: []

0 commit comments

Comments
 (0)