Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get default issue number #155

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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