Git Product home page Git Product logo

Comments (8)

shenxianpeng avatar shenxianpeng commented on June 3, 2024 1

Tested again and found that this issue was caused by headers=API_HEADERS. So the public repository might don't need to pass in headers.

When headers=API_HEADERS exist, reproduce the error

import requests
from requests import Response

class Globals:
    response_buffer = Response()


API_HEADERS = {"Accept": "application/vnd.github.v3.text+json",}
# if GITHUB_TOKEN:
#     API_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}"

comments_url = 'https://api.github.com/repos/shenxianpeng/cpp-linter-action/commits/f4c83bab3681622d96b63bc60abeec966bdf4968/comments'
Globals.response_buffer = requests.get(comments_url, headers=API_HEADERS)

comments = Globals.response_buffer.json()
for comment in comments:
    if (comment["body"].startswith("<!-- cpp linter action -->")): 
        print("Success")
$ python3 test.py 
Traceback (most recent call last):
  File "test.py", line 17, in <module>
    if (comment["body"].startswith("<!-- cpp linter action -->")): 
KeyError: 'body'

When headers=API_HEADERS not exist, run again, success.

import requests
from requests import Response

class Globals:
    response_buffer = Response()


API_HEADERS = {"Accept": "application/vnd.github.v3.text+json",}
# if GITHUB_TOKEN:
#     API_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}"

comments_url = 'https://api.github.com/repos/shenxianpeng/cpp-linter-action/commits/f4c83bab3681622d96b63bc60abeec966bdf4968/comments'
Globals.response_buffer = requests.get(comments_url)

comments = Globals.response_buffer.json()
for comment in comments:
    if (comment["body"].startswith("<!-- cpp linter action -->")): 
        print("Success")
$ python3 test.py 
Success

from cpp-linter-action.

2bndy5 avatar 2bndy5 commented on June 3, 2024 1

If that's the case, then it should be an easy fix.

from cpp-linter-action.

2bndy5 avatar 2bndy5 commented on June 3, 2024 1

ok I pushed the fix for unnecessarily using a token when fetching the thread comments on the update-thread-comments branch

from cpp-linter-action.

2bndy5 avatar 2bndy5 commented on June 3, 2024

Getting this error on a public repo makes me think github has changed how a thread's comments are returned. If they switch everything from using body to body_text field, then we may not be able to continue using an HTML comment to identify a bot's comment from other actions' bot comments.

Personally, I find the bot comments to be annoying, so I always disable them.

from cpp-linter-action.

shenxianpeng avatar shenxianpeng commented on June 3, 2024

See from the comments_url: https://api.github.com/repos/shenxianpeng/cpp-linter-action/commits/f4c83bab3681622d96b63bc60abeec966bdf4968/comments, it seems still using body

Personally, I find the bot comments to be annoying, so I always disable them.

So we could change thread-comments default value to false. your thoughts?

from cpp-linter-action.

2bndy5 avatar 2bndy5 commented on June 3, 2024

Changing the default value will only abate the issue. I'm not sure why the error is happening.

This is what I saw when I looked into the error on the test private repo
[
    {
        "url": "https://api.github.com/repos/shenxianpeng/test-cpp-linter-action/issues/comments/1074807551",
        "html_url": "https://github.com/shenxianpeng/test-cpp-linter-action/pull/10#issuecomment-1074807551",
        "issue_url": "https://api.github.com/repos/shenxianpeng/test-cpp-linter-action/issues/10",
        "id": 1074807551,
        "node_id": "IC_kwDOFY2uzM5AEEL_",
        "user": {
            "login": "github-actions[bot]",
            "id": 41898282,
            "node_id": "MDM6Qm90NDE4OTgyODI=",
            "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/github-actions%5Bbot%5D",
            "html_url": "https://github.com/apps/github-actions",
            "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
            "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
            "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
            "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
            "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
            "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
            "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
            "type": "Bot",
            "site_admin": false
        },
        "created_at": "2022-03-22T07:04:40Z",
        "updated_at": "2022-03-22T07:04:40Z",
        "author_association": "NONE",
        "body_text": "\ud83d\udcdc Run clang-format on the following files\n\n demo.hpp\n demo.cpp\n\n\n\ud83d\udcac Output from clang-tidy\ndemo.hpp\n\ndemo.hpp:10:11: warning: [modernize-use-trailing-return-type]\n\nuse a trailing return type for this function\n\n\n    void *not_usefull(char *str){\n    ~~~~~~^\n    auto                         -> void *\n\n\n\ndemo.hpp:12:16: warning: [modernize-use-nullptr]\n\nuse nullptr\n\n\n        return 0;\n               ^\n               nullptr\n\n\ndemo.cpp\n\ndemo.cpp:5:5: warning: [modernize-use-trailing-return-type]\n\nuse a trailing return type for this function\n\n\nint main()\n~~~ ^\nauto       -> int\n\n\n\ndemo.cpp:7:13: warning: [readability-braces-around-statements]\n\nstatement should be inside braces\n\n\n    for (;;)\n            ^\n             {\n\n\n\ndemo.cpp:10:5: warning: [cppcoreguidelines-pro-type-vararg]\n\ndo not call c-style vararg functions\n\n\n    printf(\"Hello world!\\n\");\n    ^",
        "reactions": {
            "url": "https://api.github.com/repos/shenxianpeng/test-cpp-linter-action/issues/comments/1074807551/reactions",
            "total_count": 0,
            "+1": 0,
            "-1": 0,
            "laugh": 0,
            "hooray": 0,
            "confused": 0,
            "heart": 0,
            "rocket": 0,
            "eyes": 0
        },
        "performed_via_github_app": null
    },
]

from cpp-linter-action.

shenxianpeng avatar shenxianpeng commented on June 3, 2024

OK, got your point. The current bug is weird and cannot be reproduced using comments_url https://api.github.com/repos/shenxianpeng/cpp-linter-action/commits/f4c83bab3681622d96b63bc60abeec966bdf4968/comments

from cpp-linter-action.

2bndy5 avatar 2bndy5 commented on June 3, 2024

The comments_url is slightly different for PR vs push events. If I had to guess, I'd say the remove_bot_comments() is iterating over the fetched thread comments incorrectly??

from cpp-linter-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.