Skip to content

Commit

Permalink
✨ only update option
Browse files Browse the repository at this point in the history
  • Loading branch information
marocchino committed Feb 11, 2023
1 parent fe2ab5e commit 4b4f618
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ is explicitly passed, this problem can be solved by just removing it.

### `only_create`

**Optional** Only create a new comment if there is no existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it.
**Optional** Only create a new comment if there is no existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it. This options has higher priority than hide_and_recreate, hide.

### `only_update`

**Optional** Only update a exist comment if there is existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it.

### `hide`

Expand Down
2 changes: 2 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ beforeEach(() => {
process.env["INPUT_RECREATE"] = "false"
process.env["INPUT_DELETE"] = "false"
process.env["INPUT_ONLY_CREATE"] = "false"
process.env["INPUT_ONLY_UPDATE"] = "false"
process.env["INPUT_HIDE"] = "false"
process.env["INPUT_HIDE_AND_RECREATE"] = "false"
process.env["INPUT_HIDE_CLASSIFY"] = "OUTDATED"
Expand All @@ -25,6 +26,7 @@ afterEach(() => {
delete process.env["INPUT_RECREATE"]
delete process.env["INPUT_DELETE"]
delete process.env["INPUT_ONLY_CREATE"]
delete process.env["INPUT_ONLY_UPDATE"]
delete process.env["INPUT_HIDE"]
delete process.env["INPUT_HIDE_AND_RECREATE"]
delete process.env["INPUT_HIDE_CLASSIFY"]
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
description: "only create a new comment if there is no existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it. This options has higher priority than hide_and_recreate, hide."
default: "false"
required: false
only_update:
description: "only update a exist comment if there is existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it."
default: "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"
Expand Down
198 changes: 196 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const deleteOldComment = core.getBooleanInput("delete", {required: true})
export const onlyCreateComment = core.getBooleanInput("only_create", {
required: true
})
export const onlyUpdateComment = core.getBooleanInput("only_update", {
required: true
})
export const hideOldComment = core.getBooleanInput("hide", {required: true})
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
export const ignoreEmpty = core.getBooleanInput("ignore_empty", {
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
recreate,
repo,
ignoreEmpty,
onlyCreateComment
onlyCreateComment,
onlyUpdateComment
} from "./config"
import {
createComment,
Expand Down Expand Up @@ -47,6 +48,10 @@ async function run(): Promise<undefined> {
throw new Error("delete and recreate cannot be both set to true")
}

if (onlyCreateComment && onlyUpdateComment) {
throw new Error("only_create and only_update cannot be both set to true")
}

if (hideOldComment && hideAndRecreate) {
throw new Error("hide and hide_and_recreate cannot be both set to true")
}
Expand All @@ -67,6 +72,9 @@ async function run(): Promise<undefined> {
}

if (!previous) {
if (onlyUpdateComment) {
return
}
await createComment(octokit, repo, pullRequestNumber, body, header)
return
}
Expand Down

0 comments on commit 4b4f618

Please sign in to comment.