Last active
November 12, 2023 23:02
-
-
Save flipdazed/28049c79986fa3b41b5a9d47db25492b to your computer and use it in GitHub Desktop.
Retrieve/Count unresolved review comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script Name: pr-unresolved-review-comments | |
# | |
# Description: | |
# This script is used to fetch unresolved review comments from a pull request in a Github repository. | |
# The script uses Github's GraphQL API to query the repository and filter out resolved comments. | |
# It returns a list of unresolved comment threads, which can then be processed as per requirements. | |
# | |
# Usage: | |
# There are two general use cases for this script. | |
# | |
# 1. Retrieve unresolved review comments: | |
# This will get all unresolved review comments from a particular pull request. | |
# Example usage: | |
# ./pr-unresolved-review-comments myorganisation myrepo 1337 | |
# | |
# 2. Count of unresolved review comment threads: | |
# This will return the count of unresolved review comment threads in a pull request. | |
# To calculate the count we use 'jq' to find the length of the returned list. | |
# Example usage: | |
# ./pr-unresolved-review-comments myorganisation myrepo 1337 | jq length | |
# | |
# Parameters: | |
# - owner: It is the name of the organisation that owns the repository. It is passed as the first positional argument. | |
# - repo: It is the name of the repository from where the pull request is made. It is passed as the second positional argument. | |
# - pr: It is the number of the pull request. It is passed as the third positional argument. | |
# | |
# Output: | |
# This script outputs a JSON data containing the unresolved comments information including author's login, body of the comment, url of the comment. | |
# | |
gh api graphql -f owner="$1" -f repo="$2" -F pr="$3" -f query=' | |
query FetchReviewComments($owner: String!, $repo: String!, $pr: Int!) { | |
repository(owner: $owner, name: $repo) { | |
pullRequest(number: $pr) { | |
url | |
reviewDecision | |
reviewThreads(first: 100) { | |
edges { | |
node { | |
isResolved | |
isOutdated | |
isCollapsed | |
comments(first: 100) { | |
totalCount | |
nodes { | |
author { | |
login | |
} | |
body | |
url | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | jq '.data.repository.pullRequest.reviewThreads.edges | map(select(.node.isResolved == false))' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment