DEV Community

Cover image for πŸ“Š Count comments on a GitHub issue 🎫
adriens for opt-nc

Posted on

5 2

πŸ“Š Count comments on a GitHub issue 🎫

☝️ Why counting comments matters ?

There are two type issues with a lot of comments :

1️⃣ The ones that are popular, then getting a lot of feedback πŸ€—
2️⃣ The ones that have a lot of comments because we struggle to fix them efficiently 😱

πŸ‘‰ In both cases, performing report on them can be helpful to monitor your RUN performances.

❔ Count with API calls

☝️ There actually is no native gh issue command to count issues on a specific command...

πŸ‘‰ but gh api...

"Makes an authenticated HTTP request to the GitHub API and prints the response."

gh api <endpoint> [flags]
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ This short post is documenting how easy it is to count comments on a given issue.

πŸ€“ Snippet

gh api -X GET \
  -H "Accept: application/vnd.github.v3+json" \
  -F per_page=100 \
  /repos/YOUR_ORGA/REPO/issues/ISSUEID/comments | \
  jq '. | length'
Enter fullscreen mode Exit fullscreen mode

Image description

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here β†’

Top comments (4)

Collapse
 
jnv profile image
Jan Vlnas β€’

Thanks for the tip!

I can't wrap my head around one thing, though: wouldn't that count comments only up to 100, as more comments would be paginated? πŸ€”

I wonder if issue endpoint would be better for this task, as it seems to contain comments property with the comments count.

Collapse
 
adriens profile image
adriens β€’

Here we go, and thanks a lot for having pointed this to us, see that trick @mbarre :

gh api -X GET \
  -H "Accept: application/vnd.github.v3+json" \
  -F per_page=100 \
  /repos/ORGA/REPO/issues/ISSUID | \
  jq '.comments'
Enter fullscreen mode Exit fullscreen mode

... I could get :

149

within a single shot 😊

Collapse
 
adriens profile image
adriens β€’

Hmmm, that looks pretty interesting indeed !

"comments": 0,

Collapse
 
adriens profile image
adriens β€’

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more