@@ -19198,15 +19198,39 @@ const { readFileSync } = __nccwpck_require__(5747);
1919819198const header = core.getInput("comment-header");
1919919199const footer = core.getInput("comment-footer");
1920019200const minimatchOptions = {
19201- dot: core.getInput(' include-hidden-files' ) === ' true'
19201+ dot: core.getInput(" include-hidden-files" ) === " true",
1920219202};
1920319203function getChecklistPaths() {
1920419204 const inputFile = core.getInput("input-file");
1920519205 const parsedFile = YAML.parse(readFileSync(inputFile, { encoding: "utf8" }));
1920619206 return parsedFile.paths;
1920719207}
19208- function formatItemsForPath([path, items]) {
19209- const showPaths = core.getInput("show-paths") === 'true';
19208+ function formatItemsForPath(previousComment, [path, items]) {
19209+ const showPaths = core.getInput("show-paths") === "true";
19210+ const mergeComment = core.getInput("merge-comment") === "true";
19211+ if (!!previousComment && mergeComment) {
19212+ const existingCheckedItems = previousComment
19213+ .split("\n")
19214+ .filter((line) => line !== "" && line.startsWith("- [x]"))
19215+ .map((line) => line.substring(5).trim());
19216+ const preservedItems = items.filter((item) => {
19217+ return !!existingCheckedItems.find((existingItem) => existingItem.includes(item));
19218+ });
19219+ const newItems = items.filter((item) => {
19220+ return !existingCheckedItems.find((existingItem) => existingItem.includes(item));
19221+ });
19222+ return showPaths
19223+ ? [
19224+ `__Files matching \`${path}\`:__\n`,
19225+ ...preservedItems.map((item) => `- [x] ${item}\n`),
19226+ ...newItems.map((item) => `- [ ] ${item}\n`),
19227+ "\n",
19228+ ].join("")
19229+ : [
19230+ ...preservedItems.map((item) => `- [x] ${item}\n`),
19231+ ...newItems.map((item) => `- [ ] ${item}\n`),
19232+ ].join("");
19233+ }
1921019234 return showPaths
1921119235 ? [
1921219236 `__Files matching \`${path}\`:__\n`,
@@ -19227,8 +19251,8 @@ function run() {
1922719251 const modifiedPaths = (yield client.rest.pulls.listFiles({
1922819252 owner: owner,
1922919253 repo: repo,
19230- pull_number: number
19231- })).data.map(file => file.filename);
19254+ pull_number: number,
19255+ })).data.map(( file) => file.filename);
1923219256 const applicableChecklistPaths = Object.entries(checklistPaths).filter(([key, _]) => {
1923319257 for (const modifiedPath of modifiedPaths) {
1923419258 if (minimatch(modifiedPath, key, minimatchOptions)) {
@@ -19240,28 +19264,28 @@ function run() {
1924019264 const existingComment = (yield client.rest.issues.listComments({
1924119265 owner: owner,
1924219266 repo: repo,
19243- issue_number: number
19244- })).data.find(comment => comment.body.includes(footer));
19267+ issue_number: number,
19268+ })).data.find(( comment) => comment.body.includes(footer));
1924519269 if (applicableChecklistPaths.length > 0) {
1924619270 const body = [
1924719271 `${header}\n\n`,
19248- ...applicableChecklistPaths.map(formatItemsForPath),
19249- `\n${footer}`
19272+ ...applicableChecklistPaths.map(([path, items]) => formatItemsForPath(existingComment.body, [path, items]) ),
19273+ `\n${footer}`,
1925019274 ].join("");
1925119275 if (existingComment) {
1925219276 yield client.rest.issues.updateComment({
1925319277 owner: owner,
1925419278 repo: repo,
1925519279 comment_id: existingComment.id,
19256- body
19280+ body,
1925719281 });
1925819282 }
1925919283 else {
1926019284 yield client.rest.issues.createComment({
1926119285 owner: owner,
1926219286 repo: repo,
1926319287 issue_number: number,
19264- body
19288+ body,
1926519289 });
1926619290 }
1926719291 }
@@ -19270,14 +19294,14 @@ function run() {
1927019294 yield client.rest.issues.deleteComment({
1927119295 owner: owner,
1927219296 repo: repo,
19273- comment_id: existingComment.id
19297+ comment_id: existingComment.id,
1927419298 });
1927519299 }
1927619300 console.log("No paths were modified that match checklist paths");
1927719301 }
1927819302 });
1927919303}
19280- run().catch(err => core.setFailed(err.message));
19304+ run().catch(( err) => core.setFailed(err.message));
1928119305
1928219306})();
1928319307
0 commit comments