Skip to content

Commit

Permalink
deprecate body-file
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans committed Apr 4, 2023
1 parent 07bdbdb commit 25f7cab
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-command.yml
Expand Up @@ -59,7 +59,7 @@ jobs:
uses: ./
with:
issue-number: 1
body-file: .github/comment-body.md
body-path: .github/comment-body.md

# Test create from template
- name: Render template
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -55,8 +55,8 @@ A GitHub action to create or update an issue or pull request comment.
| `repository` | The full name of the repository in which to create or update a comment. | Current repository |
| `issue-number` | The number of the issue or pull request in which to create a comment. | |
| `comment-id` | The id of the comment to update. | |
| `body` | The comment body. Cannot be used in conjunction with `body-file`. | |
| `body-file` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
| `body` | The comment body. Cannot be used in conjunction with `body-path`. | |
| `body-path` | The path to a file containing the comment body. Cannot be used in conjunction with `body`. | |
| `edit-mode` | The mode when updating a comment, `replace` or `append`. | `append` |
| `append-separator` | The separator to use when appending to an existing comment. (`newline`, `space`, `none`) | `newline` |
| `reactions` | A comma or newline separated list of reactions to add to the comment. (`+1`, `-1`, `laugh`, `confused`, `heart`, `hooray`, `rocket`, `eyes`) | |
Expand Down Expand Up @@ -167,7 +167,7 @@ If required, the create and update steps can be separated for greater control.
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: 1
body-file: 'comment-body.md'
body-path: 'comment-body.md'
```

### Using a markdown template
Expand Down
6 changes: 4 additions & 2 deletions action.yml
Expand Up @@ -12,9 +12,11 @@ inputs:
comment-id:
description: 'The id of the comment to update.'
body:
description: 'The comment body. Cannot be used in conjunction with `body-file`.'
body-file:
description: 'The comment body. Cannot be used in conjunction with `body-path`.'
body-path:
description: 'The path to a file containing the comment body. Cannot be used in conjunction with `body`.'
body-file:
description: 'Deprecated in favour of `body-path`.'
edit-mode:
description: 'The mode when updating a comment, "replace" or "append".'
default: 'append'
Expand Down
25 changes: 17 additions & 8 deletions dist/index.js
Expand Up @@ -304,6 +304,15 @@ function getBody(inputs) {
return '';
}
}
function getBodyPathInput() {
const bodyPath = core.getInput('body-path');
if (bodyPath) {
return bodyPath;
}
else {
return core.getInput('body-file');
}
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand All @@ -313,7 +322,7 @@ function run() {
issueNumber: Number(core.getInput('issue-number')),
commentId: Number(core.getInput('comment-id')),
body: core.getInput('body'),
bodyFile: core.getInput('body-file'),
bodyPath: getBodyPathInput(),
editMode: core.getInput('edit-mode'),
appendSeparator: core.getInput('append-separator'),
reactions: utils.getInputAsArray('reactions'),
Expand All @@ -329,23 +338,23 @@ function run() {
if (!['newline', 'space', 'none'].includes(inputs.appendSeparator)) {
throw new Error(`Invalid append-separator '${inputs.appendSeparator}'.`);
}
if (inputs.bodyFile && inputs.body) {
throw new Error("Only one of 'body' or 'body-file' can be set.");
if (inputs.bodyPath && inputs.body) {
throw new Error("Only one of 'body' or 'body-path' can be set.");
}
if (inputs.bodyFile) {
if (!(0, fs_1.existsSync)(inputs.bodyFile)) {
throw new Error(`File '${inputs.bodyFile}' does not exist.`);
if (inputs.bodyPath) {
if (!(0, fs_1.existsSync)(inputs.bodyPath)) {
throw new Error(`File '${inputs.bodyPath}' does not exist.`);
}
}
const body = getBody(inputs);
if (inputs.commentId) {
if (!body && !inputs.reactions) {
throw new Error("Missing comment 'body', 'body-file', or 'reactions'.");
throw new Error("Missing comment 'body', 'body-path', or 'reactions'.");
}
}
else if (inputs.issueNumber) {
if (!body) {
throw new Error("Missing comment 'body' or 'body-file'.");
throw new Error("Missing comment 'body' or 'body-path'.");
}
}
else {
Expand Down
192 changes: 0 additions & 192 deletions index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/create-or-update-comment.ts
Expand Up @@ -9,7 +9,7 @@ export interface Inputs {
issueNumber: number
commentId: number
body: string
bodyFile: string
bodyPath: string
editMode: string
appendSeparator: string
reactions: string[]
Expand Down
25 changes: 17 additions & 8 deletions src/main.ts
Expand Up @@ -14,6 +14,15 @@ function getBody(inputs) {
}
}

function getBodyPathInput(): string {
const bodyPath = core.getInput('body-path')
if (bodyPath) {
return bodyPath
} else {
return core.getInput('body-file')
}
}

async function run(): Promise<void> {
try {
const inputs: Inputs = {
Expand All @@ -22,7 +31,7 @@ async function run(): Promise<void> {
issueNumber: Number(core.getInput('issue-number')),
commentId: Number(core.getInput('comment-id')),
body: core.getInput('body'),
bodyFile: core.getInput('body-file'),
bodyPath: getBodyPathInput(),
editMode: core.getInput('edit-mode'),
appendSeparator: core.getInput('append-separator'),
reactions: utils.getInputAsArray('reactions'),
Expand All @@ -44,25 +53,25 @@ async function run(): Promise<void> {
throw new Error(`Invalid append-separator '${inputs.appendSeparator}'.`)
}

if (inputs.bodyFile && inputs.body) {
throw new Error("Only one of 'body' or 'body-file' can be set.")
if (inputs.bodyPath && inputs.body) {
throw new Error("Only one of 'body' or 'body-path' can be set.")
}

if (inputs.bodyFile) {
if (!existsSync(inputs.bodyFile)) {
throw new Error(`File '${inputs.bodyFile}' does not exist.`)
if (inputs.bodyPath) {
if (!existsSync(inputs.bodyPath)) {
throw new Error(`File '${inputs.bodyPath}' does not exist.`)
}
}

const body = getBody(inputs)

if (inputs.commentId) {
if (!body && !inputs.reactions) {
throw new Error("Missing comment 'body', 'body-file', or 'reactions'.")
throw new Error("Missing comment 'body', 'body-path', or 'reactions'.")
}
} else if (inputs.issueNumber) {
if (!body) {
throw new Error("Missing comment 'body' or 'body-file'.")
throw new Error("Missing comment 'body' or 'body-path'.")
}
} else {
throw new Error("Missing either 'issue-number' or 'comment-id'.")
Expand Down

0 comments on commit 25f7cab

Please sign in to comment.