I am new to github graphQL API and I have been scrambling for a solution to the following problem, using github Entreprise Cloud:
- I have a repo "myRepo" containing an issue "myIssue"
- issue "myIssue" is added to a projectV2 "myProject", which is defined at organization level (not in a repo)
- project "myProject" contains a field "Status" (default field when creating projects)
Now... I want to automate the re-opening of an issue when it is closed via the merging of a PR, if the value of the "status" of the issue in the project is not "Closed".
Question is: having the node id of issue "myIssue", how can I retrieve the value of the field "Status" for that issue in project "myProject" (assuming I have either the project number or its node id) with a graphQL query?
tried something like
query findProjectItemsForIssueNumber($owner: String!, $repoName: String!, $issueNumber:Int!) {
viewer {
organization(login:$owner) {
repository(name:$repoName) {
issue(number:$issueNumber) {
url
projectItems(first:20) {
nodes {
id
}
}
}
}
}
}
}
derived from https://gist.github.com/richkuz/e8842fce354edbd4e12dcbfa9ca40ff6
but projectItems
is not an Issue
field
so... after learning a bit more about graphQL and going through github's documentation, it does not seem like an event is produced when a custom field's value of an issue is changed. Thus, I had to go the other way around, i.e., use a scheduled workflow that will use a graphQL query to identify all issues pertaining to a project, with the conditions I set. This is what I came up with:
this will return something like
on which I will iterate as long as
hasNextPage
istrue
looking for the cases where thestate
isOPEN
, but thestatus
isClosed
, then close those (using a mutation query like