mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
add custom owner and repo inputs (#78)
* add custom owner and repo inputs * add test for comment in another repo
This commit is contained in:
parent
7ca8398d28
commit
1605572889
6 changed files with 61 additions and 46 deletions
34
README.md
34
README.md
|
|
@ -62,22 +62,24 @@ jobs:
|
||||||
|
|
||||||
## Configuration options
|
## Configuration options
|
||||||
|
|
||||||
| Input | Location | Description | Required | Default |
|
| Input | Location | Description | Required | Default |
|
||||||
| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------- | -------- | ------------------ |
|
|--------------------------|----------|------------------------------------------------------------------------------------------------------|----------|------------------------------------|
|
||||||
| message | with | The message you'd like displayed, supports Markdown and all valid Unicode characters. | maybe | |
|
| 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-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-success | with | A message override, printed in case of success. | no | |
|
||||||
| message-failure | with | A message override, printed in case of failure. | 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-cancelled | with | A message override, printed in case of cancelled. | no | |
|
||||||
| message-skipped | with | A message override, printed in case of skipped. | 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 }} |
|
| 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 }} |
|
| repo-owner | with | Owner of the repo. | no | {{ github.repository_owner }} |
|
||||||
| message-id | with | Message id to use when searching existing comments. If found, updates the existing (sticky comment). | no | |
|
| repo-name | with | Name of the repo. | no | {{ github.event.repository.name }} |
|
||||||
| refresh-message-position | with | Should the sticky message be the last one in the PR's feed. | no | false |
|
| repo-token | with | Valid GitHub token, either the temporary token GitHub provides or a personal access token. | no | {{ github.token }} |
|
||||||
| allow-repeats | with | Boolean flag to allow identical messages to be posted each time this action is run. | no | false |
|
| message-id | with | Message id to use when searching existing comments. If found, updates the existing (sticky comment). | no | |
|
||||||
| proxy-url | with | String for your proxy service URL if you'd like this to work with fork-based PRs. | no | |
|
| refresh-message-position | with | Should the sticky message be the last one in the PR's feed. | no | false |
|
||||||
| issue | with | Optional issue number override. | no | |
|
| allow-repeats | with | Boolean flag to allow identical messages to be posted each time this action is run. | no | false |
|
||||||
| GITHUB_TOKEN | env | Valid GitHub token, can alternatively be defined in the env. | no | |
|
| 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
|
## Advanced Uses
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ const simpleMessage = 'hello world'
|
||||||
type Inputs = {
|
type Inputs = {
|
||||||
message: string | undefined
|
message: string | undefined
|
||||||
'message-path': string | undefined
|
'message-path': string | undefined
|
||||||
|
'repo-owner': string
|
||||||
|
'repo-name': string
|
||||||
'repo-token': string
|
'repo-token': string
|
||||||
'message-id': string
|
'message-id': string
|
||||||
'allow-repeats': string
|
'allow-repeats': string
|
||||||
|
|
@ -29,6 +31,8 @@ type Inputs = {
|
||||||
const defaultInputs: Inputs = {
|
const defaultInputs: Inputs = {
|
||||||
message: '',
|
message: '',
|
||||||
'message-path': undefined,
|
'message-path': undefined,
|
||||||
|
'repo-owner': 'foo',
|
||||||
|
'repo-name': 'bar',
|
||||||
'repo-token': repoToken,
|
'repo-token': repoToken,
|
||||||
'message-id': 'add-pr-comment',
|
'message-id': 'add-pr-comment',
|
||||||
'allow-repeats': 'false',
|
'allow-repeats': 'false',
|
||||||
|
|
@ -175,6 +179,18 @@ describe('add-pr-comment action', () => {
|
||||||
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('creates a comment in another repo', async () => {
|
||||||
|
const repoOwner = 'my-owner'
|
||||||
|
const repoName = 'my-repo'
|
||||||
|
inputs['repo-owner'] = repoOwner
|
||||||
|
inputs['repo-name'] = repoName
|
||||||
|
repoFullName = `${repoOwner}/${repoName}`
|
||||||
|
|
||||||
|
await expect(run()).resolves.not.toThrow()
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||||
|
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
|
||||||
|
})
|
||||||
|
|
||||||
it('safely exits when no issue can be found [using GITHUB_TOKEN in env]', async () => {
|
it('safely exits when no issue can be found [using GITHUB_TOKEN in env]', async () => {
|
||||||
process.env['GITHUB_TOKEN'] = repoToken
|
process.env['GITHUB_TOKEN'] = repoToken
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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."
|
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"
|
default: "false"
|
||||||
required: true
|
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:
|
repo-token:
|
||||||
description: "A GitHub token for API access. Defaults to {{ github.token }}."
|
description: "A GitHub token for API access. Defaults to {{ github.token }}."
|
||||||
default: "${{ github.token }}"
|
default: "${{ github.token }}"
|
||||||
|
|
|
||||||
18
dist/index.js
vendored
18
dist/index.js
vendored
|
|
@ -99,11 +99,13 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||||
const github = __importStar(__nccwpck_require__(5438));
|
const github = __importStar(__nccwpck_require__(5438));
|
||||||
const promises_1 = __importDefault(__nccwpck_require__(3977));
|
const promises_1 = __importDefault(__nccwpck_require__(3977));
|
||||||
async function getInputs() {
|
async function getInputs() {
|
||||||
var _a, _b, _c;
|
var _a, _b;
|
||||||
const messageIdInput = core.getInput('message-id', { required: false });
|
const messageIdInput = core.getInput('message-id', { required: false });
|
||||||
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
||||||
const messageInput = core.getInput('message', { required: false });
|
const messageInput = core.getInput('message', { required: false });
|
||||||
const messagePath = core.getInput('message-path', { 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 repoToken = core.getInput('repo-token', { required: true });
|
||||||
const status = core.getInput('status', { required: true });
|
const status = core.getInput('status', { required: true });
|
||||||
const issue = core.getInput('issue', { required: false });
|
const issue = core.getInput('issue', { required: false });
|
||||||
|
|
@ -136,11 +138,7 @@ async function getInputs() {
|
||||||
throw new Error('no message, check your message inputs');
|
throw new Error('no message, check your message inputs');
|
||||||
}
|
}
|
||||||
const { payload } = github.context;
|
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 {
|
return {
|
||||||
refreshMessagePosition,
|
refreshMessagePosition,
|
||||||
allowRepeats,
|
allowRepeats,
|
||||||
|
|
@ -149,11 +147,11 @@ async function getInputs() {
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
repoToken,
|
repoToken,
|
||||||
status,
|
status,
|
||||||
issue: issue ? Number(issue) : (_b = payload.issue) === null || _b === void 0 ? void 0 : _b.number,
|
issue: issue ? Number(issue) : (_a = payload.issue) === null || _a === void 0 ? void 0 : _a.number,
|
||||||
pullRequestNumber: (_c = payload.pull_request) === null || _c === void 0 ? void 0 : _c.number,
|
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
||||||
commitSha: github.context.sha,
|
commitSha: github.context.sha,
|
||||||
owner,
|
owner: repoOwner || payload.repo.owner,
|
||||||
repo,
|
repo: repoName || payload.repo.repo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.getInputs = getInputs;
|
exports.getInputs = getInputs;
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,13 @@ const core = __importStar(require("@actions/core"));
|
||||||
const github = __importStar(require("@actions/github"));
|
const github = __importStar(require("@actions/github"));
|
||||||
const promises_1 = __importDefault(require("node:fs/promises"));
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
||||||
async function getInputs() {
|
async function getInputs() {
|
||||||
var _a, _b, _c;
|
var _a, _b;
|
||||||
const messageIdInput = core.getInput('message-id', { required: false });
|
const messageIdInput = core.getInput('message-id', { required: false });
|
||||||
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`;
|
||||||
const messageInput = core.getInput('message', { required: false });
|
const messageInput = core.getInput('message', { required: false });
|
||||||
const messagePath = core.getInput('message-path', { 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 repoToken = core.getInput('repo-token', { required: true });
|
||||||
const status = core.getInput('status', { required: true });
|
const status = core.getInput('status', { required: true });
|
||||||
const issue = core.getInput('issue', { required: false });
|
const issue = core.getInput('issue', { required: false });
|
||||||
|
|
@ -72,11 +74,6 @@ async function getInputs() {
|
||||||
throw new Error('no message, check your message inputs');
|
throw new Error('no message, check your message inputs');
|
||||||
}
|
}
|
||||||
const { payload } = github.context;
|
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 {
|
return {
|
||||||
refreshMessagePosition,
|
refreshMessagePosition,
|
||||||
allowRepeats,
|
allowRepeats,
|
||||||
|
|
@ -85,11 +82,11 @@ async function getInputs() {
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
repoToken,
|
repoToken,
|
||||||
status,
|
status,
|
||||||
issue: issue ? Number(issue) : (_b = payload.issue) === null || _b === void 0 ? void 0 : _b.number,
|
issue: issue ? Number(issue) : (_a = payload.issue) === null || _a === void 0 ? void 0 : _a.number,
|
||||||
pullRequestNumber: (_c = payload.pull_request) === null || _c === void 0 ? void 0 : _c.number,
|
pullRequestNumber: (_b = payload.pull_request) === null || _b === void 0 ? void 0 : _b.number,
|
||||||
commitSha: github.context.sha,
|
commitSha: github.context.sha,
|
||||||
owner,
|
owner: repoOwner || payload.repo.owner,
|
||||||
repo,
|
repo: repoName || payload.repo.repo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.getInputs = getInputs;
|
exports.getInputs = getInputs;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ export async function getInputs(): Promise<Inputs> {
|
||||||
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`
|
const messageId = messageIdInput === '' ? 'add-pr-comment' : `add-pr-comment:${messageIdInput}`
|
||||||
const messageInput = core.getInput('message', { required: false })
|
const messageInput = core.getInput('message', { required: false })
|
||||||
const messagePath = core.getInput('message-path', { 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 repoToken = core.getInput('repo-token', { required: true })
|
||||||
const status = core.getInput('status', { required: true })
|
const status = core.getInput('status', { required: true })
|
||||||
const issue = core.getInput('issue', { required: false })
|
const issue = core.getInput('issue', { required: false })
|
||||||
|
|
@ -73,14 +75,6 @@ export async function getInputs(): Promise<Inputs> {
|
||||||
|
|
||||||
const { payload } = github.context
|
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 {
|
return {
|
||||||
refreshMessagePosition,
|
refreshMessagePosition,
|
||||||
allowRepeats,
|
allowRepeats,
|
||||||
|
|
@ -92,7 +86,7 @@ export async function getInputs(): Promise<Inputs> {
|
||||||
issue: issue ? Number(issue) : payload.issue?.number,
|
issue: issue ? Number(issue) : payload.issue?.number,
|
||||||
pullRequestNumber: payload.pull_request?.number,
|
pullRequestNumber: payload.pull_request?.number,
|
||||||
commitSha: github.context.sha,
|
commitSha: github.context.sha,
|
||||||
owner,
|
owner: repoOwner || payload.repo.owner,
|
||||||
repo,
|
repo: repoName || payload.repo.repo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue