diff --git a/README.md b/README.md index 83b7dd62..55b5f6c1 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v3 - name: Comment PR - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: message: | Hello world ! :wave: @@ -35,7 +35,7 @@ You can either pass an absolute filePath or a relative one that will be by defau ```yml - name: PR comment with file - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: filePath: /path/to/file.txt ``` @@ -48,7 +48,7 @@ It takes only valid reactions and adds it to the comment you've just created. (S ```yml - name: PR comment with reactions - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: message: | Hello world ! :wave: @@ -63,7 +63,7 @@ That is particularly useful for manual workflow for instance (`workflow_run`). ```yml ... - name: Comment PR - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: message: | Hello world ! :wave: @@ -83,7 +83,7 @@ _That is particularly interesting while committing multiple times in a PR and th ```yml ... - name: Comment PR with execution number - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: message: | _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_ @@ -101,7 +101,7 @@ This will delete the comment at the end of the job. ```yml ... - name: Write a comment that will be deleted at the end of the job - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 with: message: | The PR is being built... @@ -142,7 +142,7 @@ You can get some outputs from this actions : ```yaml - name: Comment PR - uses: thollander/actions-comment-pull-request@v2 + uses: yorhodes/actions-comment-pull-request@v2 id: hello with: message: | diff --git a/action.yml b/action.yml index c868e869..0f5672be 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: description: 'Message that should be printed in the pull request' filePath: description: 'Path of the file that should be commented' + header: + description: 'Header of the comment' + mdLanguage: + description: 'Syntax highlighting language for the comment (content from filePath)' GITHUB_TOKEN: description: 'Github token of the repository (automatically created by Github)' default: ${{ github.token }} diff --git a/lib/cleanup/index.js b/lib/cleanup/index.js index 49162872..e4baf565 100644 --- a/lib/cleanup/index.js +++ b/lib/cleanup/index.js @@ -9536,8 +9536,8 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const github = __importStar(__nccwpck_require__(5438)); const core = __importStar(__nccwpck_require__(2186)); +const github = __importStar(__nccwpck_require__(5438)); async function run() { try { const github_token = core.getInput('GITHUB_TOKEN'); @@ -9559,7 +9559,7 @@ async function run() { core.setFailed('No issue/pull request in input neither in current context.'); return; } - const comment_tag_pattern = ``; + const comment_tag_pattern = ``; if (comment_tag_pattern) { for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, { ...context.repo, diff --git a/lib/index.js b/lib/index.js index c7410c4d..d862730f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9539,15 +9539,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const fs_1 = __importDefault(__nccwpck_require__(7147)); -const github = __importStar(__nccwpck_require__(5438)); const core = __importStar(__nccwpck_require__(2186)); +const github = __importStar(__nccwpck_require__(5438)); +const fs_1 = __importDefault(__nccwpck_require__(7147)); // See https://docs.github.com/en/rest/reactions#reaction-types const REACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes']; async function run() { try { const message = core.getInput('message'); const filePath = core.getInput('filePath'); + const header = core.getInput('header'); + const mdLanguage = core.getInput('mdLanguage'); const github_token = core.getInput('GITHUB_TOKEN'); const pr_number = core.getInput('pr_number'); const comment_tag = core.getInput('comment_tag'); @@ -9561,6 +9563,17 @@ async function run() { let content = message; if (!message && filePath) { content = fs_1.default.readFileSync(filePath, 'utf8'); + // exit if file is empty (and do not comment) + if (content.length === 0) { + core.info('File is empty. Exiting.'); + return; + } + if (mdLanguage) { + content = `\`\`\`${mdLanguage}\n${content}\n\`\`\``; + } + } + if (header) { + content = `# ${header}\n${content}`; } const context = github.context; const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number; @@ -9617,7 +9630,7 @@ async function run() { return comment; } const comment_tag_pattern = comment_tag - ? `` + ? `` : null; const body = comment_tag_pattern ? `${content}\n${comment_tag_pattern}` : content; if (comment_tag_pattern) { diff --git a/package.json b/package.json index fb81e795..b5ea4731 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/thollander/actions-comment-pull-request" + "url": "git+https://github.com/yorhodes/actions-comment-pull-request" }, "keywords": [ "actions", @@ -23,9 +23,9 @@ "author": "Térence Hollander", "license": "MIT", "bugs": { - "url": "https://github.com/thollander/actions-comment-pull-request/issues" + "url": "https://github.com/yorhodes/actions-comment-pull-request/issues" }, - "homepage": "https://github.com/thollander/actions-comment-pull-request#readme", + "homepage": "https://github.com/yorhodes/actions-comment-pull-request#readme", "dependencies": { "@actions/core": "^1.10.1", "@actions/exec": "^1.0.0", diff --git a/src/cleanup.ts b/src/cleanup.ts index 9ef2bd51..391b2bdc 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -1,6 +1,5 @@ -import * as github from '@actions/github'; import * as core from '@actions/core'; -import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'; +import * as github from '@actions/github'; async function run() { try { @@ -29,7 +28,7 @@ async function run() { return; } - const comment_tag_pattern = ``; + const comment_tag_pattern = ``; if (comment_tag_pattern) { for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, { diff --git a/src/main.ts b/src/main.ts index 62e1ee81..a3828e7d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,7 @@ -import fs from 'fs'; -import * as github from '@actions/github'; import * as core from '@actions/core'; +import * as github from '@actions/github'; import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'; +import fs from 'fs'; // See https://docs.github.com/en/rest/reactions#reaction-types const REACTIONS = ['+1', '-1', 'laugh', 'confused', 'heart', 'hooray', 'rocket', 'eyes'] as const; @@ -11,6 +11,8 @@ async function run() { try { const message: string = core.getInput('message'); const filePath: string = core.getInput('filePath'); + const header: string = core.getInput('header'); + const mdLanguage: string = core.getInput('mdLanguage'); const github_token: string = core.getInput('GITHUB_TOKEN'); const pr_number: string = core.getInput('pr_number'); const comment_tag: string = core.getInput('comment_tag'); @@ -26,6 +28,20 @@ async function run() { let content: string = message; if (!message && filePath) { content = fs.readFileSync(filePath, 'utf8'); + + // exit if file is empty (and do not comment) + if (content.length === 0) { + core.info('File is empty. Exiting.'); + return; + } + + if (mdLanguage) { + content = `\`\`\`${mdLanguage}\n${content}\n\`\`\``; + } + } + + if (header) { + content = `# ${header}\n${content}`; } const context = github.context; @@ -120,7 +136,7 @@ async function run() { } const comment_tag_pattern = comment_tag - ? `` + ? `` : null; const body = comment_tag_pattern ? `${content}\n${comment_tag_pattern}` : content;