diff --git a/README.md b/README.md index 3ee303e..3251104 100644 --- a/README.md +++ b/README.md @@ -62,22 +62,24 @@ jobs: ## Configuration options -| Input | Location | Description | Required | Default | -| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------- | -------- | ------------------ | -| message | with | The message you'd like displayed, supports Markdown and all valid Unicode characters. | maybe | | -| message-path | with | Path to a message you'd like displayed. Will be read and displayed just like a normal message. | maybe | | -| message-success | with | A message override, printed in case of success. | no | | -| message-failure | with | A message override, printed in case of failure. | no | | -| message-cancelled | with | A message override, printed in case of cancelled. | no | | -| message-skipped | with | A message override, printed in case of skipped. | no | | -| status | with | Required if you want to use message status overrides. | no | {{ job.status }} | -| repo-token | with | Valid GitHub token, either the temporary token GitHub provides or a personal access token. | no | {{ github.token }} | -| message-id | with | Message id to use when searching existing comments. If found, updates the existing (sticky comment). | no | | -| refresh-message-position | with | Should the sticky message be the last one in the PR's feed. | no | false | -| allow-repeats | with | Boolean flag to allow identical messages to be posted each time this action is run. | no | false | -| proxy-url | with | String for your proxy service URL if you'd like this to work with fork-based PRs. | no | | -| issue | with | Optional issue number override. | no | | -| GITHUB_TOKEN | env | Valid GitHub token, can alternatively be defined in the env. | no | | +| Input | Location | Description | Required | Default | +|--------------------------|----------|------------------------------------------------------------------------------------------------------|----------|------------------------------------| +| message | with | The message you'd like displayed, supports Markdown and all valid Unicode characters. | maybe | | +| message-path | with | Path to a message you'd like displayed. Will be read and displayed just like a normal message. | maybe | | +| message-success | with | A message override, printed in case of success. | no | | +| message-failure | with | A message override, printed in case of failure. | no | | +| message-cancelled | with | A message override, printed in case of cancelled. | no | | +| message-skipped | with | A message override, printed in case of skipped. | no | | +| status | with | Required if you want to use message status overrides. | no | {{ job.status }} | +| repo-owner | with | Owner of the repo. | no | {{ github.repository_owner }} | +| repo-name | with | Name of the repo. | no | {{ github.event.repository.name }} | +| repo-token | with | Valid GitHub token, either the temporary token GitHub provides or a personal access token. | no | {{ github.token }} | +| message-id | with | Message id to use when searching existing comments. If found, updates the existing (sticky comment). | no | | +| refresh-message-position | with | Should the sticky message be the last one in the PR's feed. | no | false | +| allow-repeats | with | Boolean flag to allow identical messages to be posted each time this action is run. | no | false | +| proxy-url | with | String for your proxy service URL if you'd like this to work with fork-based PRs. | no | | +| issue | with | Optional issue number override. | no | | +| GITHUB_TOKEN | env | Valid GitHub token, can alternatively be defined in the env. | no | | ## Advanced Uses diff --git a/__tests__/add-pr-comment.test.ts b/__tests__/add-pr-comment.test.ts index dc25207..0822b08 100644 --- a/__tests__/add-pr-comment.test.ts +++ b/__tests__/add-pr-comment.test.ts @@ -15,6 +15,8 @@ const simpleMessage = 'hello world' type Inputs = { message: string | undefined 'message-path': string | undefined + 'repo-owner': string + 'repo-name': string 'repo-token': string 'message-id': string 'allow-repeats': string @@ -28,6 +30,8 @@ type Inputs = { const defaultInputs: Inputs = { message: '', 'message-path': undefined, + 'repo-owner': 'foo', + 'repo-name': 'bar', 'repo-token': repoToken, 'message-id': 'add-pr-comment', 'allow-repeats': 'false', @@ -172,7 +176,7 @@ describe('add-pr-comment action', () => { expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true') }) - it.only('creates a comment in another repo', async () => { + it('creates a comment in another repo', async () => { inputs.message = simpleMessage inputs['repo-owner'] = 'my-owner' inputs['repo-name'] = 'my-repo' diff --git a/action.yml b/action.yml index 625a5b9..b378da1 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,14 @@ inputs: description: "If a message with the same id, this option allow to refresh the position of the message to be the last one posted." default: "false" required: true + repo-owner: + description: "The repo owner." + default: "${{ github.repository_owner }}" + required: true + repo-name: + description: "The repo name." + default: "${{ github.event.repository.name }}" + required: true repo-token: description: "A GitHub token for API access. Defaults to {{ github.token }}." default: "${{ github.token }}" diff --git a/dist/index.js b/dist/index.js index befc874..6d39f31 100644 --- a/dist/index.js +++ b/dist/index.js @@ -99,11 +99,13 @@ const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); const promises_1 = __importDefault(__nccwpck_require__(3977)); async function getInputs() { - var _a, _b, _c; + var _a, _b; const messageIdInput = core.getInput('message-id', { required: false }); const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`; const messageInput = core.getInput('message', { required: false }); const messagePath = core.getInput('message-path', { required: false }); + const repoOwner = core.getInput('repo-owner', { required: true }); + const repoName = core.getInput('repo-name', { required: true }); const repoToken = core.getInput('repo-token', { required: true }); const status = core.getInput('status', { required: true }); const issue = core.getInput('issue', { required: false }); @@ -136,11 +138,7 @@ async function getInputs() { throw new Error('no message, check your message inputs'); } const { payload } = github.context; - const repoFullName = (_a = payload.repository) === null || _a === void 0 ? void 0 : _a.full_name; - if (!repoFullName) { - throw new Error('unable to determine repository from request type'); - } - const [owner, repo] = repoFullName.split('/'); + return { refreshMessagePosition, allowRepeats, @@ -149,11 +147,11 @@ async function getInputs() { proxyUrl, repoToken, status, - issue: issue ? Number(issue) : (_b = payload.issue) === null || _b === void 0 ? void 0 : _b.number, - pullRequestNumber: (_c = payload.pull_request) === null || _c === void 0 ? void 0 : _c.number, + issue: issue ? Number(issue) : (_a = payload.issue) === null || _a === void 0 ? void 0 : _a.number, + pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number, commitSha: github.context.sha, - owner, - repo, + owner: repoOwner || payload.repo.owner, + repo: repoName || payload.repo.repo, }; } exports.getInputs = getInputs; diff --git a/lib/config.js b/lib/config.js index cb22edf..433bd2e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -31,11 +31,13 @@ const core = __importStar(require("@actions/core")); const github = __importStar(require("@actions/github")); const promises_1 = __importDefault(require("node:fs/promises")); async function getInputs() { - var _a, _b, _c; + var _a, _b; const messageIdInput = core.getInput('message-id', { required: false }); const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`; const messageInput = core.getInput('message', { required: false }); const messagePath = core.getInput('message-path', { required: false }); + const repoOwner = core.getInput('repo-owner', { required: true }); + const repoName = core.getInput('repo-name', { required: true }); const repoToken = core.getInput('repo-token', { required: true }); const status = core.getInput('status', { required: true }); const issue = core.getInput('issue', { required: false }); @@ -72,11 +74,6 @@ async function getInputs() { throw new Error('no message, check your message inputs'); } const { payload } = github.context; - const repoFullName = (_a = payload.repository) === null || _a === void 0 ? void 0 : _a.full_name; - if (!repoFullName) { - throw new Error('unable to determine repository from request type'); - } - const [owner, repo] = repoFullName.split('/'); return { refreshMessagePosition, allowRepeats, @@ -85,11 +82,11 @@ async function getInputs() { proxyUrl, repoToken, status, - issue: issue ? Number(issue) : (_b = payload.issue) === null || _b === void 0 ? void 0 : _b.number, - pullRequestNumber: (_c = payload.pull_request) === null || _c === void 0 ? void 0 : _c.number, + issue: issue ? Number(issue) : (_a = payload.issue) === null || _a === void 0 ? void 0 : _a.number, + pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number, commitSha: github.context.sha, - owner, - repo, + owner: repoOwner || payload.repo.owner, + repo: repoName || payload.repo.repo, }; } exports.getInputs = getInputs; diff --git a/src/config.ts b/src/config.ts index 4350e9d..90a7c70 100644 --- a/src/config.ts +++ b/src/config.ts @@ -26,6 +26,8 @@ export async function getInputs(): Promise { const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}` const messageInput = core.getInput('message', { required: false }) const messagePath = core.getInput('message-path', { required: false }) + const repoOwner = core.getInput('repo-owner', { required: true }) + const repoName = core.getInput('repo-name', { required: true }) const repoToken = core.getInput('repo-token', { required: true }) const status = core.getInput('status', { required: true }) const issue = core.getInput('issue', { required: false }) @@ -73,14 +75,6 @@ export async function getInputs(): Promise { const { payload } = github.context - const repoFullName = payload.repository?.full_name - - if (!repoFullName) { - throw new Error('unable to determine repository from request type') - } - - const [owner, repo] = repoFullName.split('/') - return { refreshMessagePosition, allowRepeats, @@ -92,7 +86,7 @@ export async function getInputs(): Promise { issue: issue ? Number(issue) : payload.issue?.number, pullRequestNumber: payload.pull_request?.number, commitSha: github.context.sha, - owner, - repo, + owner: repoOwner || payload.repo.owner, + repo: repoName || payload.repo.repo, } }