Skip to content

Commit

Permalink
feat: get default issue number (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
thollander committed Nov 28, 2022
1 parent ef5f9c8 commit 0764db8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ _That is particularly interesting while committing multiple times in a PR and th
| `GITHUB_TOKEN` | Token that is used to create comments. Defaults to ${{ github.token }} || |
| `message` | The comment body || |
| `reactions` | List of reactions for the comment (comma separated). See https://docs.github.com/en/rest/reactions#reaction-types | | |
| `pr_number` | The number of the pull request where to create the comment | | current pull request number (deduced from context) |
| `pr_number` | The number of the pull request where to create the comment | | current pull-request/issue number (deduced from context) |
| `comment_includes` | The text that should be used to find comment in case of replacement. | | |

## Contributing
Expand Down
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9548,10 +9548,10 @@ async function run() {
const comment_includes = core.getInput('comment_includes');
const reactions = core.getInput('reactions');
const context = github.context;
const pull_number = parseInt(pr_number) || context.payload.pull_request?.number;
const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number;
const octokit = github.getOctokit(github_token);
if (!pull_number) {
core.setFailed('No pull request in input neither in current context.');
if (!issue_number) {
core.setFailed('No issue/pull request in input neither in current context.');
return;
}
async function addReactions(comment_id, reactions) {
Expand All @@ -9571,7 +9571,7 @@ async function run() {
let comment;
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
...context.repo,
issue_number: pull_number,
issue_number,
})) {
comment = comments.find((comment) => comment?.body?.includes(comment_includes));
if (comment)
Expand All @@ -9592,7 +9592,7 @@ async function run() {
}
const { data: comment } = await octokit.rest.issues.createComment({
...context.repo,
issue_number: pull_number,
issue_number,
body: message,
});
await addReactions(comment.id, reactions);
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ async function run() {
const reactions: string = core.getInput('reactions');

const context = github.context;
const pull_number = parseInt(pr_number) || context.payload.pull_request?.number;
const issue_number = parseInt(pr_number) || context.payload.pull_request?.number || context.payload.issue?.number;

const octokit = github.getOctokit(github_token);

if (!pull_number) {
core.setFailed('No pull request in input neither in current context.');
if (!issue_number) {
core.setFailed('No issue/pull request in input neither in current context.');
return;
}

Expand Down Expand Up @@ -48,7 +48,7 @@ async function run() {
let comment: ListCommentsResponseDataType[0] | undefined;
for await (const { data: comments } of octokit.paginate.iterator(octokit.rest.issues.listComments, {
...context.repo,
issue_number: pull_number,
issue_number,
})) {
comment = comments.find((comment) => comment?.body?.includes(comment_includes));
if (comment) break;
Expand All @@ -69,7 +69,7 @@ async function run() {

const { data: comment } = await octokit.rest.issues.createComment({
...context.repo,
issue_number: pull_number,
issue_number,
body: message,
});

Expand Down

0 comments on commit 0764db8

Please sign in to comment.