minimize comment (#472)

*  minimize comment

*  hide, hide_and_recreate, hide_classify option

*  update config test
This commit is contained in:
marocchino 2021-10-21 02:20:24 +09:00 committed by GitHub
parent 3c38ed8cd4
commit 39c5b5dc77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 272 additions and 16 deletions

View file

@ -18,7 +18,7 @@ with:
In some cases, different actions may require different comments. The header allows you to maintain comments independently. In some cases, different actions may require different comments. The header allows you to maintain comments independently.
```yaml ````yaml
release: release:
... ...
- uses: marocchino/sticky-pull-request-comment@v2 - uses: marocchino/sticky-pull-request-comment@v2
@ -44,11 +44,11 @@ test:
``` ```
${{ steps.test.outputs.result }} ${{ steps.test.outputs.result }}
``` ```
``` ````
### Append after comment every time it runs ### Append after comment every time it runs
```yaml ````yaml
test: test:
... ...
- name: Run Test - name: Run Test
@ -67,7 +67,7 @@ test:
``` ```
${{ steps.test.outputs.result }} ${{ steps.test.outputs.result }}
``` ```
``` ````
### Comment from push ### Comment from push
@ -111,10 +111,31 @@ with:
delete: true delete: true
``` ```
### Hide the previous comment and add a comment at the end
```yaml
uses: marocchino/sticky-pull-request-comment@v2
with:
hide_and_recreate: true
hide_classify: "OUTDATED"
message: |
Release ${{ github.sha }} to <https://pr-${{ github.event.number }}.example.com>
```
### Hide previous comment
```yaml
uses: marocchino/sticky-pull-request-comment@v2
with:
header: <same-header-as-the-step-that-added-the-comment>
hide: true
hide_classify: "OUTDATED"
```
### Error: Resource not accessible by integration ### Error: Resource not accessible by integration
This message means the requester does not have enough permission. If `secrets.GITHUB_TOKEN` This message means the requester does not have enough permission. If `secrets.GITHUB_TOKEN`
is explicitly passed, this problem can be solved by just removing it. is explicitly passed, this problem can be solved by just removing it.
## Inputs ## Inputs
@ -134,6 +155,22 @@ is explicitly passed, this problem can be solved by just removing it.
**Optional** Delete a previously created comment. Use `header` to point to which comment you want to delete. Only `true` is allowed (i.e. delete this option if you don't need it). **Optional** Delete a previously created comment. Use `header` to point to which comment you want to delete. Only `true` is allowed (i.e. delete this option if you don't need it).
### `hide`
**Optional** Hide a previously created comment. Use `header` to point to which comment you want to delete. Only `true` is allowed (i.e. delete this option if you don't need it).
### `hide_classify`
**Optional** The reasons a piece of content can be reported or minimized. SPAM, ABUSE, OFF_TOPIC, OUTDATED, DUPLICATE, RESOLVED are available. default is OUTDATED.
### `hide_details`
**Optional** Hide summary tags in the previously created comment. Only `true` is allowed. Just skip this item when you don't need it.
### `hide_and_recreate`
**Optional** Indicate if previous comment should be removed before creating a new comment. Only `true` is allowed. Just skip this option when you don't need it.
### `message` ### `message`
**Optional** Comment message **Optional** Comment message

View file

@ -6,7 +6,8 @@ import {
deleteComment, deleteComment,
findPreviousComment, findPreviousComment,
getBodyOf, getBodyOf,
updateComment updateComment,
minimizeComment
} from "../src/comment" } from "../src/comment"
jest.mock("@actions/core", () => ({ jest.mock("@actions/core", () => ({
@ -198,6 +199,19 @@ it("deleteComment", async () => {
}) })
}) })
it("minimizeComment", async () => {
const octokit = getOctokit("github-token")
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
expect(await minimizeComment(octokit, "456", "OUTDATED")).toBeUndefined()
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
input: {
subjectId: "456",
classifier: "OUTDATED"
}
})
})
describe("getBodyOf", () => { describe("getBodyOf", () => {
const nullPrevious = {} const nullPrevious = {}
const simplePrevious = { const simplePrevious = {

View file

@ -4,6 +4,9 @@ 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"] = "false"
process.env["INPUT_HIDE_AND_RECREATE"] = "false"
process.env["INPUT_HIDE_CLASSIFY"] = "OUTDATED"
process.env["INPUT_HIDE_DETAILS"] = "false" process.env["INPUT_HIDE_DETAILS"] = "false"
process.env["INPUT_GITHUB_TOKEN"] = "some-token" process.env["INPUT_GITHUB_TOKEN"] = "some-token"
}) })
@ -18,6 +21,9 @@ 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"]
delete process.env["INPUT_HIDE_AND_RECREATE"]
delete process.env["INPUT_HIDE_CLASSIFY"]
delete process.env["INPUT_HIDE_DETAILS"] 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"]
@ -33,6 +39,9 @@ test("repo", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -47,6 +56,9 @@ test("header", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -61,6 +73,9 @@ test("append", () => {
append: true, append: true,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -75,6 +90,9 @@ test("recreate", () => {
append: false, append: false,
recreate: true, recreate: true,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -89,6 +107,60 @@ test("delete", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: true, deleteOldComment: true,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false,
githubToken: "some-token"
})
})
test("hideOldComment", () => {
process.env["INPUT_HIDE"] = "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,
hideOldComment: true,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false,
githubToken: "some-token"
})
})
test("hideAndRecreate", () => {
process.env["INPUT_HIDE_AND_RECREATE"] = "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,
hideOldComment: false,
hideAndRecreate: true,
hideClassify: 'OUTDATED',
hideDetails: false,
githubToken: "some-token"
})
})
test("hideClassify", () => {
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
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,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OFF_TOPIC',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -103,6 +175,9 @@ test("hideDetails", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: true, hideDetails: true,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -118,6 +193,9 @@ describe("path", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -133,6 +211,9 @@ describe("path", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })
@ -149,6 +230,9 @@ test("message", () => {
append: false, append: false,
recreate: false, recreate: false,
deleteOldComment: false, deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: 'OUTDATED',
hideDetails: false, hideDetails: false,
githubToken: "some-token" githubToken: "some-token"
}) })

View file

@ -22,6 +22,18 @@ inputs:
description: "hide summary tags in the previously created comment. Only `true` is allowed. Just skip this item when you don't need it." 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" default: "false"
required: false required: false
hide:
description: "hide previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
default: "false"
required: false
hide_and_recreate:
description: "Indicate if previous comment should be hide before creating a new comment. Only `true` is allowed. Just skip this item when you don't need it."
default: "false"
required: false
hide_classify:
description: "The reasons a piece of content can be reported or minimized. SPAM, ABUSE, OFF_TOPIC, OUTDATED, DUPLICATE, RESOLVED."
default: "OUTDATED"
required: false
message: message:
description: "comment message" description: "comment message"
required: false required: false

37
dist/index.js generated vendored
View file

@ -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.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0; exports.getBodyOf = exports.minimizeComment = 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} -->`;
@ -137,6 +137,18 @@ function deleteComment(octokit, id) {
}); });
} }
exports.deleteComment = deleteComment; exports.deleteComment = deleteComment;
function minimizeComment(octokit, subjectId, classifier) {
return __awaiter(this, void 0, void 0, function* () {
yield octokit.graphql(`
mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) {
clientMutationId
}
}
`, { input: { subjectId, classifier } });
});
}
exports.minimizeComment = minimizeComment;
function getBodyOf(previous, append, hideDetails) { function getBodyOf(previous, append, hideDetails) {
var _a; var _a;
if (!append) { if (!append) {
@ -178,7 +190,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.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0; exports.body = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = 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);
@ -191,7 +203,14 @@ exports.hideDetails = core.getBooleanInput("hide_details", {
required: true required: true
}); });
exports.recreate = core.getBooleanInput("recreate", { required: true }); exports.recreate = core.getBooleanInput("recreate", { required: true });
exports.hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
required: true
});
exports.hideClassify = core.getInput("hide_classify", {
required: true
});
exports.deleteOldComment = core.getBooleanInput("delete", { required: true }); exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
exports.hideOldComment = core.getBooleanInput("hide", { required: true });
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true }); exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
exports.body = buildBody(); exports.body = buildBody();
function buildRepo() { function buildRepo() {
@ -266,12 +285,15 @@ function run() {
return; return;
} }
try { try {
if (!config_1.deleteOldComment && !config_1.body) { if (!config_1.deleteOldComment && !config_1.hideOldComment && !config_1.body) {
throw new Error("Either message or path input is required"); throw new Error("Either message or path input is required");
} }
if (config_1.deleteOldComment && config_1.recreate) { if (config_1.deleteOldComment && config_1.recreate) {
throw new Error("delete and recreate cannot be both set to true"); throw new Error("delete and recreate cannot be both set to true");
} }
if (config_1.hideOldComment && config_1.hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true");
}
const octokit = github.getOctokit(config_1.githubToken); const octokit = github.getOctokit(config_1.githubToken);
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header); const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
if (!previous) { if (!previous) {
@ -282,12 +304,21 @@ function run() {
yield (0, comment_1.deleteComment)(octokit, previous.id); yield (0, comment_1.deleteComment)(octokit, previous.id);
return; return;
} }
if (config_1.hideOldComment) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
return;
}
const previousBody = (0, comment_1.getBodyOf)(previous, config_1.append, config_1.hideDetails); 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, previous.id); yield (0, comment_1.deleteComment)(octokit, 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);
return; return;
} }
if (config_1.hideAndRecreate) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
return;
}
yield (0, comment_1.updateComment)(octokit, previous.id, config_1.body, config_1.header, previousBody); yield (0, comment_1.updateComment)(octokit, previous.id, config_1.body, config_1.header, previousBody);
} }
catch (error) { catch (error) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

14
lib/comment.js generated
View file

@ -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.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0; exports.getBodyOf = exports.minimizeComment = 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} -->`;
@ -130,6 +130,18 @@ function deleteComment(octokit, id) {
}); });
} }
exports.deleteComment = deleteComment; exports.deleteComment = deleteComment;
function minimizeComment(octokit, subjectId, classifier) {
return __awaiter(this, void 0, void 0, function* () {
yield octokit.graphql(`
mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) {
clientMutationId
}
}
`, { input: { subjectId, classifier } });
});
}
exports.minimizeComment = minimizeComment;
function getBodyOf(previous, append, hideDetails) { function getBodyOf(previous, append, hideDetails) {
var _a; var _a;
if (!append) { if (!append) {

9
lib/config.js generated
View file

@ -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.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0; exports.body = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = 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");
@ -33,7 +33,14 @@ exports.hideDetails = core.getBooleanInput("hide_details", {
required: true required: true
}); });
exports.recreate = core.getBooleanInput("recreate", { required: true }); exports.recreate = core.getBooleanInput("recreate", { required: true });
exports.hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
required: true
});
exports.hideClassify = core.getInput("hide_classify", {
required: true
});
exports.deleteOldComment = core.getBooleanInput("delete", { required: true }); exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
exports.hideOldComment = core.getBooleanInput("hide", { required: true });
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true }); exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
exports.body = buildBody(); exports.body = buildBody();
function buildRepo() { function buildRepo() {

14
lib/main.js generated
View file

@ -39,12 +39,15 @@ function run() {
return; return;
} }
try { try {
if (!config_1.deleteOldComment && !config_1.body) { if (!config_1.deleteOldComment && !config_1.hideOldComment && !config_1.body) {
throw new Error("Either message or path input is required"); throw new Error("Either message or path input is required");
} }
if (config_1.deleteOldComment && config_1.recreate) { if (config_1.deleteOldComment && config_1.recreate) {
throw new Error("delete and recreate cannot be both set to true"); throw new Error("delete and recreate cannot be both set to true");
} }
if (config_1.hideOldComment && config_1.hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true");
}
const octokit = github.getOctokit(config_1.githubToken); const octokit = github.getOctokit(config_1.githubToken);
const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header); const previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
if (!previous) { if (!previous) {
@ -55,12 +58,21 @@ function run() {
yield (0, comment_1.deleteComment)(octokit, previous.id); yield (0, comment_1.deleteComment)(octokit, previous.id);
return; return;
} }
if (config_1.hideOldComment) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
return;
}
const previousBody = (0, comment_1.getBodyOf)(previous, config_1.append, config_1.hideDetails); 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, previous.id); yield (0, comment_1.deleteComment)(octokit, 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);
return; return;
} }
if (config_1.hideAndRecreate) {
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.body, config_1.header);
return;
}
yield (0, comment_1.updateComment)(octokit, previous.id, config_1.body, config_1.header, previousBody); yield (0, comment_1.updateComment)(octokit, previous.id, config_1.body, config_1.header, previousBody);
} }
catch (error) { catch (error) {

View file

@ -1,5 +1,10 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import {IssueComment, Repository, User} from "@octokit/graphql-schema" import {
IssueComment,
ReportedContentClassifiers,
Repository,
User
} from "@octokit/graphql-schema"
import {GitHub} from "@actions/github/lib/utils" import {GitHub} from "@actions/github/lib/utils"
function headerComment(header: String): string { function headerComment(header: String): string {
@ -14,7 +19,7 @@ export async function findPreviousComment(
}, },
number: number, number: number,
header: string header: string
): Promise<{body: string; id: string} | undefined> { ): Promise<IssueComment | undefined> {
let after = null let after = null
let hasNextPage = true let hasNextPage = true
const h = headerComment(header) const h = headerComment(header)
@ -133,6 +138,22 @@ export async function deleteComment(
{id} {id}
) )
} }
export async function minimizeComment(
octokit: InstanceType<typeof GitHub>,
subjectId: string,
classifier: ReportedContentClassifiers
): Promise<void> {
await octokit.graphql(
`
mutation($input: MinimizeCommentInput!) {
minimizeComment(input: $input) {
clientMutationId
}
}
`,
{input: {subjectId, classifier}}
)
}
export function getBodyOf( export function getBodyOf(
previous: {body?: string}, previous: {body?: string},

View file

@ -1,4 +1,5 @@
import * as core from "@actions/core" import * as core from "@actions/core"
import {ReportedContentClassifiers} from "@octokit/graphql-schema"
import {context} from "@actions/github" import {context} from "@actions/github"
import {readFileSync} from "fs" import {readFileSync} from "fs"
@ -13,7 +14,14 @@ export const hideDetails = core.getBooleanInput("hide_details", {
required: true required: true
}) })
export const recreate = core.getBooleanInput("recreate", {required: true}) export const recreate = core.getBooleanInput("recreate", {required: true})
export const hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
required: true
})
export const hideClassify = core.getInput("hide_classify", {
required: true
}) as ReportedContentClassifiers
export const deleteOldComment = core.getBooleanInput("delete", {required: true}) export const deleteOldComment = core.getBooleanInput("delete", {required: true})
export const hideOldComment = core.getBooleanInput("hide", {required: true})
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true}) export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
export const body = buildBody() export const body = buildBody()

