mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-12 19:51:14 +00:00
Hide details (#435)
* ✨ hide details * 📦 build * 👷 ci for hide_details option
This commit is contained in:
parent
53e089cfe2
commit
21a90c1106
12 changed files with 136 additions and 8 deletions
11
.github/workflows/comment_on_workflow_run.yml
vendored
11
.github/workflows/comment_on_workflow_run.yml
vendored
|
|
@ -23,6 +23,17 @@ jobs:
|
||||||
header: All
|
header: All
|
||||||
number: ${{ steps.artifact.outputs.number }}
|
number: ${{ steps.artifact.outputs.number }}
|
||||||
message: |
|
message: |
|
||||||
|
<details open>
|
||||||
|
<summary>output of `yarn all`</summary>
|
||||||
|
|
||||||
```
|
```
|
||||||
${{ steps.artifact.outputs.all_result }}
|
${{ steps.artifact.outputs.all_result }}
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
header: All
|
||||||
|
append: true
|
||||||
|
hide_details: true
|
||||||
|
message: |
|
||||||
|
The build is over.
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {
|
||||||
createComment,
|
createComment,
|
||||||
deleteComment,
|
deleteComment,
|
||||||
findPreviousComment,
|
findPreviousComment,
|
||||||
|
getBodyOf,
|
||||||
updateComment
|
updateComment
|
||||||
} from "../src/comment"
|
} from "../src/comment"
|
||||||
|
|
||||||
|
|
@ -177,3 +178,42 @@ it("deleteComment", async () => {
|
||||||
repo: "sticky-pull-request-comment"
|
repo: "sticky-pull-request-comment"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("getBodyOf", () => {
|
||||||
|
const nullPrevious = {}
|
||||||
|
const simplePrevious = {
|
||||||
|
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||||
|
}
|
||||||
|
const detailsPrevious = {
|
||||||
|
body: `
|
||||||
|
<details open>
|
||||||
|
<summary>title</summary>
|
||||||
|
|
||||||
|
content
|
||||||
|
</details>
|
||||||
|
<!-- Sticky Pull Request CommentTypeA -->
|
||||||
|
`
|
||||||
|
}
|
||||||
|
const replaced = `
|
||||||
|
<details>
|
||||||
|
<summary>title</summary>
|
||||||
|
|
||||||
|
content
|
||||||
|
</details>
|
||||||
|
<!-- Sticky Pull Request CommentTypeA -->
|
||||||
|
`
|
||||||
|
test.each`
|
||||||
|
append | hideDetails | previous | expected
|
||||||
|
${false} | ${false} | ${detailsPrevious} | ${undefined}
|
||||||
|
${true} | ${false} | ${nullPrevious} | ${undefined}
|
||||||
|
${true} | ${false} | ${detailsPrevious} | ${detailsPrevious.body}
|
||||||
|
${true} | ${true} | ${nullPrevious} | ${undefined}
|
||||||
|
${true} | ${true} | ${simplePrevious} | ${simplePrevious.body}
|
||||||
|
${true} | ${true} | ${detailsPrevious} | ${replaced}
|
||||||
|
`(
|
||||||
|
"receive $previous, $append, $hideDetails and returns $expected",
|
||||||
|
({append, hideDetails, previous, expected}) => {
|
||||||
|
expect(getBodyOf(previous, append, hideDetails)).toEqual(expected)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ beforeEach(() => {
|
||||||
process.env["INPUT_APPEND"] = "false"
|
process.env["INPUT_APPEND"] = "false"
|
||||||
process.env["INPUT_RECREATE"] = "false"
|
process.env["INPUT_RECREATE"] = "false"
|
||||||
process.env["INPUT_DELETE"] = "false"
|
process.env["INPUT_DELETE"] = "false"
|
||||||
|
process.env["INPUT_HIDE_DETAILS"] = "false"
|
||||||
process.env["INPUT_GITHUB_TOKEN"] = "some-token"
|
process.env["INPUT_GITHUB_TOKEN"] = "some-token"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -17,6 +18,7 @@ afterEach(() => {
|
||||||
delete process.env["INPUT_APPEND"]
|
delete process.env["INPUT_APPEND"]
|
||||||
delete process.env["INPUT_RECREATE"]
|
delete process.env["INPUT_RECREATE"]
|
||||||
delete process.env["INPUT_DELETE"]
|
delete process.env["INPUT_DELETE"]
|
||||||
|
delete process.env["INPUT_HIDE_DETAILS"]
|
||||||
delete process.env["INPUT_GITHUB_TOKEN"]
|
delete process.env["INPUT_GITHUB_TOKEN"]
|
||||||
delete process.env["INPUT_PATH"]
|
delete process.env["INPUT_PATH"]
|
||||||
})
|
})
|
||||||
|
|
@ -31,6 +33,7 @@ test("repo", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -44,6 +47,7 @@ test("header", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -57,6 +61,7 @@ test("append", () => {
|
||||||
append: true,
|
append: true,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -70,6 +75,7 @@ test("recreate", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: true,
|
recreate: true,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -83,6 +89,21 @@ test("delete", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: true,
|
deleteOldComment: true,
|
||||||
|
hideDetails: false,
|
||||||
|
githubToken: "some-token"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
test("hideDetails", () => {
|
||||||
|
process.env["INPUT_HIDE_DETAILS"] = "true"
|
||||||
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
pullRequestNumber: expect.any(Number),
|
||||||
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
|
body: "",
|
||||||
|
header: "",
|
||||||
|
append: false,
|
||||||
|
recreate: false,
|
||||||
|
deleteOldComment: false,
|
||||||
|
hideDetails: true,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -97,6 +118,7 @@ describe("path", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -111,6 +133,7 @@ describe("path", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -126,6 +149,7 @@ test("message", () => {
|
||||||
append: false,
|
append: false,
|
||||||
recreate: false,
|
recreate: false,
|
||||||
deleteOldComment: false,
|
deleteOldComment: false,
|
||||||
|
hideDetails: false,
|
||||||
githubToken: "some-token"
|
githubToken: "some-token"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ inputs:
|
||||||
description: "delete the previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
|
description: "delete the previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
|
||||||
default: "false"
|
default: "false"
|
||||||
required: false
|
required: false
|
||||||
|
hide_details:
|
||||||
|
description: "hide summary tags in the previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
|
||||||
|
default: "false"
|
||||||
|
required: false
|
||||||
message:
|
message:
|
||||||
description: "comment message"
|
description: "comment message"
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
20
dist/index.js
generated
vendored
20
dist/index.js
generated
vendored
|
|
@ -35,7 +35,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
exports.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
function headerComment(header) {
|
function headerComment(header) {
|
||||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||||
|
|
@ -75,6 +75,17 @@ function deleteComment(octokit, repo, comment_id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.deleteComment = deleteComment;
|
exports.deleteComment = deleteComment;
|
||||||
|
function getBodyOf(previous, append, hideDetails) {
|
||||||
|
var _a;
|
||||||
|
if (!append) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!hideDetails) {
|
||||||
|
return previous.body;
|
||||||
|
}
|
||||||
|
return (_a = previous.body) === null || _a === void 0 ? void 0 : _a.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2");
|
||||||
|
}
|
||||||
|
exports.getBodyOf = getBodyOf;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
@ -105,7 +116,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
};
|
};
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.body = exports.githubToken = exports.deleteOldComment = exports.recreate = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
exports.body = exports.githubToken = exports.deleteOldComment = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
const github_1 = __nccwpck_require__(438);
|
const github_1 = __nccwpck_require__(438);
|
||||||
const fs_1 = __nccwpck_require__(747);
|
const fs_1 = __nccwpck_require__(747);
|
||||||
|
|
@ -114,6 +125,9 @@ exports.pullRequestNumber = ((_b = (_a = github_1.context === null || github_1.c
|
||||||
exports.repo = buildRepo();
|
exports.repo = buildRepo();
|
||||||
exports.header = core.getInput("header", { required: false });
|
exports.header = core.getInput("header", { required: false });
|
||||||
exports.append = core.getBooleanInput("append", { required: true });
|
exports.append = core.getBooleanInput("append", { required: true });
|
||||||
|
exports.hideDetails = core.getBooleanInput("hide_details", {
|
||||||
|
required: true
|
||||||
|
});
|
||||||
exports.recreate = core.getBooleanInput("recreate", { required: true });
|
exports.recreate = core.getBooleanInput("recreate", { required: true });
|
||||||
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
||||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||||
|
|
@ -206,7 +220,7 @@ function run() {
|
||||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const previousBody = config_1.append ? previous.body : undefined;
|
const previousBody = (0, comment_1.getBodyOf)(previous, config_1.append, config_1.hideDetails);
|
||||||
if (config_1.recreate) {
|
if (config_1.recreate) {
|
||||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
13
lib/comment.js
generated
13
lib/comment.js
generated
|
|
@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
exports.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
function headerComment(header) {
|
function headerComment(header) {
|
||||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||||
|
|
@ -68,3 +68,14 @@ function deleteComment(octokit, repo, comment_id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.deleteComment = deleteComment;
|
exports.deleteComment = deleteComment;
|
||||||
|
function getBodyOf(previous, append, hideDetails) {
|
||||||
|
var _a;
|
||||||
|
if (!append) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (!hideDetails) {
|
||||||
|
return previous.body;
|
||||||
|
}
|
||||||
|
return (_a = previous.body) === null || _a === void 0 ? void 0 : _a.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2");
|
||||||
|
}
|
||||||
|
exports.getBodyOf = getBodyOf;
|
||||||
|
|
|
||||||
5
lib/config.js
generated
5
lib/config.js
generated
|
|
@ -20,7 +20,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
};
|
};
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.body = exports.githubToken = exports.deleteOldComment = exports.recreate = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
exports.body = exports.githubToken = exports.deleteOldComment = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const github_1 = require("@actions/github");
|
const github_1 = require("@actions/github");
|
||||||
const fs_1 = require("fs");
|
const fs_1 = require("fs");
|
||||||
|
|
@ -29,6 +29,9 @@ exports.pullRequestNumber = ((_b = (_a = github_1.context === null || github_1.c
|
||||||
exports.repo = buildRepo();
|
exports.repo = buildRepo();
|
||||||
exports.header = core.getInput("header", { required: false });
|
exports.header = core.getInput("header", { required: false });
|
||||||
exports.append = core.getBooleanInput("append", { required: true });
|
exports.append = core.getBooleanInput("append", { required: true });
|
||||||
|
exports.hideDetails = core.getBooleanInput("hide_details", {
|
||||||
|
required: true
|
||||||
|
});
|
||||||
exports.recreate = core.getBooleanInput("recreate", { required: true });
|
exports.recreate = core.getBooleanInput("recreate", { required: true });
|
||||||
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
||||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||||
|
|
|
||||||
2
lib/main.js
generated
2
lib/main.js
generated
|
|
@ -55,7 +55,7 @@ function run() {
|
||||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const previousBody = config_1.append ? previous.body : undefined;
|
const previousBody = (0, comment_1.getBodyOf)(previous, config_1.append, config_1.hideDetails);
|
||||||
if (config_1.recreate) {
|
if (config_1.recreate) {
|
||||||
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
yield (0, comment_1.deleteComment)(octokit, config_1.repo, previous.id);
|
||||||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header, previousBody);
|
||||||
|
|
|
||||||
|
|
@ -81,3 +81,19 @@ export async function deleteComment(
|
||||||
comment_id
|
comment_id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBodyOf(
|
||||||
|
previous: {body?: string},
|
||||||
|
append: boolean,
|
||||||
|
hideDetails: boolean
|
||||||
|
): string | undefined {
|
||||||
|
if (!append) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hideDetails) {
|
||||||
|
return previous.body
|
||||||
|
}
|
||||||
|
|
||||||
|
return previous.body?.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ export const pullRequestNumber =
|
||||||
export const repo = buildRepo()
|
export const repo = buildRepo()
|
||||||
export const header = core.getInput("header", {required: false})
|
export const header = core.getInput("header", {required: false})
|
||||||
export const append = core.getBooleanInput("append", {required: true})
|
export const append = core.getBooleanInput("append", {required: true})
|
||||||
|
export const hideDetails = core.getBooleanInput("hide_details", {
|
||||||
|
required: true
|
||||||
|
})
|
||||||
export const recreate = core.getBooleanInput("recreate", {required: true})
|
export const recreate = core.getBooleanInput("recreate", {required: true})
|
||||||
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
|
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
|
||||||
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
|
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
deleteOldComment,
|
deleteOldComment,
|
||||||
githubToken,
|
githubToken,
|
||||||
header,
|
header,
|
||||||
|
hideDetails,
|
||||||
pullRequestNumber,
|
pullRequestNumber,
|
||||||
recreate,
|
recreate,
|
||||||
repo
|
repo
|
||||||
|
|
@ -14,6 +15,7 @@ import {
|
||||||
createComment,
|
createComment,
|
||||||
deleteComment,
|
deleteComment,
|
||||||
findPreviousComment,
|
findPreviousComment,
|
||||||
|
getBodyOf,
|
||||||
updateComment
|
updateComment
|
||||||
} from "./comment"
|
} from "./comment"
|
||||||
|
|
||||||
|
|
@ -50,7 +52,7 @@ async function run(): Promise<undefined> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const previousBody = append ? previous.body : undefined
|
const previousBody = getBodyOf(previous, append, hideDetails)
|
||||||
if (recreate) {
|
if (recreate) {
|
||||||
await deleteComment(octokit, repo, previous.id)
|
await deleteComment(octokit, repo, previous.id)
|
||||||
await createComment(
|
await createComment(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue