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

Discussions are limited to 100 results #44

Open
zkoppert opened this issue Jun 30, 2023 · 5 comments
Open

Discussions are limited to 100 results #44

zkoppert opened this issue Jun 30, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers keep

Comments

@zkoppert
Copy link
Member

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 zkoppert added the enhancement New feature or request label Jun 30, 2023
@nmamlm

This comment was marked as off-topic.

@mcanouil
Copy link

mcanouil commented Jul 14, 2023

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'

@Khlooddeeb

This comment was marked as spam.

@Khlooddeeb

This comment was marked as spam.

@zkoppert zkoppert added the good first issue Good for newcomers label Aug 25, 2023
Copy link

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 github-actions bot added the Stale label Mar 14, 2024
@zkoppert zkoppert added keep and removed Stale labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers keep
Projects
None yet
Development

No branches or pull requests

4 participants