View file

@ -6,7 +6,10 @@ import {
deleteOldComment, deleteOldComment,
githubToken, githubToken,
header, header,
hideAndRecreate,
hideClassify,
hideDetails, hideDetails,
hideOldComment,
pullRequestNumber, pullRequestNumber,
recreate, recreate,
repo repo
@ -16,6 +19,7 @@ import {
deleteComment, deleteComment,
findPreviousComment, findPreviousComment,
getBodyOf, getBodyOf,
minimizeComment,
updateComment updateComment
} from "./comment" } from "./comment"
@ -26,7 +30,7 @@ async function run(): Promise<undefined> {
} }
try { try {
if (!deleteOldComment && !body) { if (!deleteOldComment && !hideOldComment && !body) {
throw new Error("Either message or path input is required") throw new Error("Either message or path input is required")
} }
@ -34,6 +38,10 @@ async function run(): Promise<undefined> {
throw new Error("delete and recreate cannot be both set to true") throw new Error("delete and recreate cannot be both set to true")
} }
if (hideOldComment && hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true")
}
const octokit = github.getOctokit(githubToken) const octokit = github.getOctokit(githubToken)
const previous = await findPreviousComment( const previous = await findPreviousComment(
octokit, octokit,
@ -51,6 +59,10 @@ async function run(): Promise<undefined> {
await deleteComment(octokit, previous.id) await deleteComment(octokit, previous.id)
return return
} }
if (hideOldComment) {
await minimizeComment(octokit, previous.id, hideClassify)
return
}
const previousBody = getBodyOf(previous, append, hideDetails) const previousBody = getBodyOf(previous, append, hideDetails)
if (recreate) { if (recreate) {
@ -66,6 +78,12 @@ async function run(): Promise<undefined> {
return return
} }
if (hideAndRecreate) {
await minimizeComment(octokit, previous.id, hideClassify)
await createComment(octokit, repo, pullRequestNumber, body, header)
return
}
await updateComment(octokit, previous.id, body, header, previousBody) await updateComment(octokit, previous.id, body, header, previousBody)
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof Error) {