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

[BUG]: Rest call to delete comment returns 404 #634

Closed
1 task done
pantelis-karamolegkos opened this issue Nov 14, 2023 · 3 comments
Closed
1 task done

[BUG]: Rest call to delete comment returns 404 #634

pantelis-karamolegkos opened this issue Nov 14, 2023 · 3 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@pantelis-karamolegkos
Copy link

What happened?

I am trying to conditionally delete comments through the following workflow

on:
  pull_request:
    types: [ labeled ]


env:
  GH_TOKEN: ${{ github.token }}

jobs:
  clean-atlantis-comments:
    if: contains( github.event.pull_request.labels.*.name, 'atlantis-clean')
    name: clean atlantis and user comments invoking plan
    runs-on: ubuntu-latest

    steps:

      - name: checkout the project
        uses: actions/checkout@v4

      - name: list pull request comments
        shell: bash
        run: |
          gh pr view ${{ github.event.number }} --json comments > comments.json

      - name: delete comments
        uses: actions/github-script@v6
        with:
          result-encoding: string
          script: |
            const fs = require('fs');
            const jsonData = JSON.parse(fs.readFileSync('comments.json', 'utf-8'));
            const comments = jsonData.comments;
            for (const cmnt of comments) {
              comment_id = cmnt.id
              if (cmnt.author.login == 'pantelis-karamolegkos' || cmnt.body == 'foo') {
                github.rest.issues.deleteComment({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  comment_id: comment_id,
                })
              }
            }

However this fails with

Run actions/github-script@v6
RequestError [HttpError]: Not Found
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:6842:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 404,
  response: {
    url: 'https://api.github.com/repos/MyOrg/MyRepo/issues/comments/IC_kwDODse5xs5r3EqV',
    status: 404,

Versions

Using actions/github-script@v6 which in turn uses @octokit/core version: 5.0.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@pantelis-karamolegkos pantelis-karamolegkos added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 14, 2023
Copy link
Contributor

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@gr2m
Copy link
Contributor

gr2m commented Nov 14, 2023

By default, the github instance is authenticated with the GITHUB_TOKEN provided by GitHub Actions. This token has only access to the current repository. I assume that you are trying to delete a comment in another repository?

I would recommend to register a GitHub App with the needed permissions, install the app on the repositories you need it to have access to, and create an installation access token using https://github.com/actions/create-github-app-token, then pass that token to actions/github-script

For further questions, can you file an issue in https://github.com/actions/github-script?

@gr2m gr2m closed this as completed Nov 14, 2023
@github-project-automation github-project-automation bot moved this from 🆕 Triage to ✅ Done in 🧰 Octokit Active Nov 14, 2023
@gr2m gr2m added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 14, 2023
@pantelis-karamolegkos
Copy link
Author

pantelis-karamolegkos commented Nov 14, 2023

Just for the record any action is taken on the repository the workflow on, is running as the corresponding variables are taken from the current context

owner: context.repo.owner,
repo: context.repo.repo,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Archived in project
Development

No branches or pull requests

2 participants