issue-metrics icon indicating copy to clipboard operation
issue-metrics copied to clipboard

Discussions are limited to 100 results

Open zkoppert opened this issue 2 years ago • 5 comments

Seems like some folks might want this to be increased to measure metrics on more than 100 discussions. We could either implement a more reasonable limit or figure out how to handle paging up to the limit of github search results.

zkoppert avatar Jun 30 '23 18:06 zkoppert

Seems like some folks might want this to be increased to measure metrics on more than 100 discussions. We could either implement a more reasonable limit or figure out how to handle paging up to the limit of github search results.

nmamlm avatar Jul 13 '23 17:07 nmamlm

FWIW, I am/was using the following to compute some statistics from GitHub Discussions (Q&A mostly):

OWNER='<owner>'
REPO='<repo>'
CATEGORY='<category-id>'

QUERY='
query($owner: String!, $repo: String!, $category: ID!, $cursor: String) {
  repository(owner: $owner, name: $repo) {
    discussions(first: 100, after: $cursor, categoryId: $category) {
      nodes {
        url
        category {
          name
        }
        createdAt
        updatedAt
        answerChosenAt,
        comments(first: 1) {
          nodes {
            createdAt
            updatedAt
          }
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}
'

CURSOR=$(gh api graphql -f query="$QUERY" -f owner="$OWNER" -f repo="$REPO" -f category="$CATEGORY" | jq -r '.data.repository.discussions.pageInfo | select(.hasNextPage == true) | .endCursor')
RESULTS='[]'
ipage=0
while true; do
  ipage=$((ipage + 1))
  echo "Page: $ipage"
  RESPONSE=$(gh api graphql -f query="$QUERY" -f owner="$OWNER" -f repo="$REPO" -f category="$CATEGORY" -f cursor="$CURSOR")
  RESULTS=$(echo "$RESULTS" | jq --argjson response "$RESPONSE" '. + $response.data.repository.discussions.nodes')
  CURSOR=$(echo "$RESPONSE" | jq -r '.data.repository.discussions.pageInfo | select(.hasNextPage == true) | .endCursor')
  if [ "$CURSOR" = "" ]; then
    break
  fi
done

echo "$RESULTS" | jq 'map({url: .url, category: .category.name, createdAt: .createdAt, updatedAt: .updatedAt, answerChosenAt: .answerChosenAt, commentCreatedAt: .comments.nodes[0].createdAt, commentUpdatedAt: .comments.nodes[0].updatedAt})' > discussions.json

Where the categories ID can be retrieved with:

OWNER='<owner>'
REPO='<repo>'
gh api graphql -f query='
query($owner: String!, $repo: String!) {
  repository(owner: $owner, name: $repo) {
    discussionCategories(first: 10) {
      nodes {
        id
        name
      }
    }
  }
}
' -f owner="$OWNER" -f repo="$REPO" | jq '.data.repository.discussionCategories.nodes'

mcanouil avatar Jul 14 '23 00:07 mcanouil

y

Khlooddeeb avatar Jul 31 '23 05:07 Khlooddeeb

  • @https://1drv.ms/f/s!AiQfd2NdVtYvZ0Fo_LEqhgheQz0

Khlooddeeb avatar Jul 31 '23 06:07 Khlooddeeb

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Mar 14 '24 01:03 github-actions[bot]