Skip to content

Support "issue_comment" event #35

Description

@josteph

If an action is triggered via issue_comment, the PR number object might be different.

CI File

on:
  issue_comment:
    types:
      - created

jobs:
  build-comment:
    if: |
      github.event.issue.pull_request &&
        (github.event.comment.body == 'ping')
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v2

      - name: Comment to PR with zipped file
        uses: exercism/pr-commenter-action@v1.3.0
        with:
          github-token: ${{ github.token }}
          config-file: ".github/pr-commenter.yml"

Technical Details

The getPRNumber function needs to be updated

function getPrNumber() {

function getPrNumber() {
  const pullRequest = github.context.payload.pull_request || github.event.issue;
  if (!pullRequest) {
    return undefined;
  }

  return pullRequest.number;
}

GitHub Context Dump

{
    "event": {
      "action": "created",
      "comment": {
        "author_association": "CONTRIBUTOR",
        "body": "e2e",
        "created_at": "2022-04-26T08:47:20Z",
        "html_url": "https://github.com/org/repo-name/pull/173#issuecomment-1109524822",
        "id": 0,
        "issue_url": "https://api.github.com/repos/org/repo-name/issues/173",
        "node_id": "",
        "performed_via_github_app": null,
        "reactions": {
          "+1": 0,
          "-1": 0,
          "confused": 0,
          "eyes": 0,
          "heart": 0,
          "hooray": 0,
          "laugh": 0,
          "rocket": 0,
          "total_count": 0,
          "url": "https://api.github.com/repos/org/repo-name/issues/comments/1109524822/reactions"
        },
        "updated_at": "2022-04-26T08:47:20Z",
        "url": "https://api.github.com/repos/org/repo-name/issues/comments/1109524822",
        "user": {
          "avatar_url": "https://avatars.githubusercontent.com/u/13672022?v=4",
          "events_url": "https://api.github.com/users/user/events{/privacy}",
          "followers_url": "https://api.github.com/users/user/followers",
          "following_url": "https://api.github.com/users/user/following{/other_user}",
          "gists_url": "https://api.github.com/users/user/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/user",
          "id": 13672022,
          "login": "user",
          "node_id": "",
          "organizations_url": "https://api.github.com/users/user/orgs",
          "received_events_url": "https://api.github.com/users/user/received_events",
          "repos_url": "https://api.github.com/users/user/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/user/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/user/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/user"
        }
      },
      "issue": {
        "active_lock_reason": null,
        "assignee": null,
        "assignees": [],
        "author_association": "CONTRIBUTOR",
        "body": "",
        "closed_at": null,
        "comments": 3,
        "comments_url": "https://api.github.com/repos/org/repo-name/issues/173/comments",
        "created_at": "2022-04-26T08:31:23Z",
        "draft": false,
        "events_url": "https://api.github.com/repos/org/repo-name/issues/173/events",
        "html_url": "https://github.com/org/repo-name/pull/173",
        "id": 0,
        "labels": [],
        "labels_url": "https://api.github.com/repos/org/repo-name/issues/173/labels{/name}",
        "locked": false,
        "milestone": null,
        "node_id": "",
        "number": 173,
        "performed_via_github_app": null,
        "pull_request": {
          "diff_url": "https://github.com/org/repo-name/pull/173.diff",
          "html_url": "https://github.com/org/repo-name/pull/173",
          "merged_at": null,
          "patch_url": "https://github.com/org/repo-name/pull/173.patch",
          "url": "https://api.github.com/repos/org/repo-name/pulls/173"
        },
        "reactions": {
          "+1": 0,
          "-1": 0,
          "confused": 0,
          "eyes": 0,
          "heart": 0,
          "hooray": 0,
          "laugh": 0,
          "rocket": 0,
          "total_count": 0,
          "url": "https://api.github.com/repos/org/repo-name/issues/173/reactions"
        },
        "repository_url": "https://api.github.com/repos/org/repo-name",
        "state": "open",
        "timeline_url": "https://api.github.com/repos/org/repo-name/issues/173/timeline",
        "title": "ci: dummy test",
        "updated_at": "2022-04-26T08:47:20Z",
        "url": "https://api.github.com/repos/org/repo-name/issues/173",
        "user": {
          "avatar_url": "https://avatars.githubusercontent.com/u/13672022?v=4",
          "events_url": "https://api.github.com/users/user/events{/privacy}",
          "followers_url": "https://api.github.com/users/user/followers",
          "following_url": "https://api.github.com/users/user/following{/other_user}",
          "gists_url": "https://api.github.com/users/user/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/user",
          "id": 0,
          "login": "user",
          "node_id": "",
          "organizations_url": "https://api.github.com/users/user/orgs",
          "received_events_url": "https://api.github.com/users/user/received_events",
          "repos_url": "https://api.github.com/users/user/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/user/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/user/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/user"
        }
      },
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions