How can i close all issues set as done in my projects using the gh cli #6414
-
Hi All. I added the above discussion but i felt maybe i can do this from the cli if there is no way to do it from the ui. I dont mind writing it in go even it is that annoying. I find just figuring the grpahl API is not easy from the documentation or from reading the code. Best Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
(This answer focuses on getting the data of all open issues in a project with a status of Query_1First we have to find out the {
user(login: "LangLangBart") {
projectsV2(first: 100) {
totalCount
nodes {
number
id
title
}
}
}
} Result 1{
"data": {
"user": {
"projectsV2": {
"totalCount": 1,
"nodes": [
{
"number": 2,
"id": "PVT_kwHOBYXG0s4AHGtT",
"title": "TestMe"
}
]
}
}
}
} Query_2For the user query ($user: String!, $projectNumber: Int!, $endCursor: String) {
user(login: $user) {
projectV2(number: $projectNumber) {
number
title
items(first: 100, after: $endCursor) {
totalCount
pageInfo {
hasNextPage
endCursor
}
nodes {
type
... on ProjectV2Item {
fieldValueByName(name: "Status") {
... on ProjectV2ItemFieldSingleSelectValue {
name
id
creator {
login
}
updatedAt
}
}
}
content {
... on Issue {
state
number
repository {
nameWithOwner
}
}
}
}
}
}
}
} Result 2We get 1x issue and 1x draft, the issue is {
"data": {
"user": {
"projectV2": {
"number": 2,
"title": "TestMe",
"items": {
"totalCount": 2,
"nodes": [
{
"type": "ISSUE",
"fieldValueByName": {
"name": "Done",
"id": "PVTFSV_lQHOBYXG0s4AHGtTzgC5qt_OAf4IFQ",
"creator": {
"login": "LangLangBart"
},
"updatedAt": "2022-10-12T18:25:44Z"
},
"content": {
"state": "OPEN",
"number": 2,
"repository": {
"nameWithOwner": "LangLangBart/gh-look"
}
}
},
{
"type": "DRAFT_ISSUE",
"fieldValueByName": {
"name": "In Progress",
"id": "PVTFSV_lQHOBYXG0s4AHGtTzgC6C1zOAf4bgQ",
"creator": {
"login": "LangLangBart"
},
"updatedAt": "2022-10-12T18:39:38Z"
},
"content": {}
}
]
}
}
}
}
}
--jqgh api graphql --paginate --field projectNumber=2 --raw-field user=LangLangBart --raw-field query=$Query_2 --jq '.[].user.projectV2.items.nodes[] | select(.fieldValueByName.name == "Done") | select(.type == "ISSUE") | select(.content.state == "OPEN") | .content'
# result
{"number":2,"repository":{"nameWithOwner":"LangLangBart/gh-look"},"state":"OPEN"} --templategh api graphql --paginate --field projectNumber=2 --raw-field user=LangLangBart --raw-field query=$Query_2 --template '{{- range .data.user.projectV2.items.nodes -}}{{- if .fieldValueByName -}}{{- if (and (eq .type "ISSUE") (eq .fieldValueByName.name "Done") (eq .content.state "OPEN")) }}{{- tablerow (printf "%0.f" .content.number | color "green+h") .content.repository.nameWithOwner (printf "%s added by %s %s" (.fieldValueByName.name | color "22+b:2") (.fieldValueByName.creator.login | color "cyan+h") (timeago .fieldValueByName.updatedAt | color "gray+h")) -}}{{- tablerender -}}{{- end -}}{{- end -}}{{- end -}}'
# result
2 LangLangBart/gh-look Done added by LangLangBart 37 minutes ago closing thoughts
|
Beta Was this translation helpful? Give feedback.
-
A crude but simple one-liner to close a 100 issues: gh issue list --json number --jq '.[].number' -L 100 | while read number; do gh issue close $number; done |
Beta Was this translation helpful? Give feedback.
(This answer focuses on getting the data of all open issues in a project with a status of
Done
for a particular user. How you then process your issues to close them is up to you).Query_1
First we have to find out the
number
of the project, another possibility would be theid
(see node-id GitHub Docs).Result 1