5

Given a commit range, say:

https://github.com/microsoft/msquic/compare/3fb2c1145be48cf5acbca72a4e42d8702e3afbd6...2be77cd39ce39528b00ea698645e369b12187502

Is it possible to get the list of Issues that were closed by these commits?

The only way I can tell is to manually go to each commit, find the corresponding PR, and then see if there were any issues associated with it. Any way to automate that?

Nick Banks
  • 4,298
  • 5
  • 39
  • 65
  • You can probably look at Github's API for Pull Requests. https://developer.github.com/v3/pulls/#link-relations I believe you can get a list of issues corresponding to that PR. So you can traverse the history checking to see if said commit was a PR, if so check if there is an issue attached. – Eric Wang Jul 09 '20 at 06:55

2 Answers2

1

It looks like the nice link at the top of commits that indicates which PR they're associated with comes from an internal API that isn't exposed to the general public. So far as I can tell the way to do this (using the official API and not reverse engineering any internal endpoints) would be to list pull requests (https://developer.github.com/v3/pulls/#list-pull-requests), filter for ones with linked issues, then grab the merge commit (looks like your repo uses merge commits) to determine which PRs have commits in the desired range. Here's an example of how to do that. I didn't include how to get commits for a range, just wanted to demonstrate the github api pieces needed. This script prints out the merge commits with associated issues for a given repo as well as the linked issue.

#!/bin/bash


echo "[" > allResults

i=1
numResults=1
firstRun=1
while [[ $numResults -gt 0 ]]
do
  curl -X GET -u ${GITHUB_USERNAME}:${HOMEBREW_GITHUB_API_TOKEN} "https://api.github.com/repos/microsoft/msquic/pulls?state=closed&page=$i" > page

  numResults=`cat page | jq '. | length'`
  i=$[$i + 1]

  if [[ $numResults -gt 0 ]]
  then
    # bit of nonsense to deal with trailing comma problem
    if [[ $firstRun -ne 1 ]]
    then
      echo "," >> allResults
    fi
    if [[ $firstRun -eq 1 ]]
    then
      firstRun=0
    fi

    cat page | awk 'NR != 1 { print buffer; buffer = $0 }' >> allResults
  fi
done

echo "]" >> allResults

echo "[" > prsWithIssues
# select only PRs with issues then use the crazy awk business to put 
# back the commas in the array
cat allResults | jq '.[] | select(.has_issues == true)' | awk '/^{/ { if (endsWithBrace) {print","$0} else {print} ; endsWithBrace=0} !/^{/ {endsWithBrace=1; print}   /.*\}$/ { endsWithBrace = 1 }' >> prsWithIssues
echo "]" >> prsWithIssues

cat prsWithIssues | jq '.[] | "\(.merge_commit_sha) \(._links.issue.href)"' > mergeCommitToIssueLink
# just printing here, you'll probably want 
# to do a grep for commits in the range you want
cat mergeCommitToIssueLink
joshbooks
  • 489
  • 3
  • 8
0

As @Eric_Wang mentioned in the comment; Github 'Issues' do not (necessarily) associate particular commits or branches, unless manually tagged as much. Merged Github pull requests will, but again, unless they are manually associated with an issue. However (given the time restraints on the bounty) you can use the Preview v3 Commit Search API to do a text grep of issues and PRs that match or reference your given requests. If the time were extended, I'd show you an example, but it is fairly self-explanatory

Geoff Nixon
  • 4,697
  • 2
  • 28
  • 34