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

Support "issue_comment" event #35

Open
josteph opened this issue Jun 7, 2022 · 0 comments
Open

Support "issue_comment" event #35

josteph opened this issue Jun 7, 2022 · 0 comments

Comments

@josteph
Copy link

josteph commented Jun 7, 2022

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"
        }
      },
}
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

No branches or pull requests

1 participant