Skip to content

Commit a5dc0fd

Browse files
reverting changes to index.js and applying them to index.ts
1 parent 5ab6e2d commit a5dc0fd

File tree

2 files changed

+60
-56
lines changed

2 files changed

+60
-56
lines changed

dist/index.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19197,7 +19197,6 @@ const minimatch = __nccwpck_require__(3973);
1919719197
const { readFileSync } = __nccwpck_require__(5747);
1919819198
const header = core.getInput("comment-header");
1919919199
const footer = core.getInput("comment-footer");
19200-
const mergeComment = core.getInput("merge-comment") === 'true';
1920119200
const minimatchOptions = {
1920219201
dot: core.getInput('include-hidden-files') === 'true'
1920319202
};
@@ -19206,46 +19205,15 @@ function getChecklistPaths() {
1920619205
const parsedFile = YAML.parse(readFileSync(inputFile, { encoding: "utf8" }));
1920719206
return parsedFile.paths;
1920819207
}
19209-
function formatItemsForPath(previousComment, mergeComment, [path, items]) {
19210-
const showPaths = core.getInput("show-paths") === "true";
19211-
19212-
if (!!previousComment && mergeComment) {
19213-
const existingCheckedItems = previousComment
19214-
.split("\n")
19215-
.filter((line) => line !== "" && line.startsWith("- [x]"))
19216-
.map((line) => line.substring(5).trim());
19217-
const preservedItems = items.filter((item) => {
19218-
return !!existingCheckedItems.find((existingItem) =>
19219-
existingItem.includes(item)
19220-
);
19221-
});
19222-
const newItems = items.filter((item) => {
19223-
return !existingCheckedItems.find((existingItem) =>
19224-
existingItem.includes(item)
19225-
);
19226-
});
19227-
19228-
return showPaths
19229-
? [
19230-
`__Files matching \`${path}\`:__\n`,
19231-
...preservedItems.map((item) => `- [x] ${item}\n`),
19232-
...newItems.map((item) => `- [ ] ${item}\n`),
19233-
"\n",
19234-
].join("")
19235-
: [
19236-
...preservedItems.map((item) => `- [x] ${item}\n`),
19237-
...newItems.map((item) => `- [ ] ${item}\n`),
19238-
].join("");
19239-
}
19240-
19208+
function formatItemsForPath([path, items]) {
19209+
const showPaths = core.getInput("show-paths") === 'true';
1924119210
return showPaths
1924219211
? [
1924319212
`__Files matching \`${path}\`:__\n`,
1924419213
...items.map((item) => `- [ ] ${item}\n`),
1924519214
"\n",
1924619215
].join("")
1924719216
: [...items.map((item) => `- [ ] ${item}\n`)].join("");
19248-
1924919217
}
1925019218
function run() {
1925119219
var _a, _b;
@@ -19277,7 +19245,7 @@ function run() {
1927719245
if (applicableChecklistPaths.length > 0) {
1927819246
const body = [
1927919247
`${header}\n\n`,
19280-
...applicableChecklistPaths.map(([path, items]) => formatItemsForPath(existingComment.body, mergeComment, [path, items])),
19248+
...applicableChecklistPaths.map(formatItemsForPath),
1928119249
`\n${footer}`
1928219250
].join("");
1928319251
if (existingComment) {

index.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const minimatch = require("minimatch");
55
const { readFileSync } = require("fs");
66

77
const header = core.getInput("comment-header");
8-
const footer = core.getInput("comment-footer")
8+
const footer = core.getInput("comment-footer");
99

1010
const minimatchOptions = {
11-
dot: core.getInput('include-hidden-files') === 'true'
11+
dot: core.getInput("include-hidden-files") === "true",
1212
};
1313

1414
function getChecklistPaths(): Record<string, string[]> {
@@ -17,22 +17,56 @@ function getChecklistPaths(): Record<string, string[]> {
1717
return parsedFile.paths;
1818
}
1919

20-
function formatItemsForPath([path, items]): string {
21-
const showPaths = core.getInput("show-paths") === 'true';
20+
function formatItemsForPath(previousComment, [path, items]) {
21+
const showPaths = core.getInput("show-paths") === "true";
22+
const mergeComment = core.getInput("merge-comment") === "true";
23+
24+
if (!!previousComment && mergeComment) {
25+
const existingCheckedItems = previousComment
26+
.split("\n")
27+
.filter((line) => line !== "" && line.startsWith("- [x]"))
28+
.map((line) => line.substring(5).trim());
29+
const preservedItems = items.filter((item) => {
30+
return !!existingCheckedItems.find((existingItem) =>
31+
existingItem.includes(item)
32+
);
33+
});
34+
const newItems = items.filter((item) => {
35+
return !existingCheckedItems.find((existingItem) =>
36+
existingItem.includes(item)
37+
);
38+
});
39+
40+
return showPaths
41+
? [
42+
`__Files matching \`${path}\`:__\n`,
43+
...preservedItems.map((item) => `- [x] ${item}\n`),
44+
...newItems.map((item) => `- [ ] ${item}\n`),
45+
"\n",
46+
].join("")
47+
: [
48+
...preservedItems.map((item) => `- [x] ${item}\n`),
49+
...newItems.map((item) => `- [ ] ${item}\n`),
50+
].join("");
51+
}
2252

2353
return showPaths
24-
? [
25-
`__Files matching \`${path}\`:__\n`,
26-
...items.map((item) => `- [ ] ${item}\n`),
27-
"\n",
28-
].join("")
29-
: [...items.map((item) => `- [ ] ${item}\n`)].join("");
54+
? [
55+
`__Files matching \`${path}\`:__\n`,
56+
...items.map((item) => `- [ ] ${item}\n`),
57+
"\n",
58+
].join("")
59+
: [...items.map((item) => `- [ ] ${item}\n`)].join("");
3060
}
3161

3262
async function run() {
3363
const context = github.context;
3464
const { owner, repo } = context.repo;
35-
const number = (context.payload.issue ?? context.payload.pull_request ?? context.payload).number;
65+
const number = (
66+
context.payload.issue ??
67+
context.payload.pull_request ??
68+
context.payload
69+
).number;
3670

3771
const ghToken = core.getInput("gh-token");
3872
const client = github.getOctokit(ghToken);
@@ -42,9 +76,9 @@ async function run() {
4276
await client.rest.pulls.listFiles({
4377
owner: owner,
4478
repo: repo,
45-
pull_number: number
79+
pull_number: number,
4680
})
47-
).data.map(file => file.filename);
81+
).data.map((file) => file.filename);
4882

4983
const applicableChecklistPaths = Object.entries(checklistPaths).filter(
5084
([key, _]) => {
@@ -61,42 +95,44 @@ async function run() {
6195
await client.rest.issues.listComments({
6296
owner: owner,
6397
repo: repo,
64-
issue_number: number
98+
issue_number: number,
6599
})
66-
).data.find(comment => comment.body.includes(footer));
100+
).data.find((comment) => comment.body.includes(footer));
67101

68102
if (applicableChecklistPaths.length > 0) {
69103
const body = [
70104
`${header}\n\n`,
71-
...applicableChecklistPaths.map(formatItemsForPath),
72-
`\n${footer}`
105+
...applicableChecklistPaths.map(([path, items]) =>
106+
formatItemsForPath(existingComment.body, [path, items])
107+
),
108+
`\n${footer}`,
73109
].join("");
74110

75111
if (existingComment) {
76112
await client.rest.issues.updateComment({
77113
owner: owner,
78114
repo: repo,
79115
comment_id: existingComment.id,
80-
body
116+
body,
81117
});
82118
} else {
83119
await client.rest.issues.createComment({
84120
owner: owner,
85121
repo: repo,
86122
issue_number: number,
87-
body
123+
body,
88124
});
89125
}
90126
} else {
91127
if (existingComment) {
92128
await client.rest.issues.deleteComment({
93129
owner: owner,
94130
repo: repo,
95-
comment_id: existingComment.id
131+
comment_id: existingComment.id,
96132
});
97133
}
98134
console.log("No paths were modified that match checklist paths");
99135
}
100136
}
101137

102-
run().catch(err => core.setFailed(err.message));
138+
run().catch((err) => core.setFailed(err.message));

0 commit comments

Comments
 (0)