(Post this here in case it's helpful for anyone else looking to get Issues linked to a Pull Request)
There's no direct way of getting a list of Issues linked to a Pull Request.
But each Pull Request includes a timeline of events and one of those events is when an Issue gets linked. Using the timeline of events I was able to write a GitHub APIv4 API request and some javascript to get the Issues linked to a PR:
First, here's the GraphQL query:
{
resource(url: "https://github.com/Org/Project/pull/1234") {
... on PullRequest {
timelineItems(itemTypes: [CONNECTED_EVENT, DISCONNECTED_EVENT], first: 100) {
nodes {
... on ConnectedEvent {
id
subject {
... on Issue {
number
}
}
}
... on DisconnectedEvent {
id
subject {
... on Issue {
number
}
}
}
}
}
}
}
}
If you run this in the GitHub GraphQL Explorer (https://developer.github.com/v4/explorer/), you'll see all the events that an Issue was connected and disconnected to a Pull Request.
Using that query, I pass the response to this code that I wrote for a nodejs app that then determines which Issue is still linked to the Pull Request
const issues = {};
resource.timelineItems.nodes.map(node => {
if (issues.hasOwnProperty(node.subject.number)) {
issues[node.subject.number]++;
} else {
issues[node.subject.number] = 1;
}
});
const linkedIssues = [];
for (const [issue, count] of Object.entries(issues)) {
if (count % 2 != 0) {
linkedIssues.push(issue);
}
}
console.log(issues);
console.log(linkedIssues);
The logic here is as follows:
Get a list of all events on a Pull Request of the type CONNECTED_EVENT and DISCONNECTED_EVENT
Create a map, keyed by Issue number and keep a count of how may times the issue is CONNECTED and DISCONNECTED
From that map, look for keys that have an odd-numbered count, as these are the events that have been CONNECTED that don't have a corresponding DISCONNECTED event.
It's not a super elegant solution, but it solves what I need, which was to find those Linked issues.
Hopefully this helps someone else out