mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-19 14:35:50 +00:00
✨ hide, hide_and_recreate, hide_classify option
This commit is contained in:
parent
4bc21b7b93
commit
bd4aa7d76d
8 changed files with 124 additions and 11 deletions
47
README.md
47
README.md
|
|
@ -18,7 +18,7 @@ with:
|
|||
|
||||
In some cases, different actions may require different comments. The header allows you to maintain comments independently.
|
||||
|
||||
```yaml
|
||||
````yaml
|
||||
release:
|
||||
...
|
||||
- uses: marocchino/sticky-pull-request-comment@v2
|
||||
|
|
@ -44,11 +44,11 @@ test:
|
|||
```
|
||||
${{ steps.test.outputs.result }}
|
||||
```
|
||||
```
|
||||
````
|
||||
|
||||
### Append after comment every time it runs
|
||||
|
||||
```yaml
|
||||
````yaml
|
||||
test:
|
||||
...
|
||||
- name: Run Test
|
||||
|
|
@ -67,7 +67,7 @@ test:
|
|||
```
|
||||
${{ steps.test.outputs.result }}
|
||||
```
|
||||
```
|
||||
````
|
||||
|
||||
### Comment from push
|
||||
|
||||
|
|
@ -111,10 +111,31 @@ with:
|
|||
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
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -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).
|
||||
|
||||
### `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`
|
||||
|
||||
**Optional** Comment message
|
||||
|
|
|
|||
12
action.yml
12
action.yml
|
|
@ -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."
|
||||
default: "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:
|
||||
description: "comment message"
|
||||
required: false
|
||||
|
|
|
|||
23
dist/index.js
generated
vendored
23
dist/index.js
generated
vendored
|
|
@ -190,7 +190,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
var _a, _b;
|
||||
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 github_1 = __nccwpck_require__(438);
|
||||
const fs_1 = __nccwpck_require__(747);
|
||||
|
|
@ -203,7 +203,14 @@ exports.hideDetails = core.getBooleanInput("hide_details", {
|
|||
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.hideOldComment = core.getBooleanInput("hide", { required: true });
|
||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
exports.body = buildBody();
|
||||
function buildRepo() {
|
||||
|
|
@ -278,12 +285,15 @@ function run() {
|
|||
return;
|
||||
}
|
||||
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");
|
||||
}
|
||||
if (config_1.deleteOldComment && config_1.recreate) {
|
||||
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 previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
if (!previous) {
|
||||
|
|
@ -294,12 +304,21 @@ function run() {
|
|||
yield (0, comment_1.deleteComment)(octokit, previous.id);
|
||||
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);
|
||||
if (config_1.recreate) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
|||
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
9
lib/config.js
generated
9
lib/config.js
generated
|
|
@ -20,7 +20,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
var _a, _b;
|
||||
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 github_1 = require("@actions/github");
|
||||
const fs_1 = require("fs");
|
||||
|
|
@ -33,7 +33,14 @@ exports.hideDetails = core.getBooleanInput("hide_details", {
|
|||
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.hideOldComment = core.getBooleanInput("hide", { required: true });
|
||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
exports.body = buildBody();
|
||||
function buildRepo() {
|
||||
|
|
|
|||
14
lib/main.js
generated
14
lib/main.js
generated
|
|
@ -39,12 +39,15 @@ function run() {
|
|||
return;
|
||||
}
|
||||
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");
|
||||
}
|
||||
if (config_1.deleteOldComment && config_1.recreate) {
|
||||
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 previous = yield (0, comment_1.findPreviousComment)(octokit, config_1.repo, config_1.pullRequestNumber, config_1.header);
|
||||
if (!previous) {
|
||||
|
|
@ -55,12 +58,21 @@ function run() {
|
|||
yield (0, comment_1.deleteComment)(octokit, previous.id);
|
||||
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);
|
||||
if (config_1.recreate) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import * as core from "@actions/core"
|
||||
import {ReportedContentClassifiers} from "@octokit/graphql-schema"
|
||||
import {context} from "@actions/github"
|
||||
import {readFileSync} from "fs"
|
||||
|
||||
|
|
@ -13,7 +14,14 @@ export const hideDetails = core.getBooleanInput("hide_details", {
|
|||
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 hideOldComment = core.getBooleanInput("hide", {required: true})
|
||||
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
|
||||
|
||||
export const body = buildBody()
|
||||
|
|
|
|||
20
src/main.ts
20
src/main.ts
|
|
@ -6,7 +6,10 @@ import {
|
|||
deleteOldComment,
|
||||
githubToken,
|
||||
header,
|
||||
hideAndRecreate,
|
||||
hideClassify,
|
||||
hideDetails,
|
||||
hideOldComment,
|
||||
pullRequestNumber,
|
||||
recreate,
|
||||
repo
|
||||
|
|
@ -16,6 +19,7 @@ import {
|
|||
deleteComment,
|
||||
findPreviousComment,
|
||||
getBodyOf,
|
||||
minimizeComment,
|
||||
updateComment
|
||||
} from "./comment"
|
||||
|
||||
|
|
@ -26,7 +30,7 @@ async function run(): Promise<undefined> {
|
|||
}
|
||||
|
||||
try {
|
||||
if (!deleteOldComment && !body) {
|
||||
if (!deleteOldComment && !hideOldComment && !body) {
|
||||
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")
|
||||
}
|
||||
|
||||
if (hideOldComment && hideAndRecreate) {
|
||||
throw new Error("hide and hide_and_recreate cannot be both set to true")
|
||||
}
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(
|
||||
octokit,
|
||||
|
|
@ -51,6 +59,10 @@ async function run(): Promise<undefined> {
|
|||
await deleteComment(octokit, previous.id)
|
||||
return
|
||||
}
|
||||
if (hideOldComment) {
|
||||
await minimizeComment(octokit, previous.id, hideClassify)
|
||||
return
|
||||
}
|
||||
|
||||
const previousBody = getBodyOf(previous, append, hideDetails)
|
||||
if (recreate) {
|
||||
|
|
@ -66,6 +78,12 @@ async function run(): Promise<undefined> {
|
|||
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)
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue