Skip to content

Commit 0712874

Browse files
committed
feat: add comments retrieval for issues and pull requests in project board script
1 parent 52e5382 commit 0712874

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

gh-cli/get-project-board-items.sh

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# This script works with GitHub Projects V2 (the newer project boards)
55
# Usage: ./get-project-board-items.sh <org> <project-number>
66

7+
# This will get all issues and pull requests linked to the project board,
8+
# it will bring in any comments but only the first 100 comments as currently constructed
9+
710
if [ $# -ne 2 ]; then
811
echo "Usage: $0 <org> <project-number>"
912
echo "Example: ./get-project-board-items.sh my-org 123"
@@ -47,6 +50,16 @@ response=$(gh api graphql --paginate -f org="$org" -F projectNumber="$project_nu
4750
name
4851
}
4952
}
53+
comments(first: 100) {
54+
nodes {
55+
body
56+
author {
57+
login
58+
}
59+
createdAt
60+
updatedAt
61+
}
62+
}
5063
}
5164
... on PullRequest {
5265
title
@@ -59,13 +72,23 @@ response=$(gh api graphql --paginate -f org="$org" -F projectNumber="$project_nu
5972
login
6073
}
6174
}
75+
comments(first: 100) {
76+
nodes {
77+
body
78+
author {
79+
login
80+
}
81+
createdAt
82+
updatedAt
83+
}
84+
}
6285
}
6386
... on DraftIssue {
6487
title
6588
body
6689
}
6790
}
68-
fieldValues(first: 20) {
91+
fieldValues(first: 100) {
6992
nodes {
7093
... on ProjectV2ItemFieldTextValue {
7194
text
@@ -237,7 +260,7 @@ echo "$items" | while IFS= read -r item; do
237260

238261
# Show labels for issues
239262
if [ "$content_type" = "Issue" ]; then
240-
labels=$(echo "$item" | jq -r '.content.labels.nodes[]?.name // empty' | tr '\n' ' ')
263+
labels=$(echo "$item" | jq -r '.content.labels.nodes[]?.name // empty' | tr '\n' ' ' | sed 's/[[:space:]]*$//')
241264
if [ -n "$labels" ]; then
242265
echo ""
243266
echo "🏷️ Labels: $labels"
@@ -272,6 +295,38 @@ echo "$items" | while IFS= read -r item; do
272295
done
273296
fi
274297

298+
# Show comments for issues and pull requests
299+
if [ "$content_type" = "Issue" ] || [ "$content_type" = "PullRequest" ]; then
300+
comments=$(echo "$item" | jq -c '.content.comments.nodes[]? // empty')
301+
if [ -n "$comments" ]; then
302+
comment_count=$(echo "$comments" | wc -l | tr -d ' ')
303+
echo ""
304+
echo "💬 Comments ($comment_count):"
305+
echo "$comments" | while IFS= read -r comment; do
306+
if [ -n "$comment" ]; then
307+
author=$(echo "$comment" | jq -r '.author.login // "Unknown"')
308+
created_at=$(echo "$comment" | jq -r '.createdAt // ""')
309+
comment_body=$(echo "$comment" | jq -r '.body // ""')
310+
311+
# Format the date
312+
if [ -n "$created_at" ] && [ "$created_at" != "null" ]; then
313+
created_date=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$created_at" "+%Y-%m-%d %H:%M" 2>/dev/null || echo "$created_at")
314+
else
315+
created_date="Unknown date"
316+
fi
317+
318+
echo " ┌─ 👤 $author$created_date"
319+
if [ -n "$comment_body" ] && [ "$comment_body" != "null" ]; then
320+
echo "$comment_body" | sed 's/[[:space:]]*$//' | sed 's/^/ │ /'
321+
else
322+
echo " │ (no content)"
323+
fi
324+
echo " └────────────────────────────────────────"
325+
fi
326+
done
327+
fi
328+
fi
329+
275330
echo ""
276331
echo ""
277332
done

0 commit comments

Comments
 (0)