Skip to content

Conversation

github-actions[bot]
Copy link

Closes #505

Applied changes based on Issue #505.

I’ve added support so that whenever the bot gives a thumbs‑up reaction it first clears its “eyes” reaction on that same event—covering issues, issue‑comments and pull‑request review comments—and I’ve added a unit test suite to lock in that behavior.

Changes in src/github/reactions.ts

  1. Extend removeEyeReaction to also handle pull‐request review comments by calling listForPullRequestReviewComment / deleteForPullRequestReviewComment.
  2. Precede every thumbs‑up with an explicit call to removeEyeReaction inside addThumbUpReaction.
--- a/src/github/reactions.ts
@@ async function removeEyeReaction(…
-    } else if (
-      event.action === 'created' &&
-      'comment' in event &&
-      'issue' in event
-    ) {
-      const reactions = await octokit.rest.reactions.listForIssueComment({
-        ...repo,
-        comment_id: event.comment.id,
-      });
-      for (const reaction of reactions.data) {
-        if (
-          reaction.content === 'eyes' &&
-          reaction.user?.login === 'github-actions[bot]'
-        ) {
-          await octokit.rest.reactions.deleteForIssueComment({
-            ...repo,
-            comment_id: event.comment.id,
-            reaction_id: reaction.id,
-          });
-          core.info(
-            `Removed eye reaction from comment on issue/PR #${event.issue.number}`,
-          );
-          break;
-        }
-      }
-    }
+    } else if (
+      event.action === 'created' &&
+      'comment' in event &&
+      'issue' in event
+    ) {
+      const reactions = await octokit.rest.reactions.listForIssueComment({
+        ...repo,
+        comment_id: event.comment.id,
+      });
+      for (const reaction of reactions.data) {
+        if (
+          reaction.content === 'eyes' &&
+          reaction.user?.login === 'github-actions[bot]'
+        ) {
+          await octokit.rest.reactions.deleteForIssueComment({
+            ...repo,
+            comment_id: event.comment.id,
+            reaction_id: reaction.id,
+          });
+          core.info(
+            `Removed eye reaction from comment on issue/PR #${event.issue.number}`,
+          );
+          break;
+        }
+      }
+    } else if (
+      event.action === 'created' &&
+      'comment' in event &&
+      'pull_request' in event
+    ) {
+      const reactions = await octokit.rest.reactions.listForPullRequestReviewComment({
+        ...repo,
+        comment_id: event.comment.id,
+      });
+      for (const reaction of reactions.data) {
+        if (
+          reaction.content === 'eyes' &&
+          reaction.user?.login === 'github-actions[bot]'
+        ) {
+          await octokit.rest.reactions.deleteForPullRequestReviewComment({
+            ...repo,
+            comment_id: event.comment.id,
+            reaction_id: reaction.id,
+          });
+          core.info(
+            `Removed eye reaction from review comment on PR #${event.pull_request.number}`,
+          );
+          break;
+        }
+      }
+    }
@@ async function addThumbUpReaction(…
-  try {
+  try {
+    await removeEyeReaction(octokit, repo, event);
*** End Patch

【F:src/github/reactions.ts†L102-L124】【F:src/github/reactions.ts†L147-L150】

New tests in __tests__/unit/github/reactions.test.ts

A dedicated test suite now verifies that for each event type (issue, issue‑comment and PR review‑comment), the eyes reaction is removed before a thumbs‑up is applied.

import { jest, describe, it, expect } from '@jest/globals';
import type { Octokit } from 'octokit';
import { addThumbUpReaction } from '../../../src/github/reactions';

describe('addThumbUpReaction', () => {
  const repo = { owner: 'owner', repo: 'repo' };

  it('removes eyes reaction and adds thumbs up to issue', async () => {
    const reactions = { data: [{ content: 'eyes', id: 1, user: { login: 'github-actions[bot]' } }] };
    const octokit = {
      rest: {
        reactions: {
          listForIssue: jest.fn().mockResolvedValue(reactions),
          deleteForIssue: jest.fn().mockResolvedValue({}),
          createForIssue: jest.fn().mockResolvedValue({}),
        },
      },
    } as unknown as Octokit;
    const event: any = { action: 'opened', issue: { number: 5 } };
    await addThumbUpReaction(octokit, repo, event);
    expect(octokit.rest.reactions.deleteForIssue).toHaveBeenCalledWith({
      ...repo,
      issue_number: 5,
      reaction_id: 1,
    });
    expect(octokit.rest.reactions.createForIssue).toHaveBeenCalledWith({
      ...repo,
      issue_number: 5,
      content: '+1',
    });
  });

  it('removes eyes reaction and adds thumbs up to issue comment', async () => {
    const reactions = { data: [{ content: 'eyes', id: 2, user: { login: 'github-actions[bot]' } }] };
    const octokit = {
      rest: {
        reactions: {
          listForIssueComment: jest.fn().mockResolvedValue(reactions),
          deleteForIssueComment: jest.fn().mockResolvedValue({}),
          createForIssueComment: jest.fn().mockResolvedValue({}),
        },
      },
    } as unknown as Octokit;
    const event: any = { action: 'created', comment: { id: 10 }, issue: { number: 6 } };
    await addThumbUpReaction(octokit, repo, event);
    expect(octokit.rest.reactions.deleteForIssueComment).toHaveBeenCalledWith({
      ...repo,
      comment_id: 10,
      reaction_id: 2,
    });
    expect(octokit.rest.reactions.createForIssueComment).toHaveBeenCalledWith({
      ...repo,
      comment_id: 10,
      content: '+1',
    });
  });

  it('removes eyes reaction and adds thumbs up to review comment', async () => {
    const reactions = { data: [{ content: 'eyes', id: 3, user: { login: 'github-actions[bot]' } }] };
    const octokit = {
      rest: {
        reactions: {
          listForPullRequestReviewComment: jest.fn().mockResolvedValue(reactions),
          deleteForPullRequestReviewComment: jest.fn().mockResolvedValue({}),
          createForPullRequestReviewComment: jest.fn().mockResolvedValue({}),
        },
      },
    } as unknown as Octokit;
    const event: any = { action: 'created', comment: { id: 20 }, pull_request: { number: 7 } };
    await addThumbUpReaction(octokit, repo, event);
    expect(octokit.rest.reactions.deleteForPullRequestReviewComment).toHaveBeenCalledWith({
      ...repo,
      comment_id: 20,
      reaction_id: 3,
    });
    expect(octokit.rest.reactions.createForPullRequestReviewComment).toHaveBeenCalledWith({
      ...repo,
      comment_id: 20,
      content: '+1',
    });
  });
});

【F:tests/unit/github/reactions.test.ts†new】


With these changes, adding a thumbs‑up on any issue, issue‑comment, or PR‑review‑comment will properly first remove the bot’s “eyes” reaction.

@YiweiShen YiweiShen merged commit 7343e9c into main Jul 20, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-fix-505-reactions-remove-eye-emoji-before-adding-thumbs-up-reaction branch July 20, 2025 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a thumbs-up in the PR comment should first remove the eye emoji.

1 participant