Skip to content

Instantly share code, notes, and snippets.

@3nids
Created February 6, 2020 06:27
Show Gist options
  • Save 3nids/2bbc384d3882645c5c3e95ae5991049f to your computer and use it in GitHub Desktop.
Save 3nids/2bbc384d3882645c5c3e95ae5991049f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
# This script will use GraphQL Github API to get pull requests on master branch, that has been merged and matching the defined labels (edit the query)
# It will return the last 100 PRs. If totalCount is bigger, you'll need to use pagination in the query
# The results can then be filtered by dates
FROM_DATE="2019-10-25T00:00:00Z"
TO_DATE="2020-02-21T00:00:00Z"
QUERY='query {
repository(name: "qgis", owner: "qgis") {
pullRequests(labels: ["Needs Documentation"], baseRefName: "master", orderBy: {field: UPDATED_AT, direction: DESC}, states: MERGED, first: 100) {
edges {
node {
id
author {
login
}
bodyHTML
title
url
headRefName
baseRefName
mergedAt
}
}
totalCount
}
}
}'
# make it oneliner and escape double quotes
QUERY=$(gsed 's/"/\\"/g' <<< "$(echo $QUERY)")
# get the response
DATA=$(curl -s -H 'Content-Type: application/json' \
-H "Authorization: bearer ${GH_TOKEN}" \
-X POST -d "{ \"query\": \"$QUERY\"}" https://api.github.com/graphql)
# filter by merge date
DATA=$(echo ${DATA} | jq ".data.repository.pullRequests.edges[] | select(.node.mergedAt > \"${FROM_DATE}\") | select( .node.mergedAt < \"${TO_DATE}\" )")
echo ${DATA}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment