-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo_info.sh
More file actions
executable file
·142 lines (127 loc) · 4.07 KB
/
repo_info.sh
File metadata and controls
executable file
·142 lines (127 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
# Get detailed info about a GitHub repository
# MIT License — Copyright 2026 Paul van Oorschot
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/_common.sh"
JSON_MODE=false
REPO=""
show_help() {
cat <<'EOF'
Usage: repo_info.sh <owner/repo> [--json]
Get detailed information about a GitHub repository including stats,
topics, languages, recent releases, and contributor count.
Options:
--json Output raw JSON
-h, --help Show this help
Examples:
repo_info.sh cli/cli
repo_info.sh microsoft/vscode --json
repo_info.sh anthropics/anthropic-sdk-python
EOF
exit 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--json) JSON_MODE=true; shift ;;
-h|--help) show_help ;;
-*) echo "Error: unknown option '$1'. See --help" >&2; exit 1 ;;
*)
if [[ -z "$REPO" ]]; then
REPO="$1"
else
echo "Error: unexpected argument '$1'" >&2; exit 1
fi
shift ;;
esac
done
if [[ -z "$REPO" ]] || [[ "$REPO" != */* ]]; then
echo "Error: provide repo as owner/name (e.g. cli/cli). See --help" >&2
exit 1
fi
OWNER="${REPO%%/*}"
NAME="${REPO##*/}"
require_gh
GQL='query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
nameWithOwner
description
url
homepageUrl
isArchived
isFork
isPrivate
createdAt
updatedAt
pushedAt
stargazerCount
forkCount
watchers { totalCount }
issues(states: OPEN) { totalCount }
pullRequests(states: OPEN) { totalCount }
discussions { totalCount }
primaryLanguage { name }
languages(first: 10, orderBy: {field: SIZE, direction: DESC}) {
nodes { name }
}
repositoryTopics(first: 10) { nodes { topic { name } } }
releases(first: 5, orderBy: {field: CREATED_AT, direction: DESC}) {
nodes { tagName name publishedAt }
}
defaultBranchRef { name }
licenseInfo { spdxId name }
mentionableUsers { totalCount }
}
}'
result=$(gh api graphql -f query="$GQL" -f owner="$OWNER" -f name="$NAME" 2>&1) || {
echo "Error: $result" >&2; exit 1
}
repo=$(echo "$result" | jq '.data.repository')
if [[ "$repo" == "null" ]]; then
echo "Error: repository '$REPO' not found" >&2
exit 1
fi
if $JSON_MODE; then
echo "$repo" | jq '{
nameWithOwner, description, url, homepageUrl,
isArchived, isFork, isPrivate,
createdAt, updatedAt, pushedAt,
stars: .stargazerCount, forks: .forkCount,
watchers: .watchers.totalCount,
openIssues: .issues.totalCount,
openPRs: .pullRequests.totalCount,
discussions: .discussions.totalCount,
primaryLanguage: .primaryLanguage.name,
languages: [.languages.nodes[].name],
topics: [.repositoryTopics.nodes[].topic.name],
releases: [.releases.nodes[] | {tag: .tagName, name, date: .publishedAt}],
defaultBranch: .defaultBranchRef.name,
license: .licenseInfo.spdxId,
contributors: .mentionableUsers.totalCount
}'
exit 0
fi
echo "$repo" | jq -r '
.nameWithOwner + (if .isArchived then " [ARCHIVED]" else "" end) +
(if .isPrivate then " [PRIVATE]" else "" end) +
"\n" + (.description // "No description") +
"\n" + .url +
(if .homepageUrl and .homepageUrl != "" then "\nHomepage: " + .homepageUrl else "" end) +
"\n" +
"\n⭐ " + (.stargazerCount | tostring) + " stars | " +
(.forkCount | tostring) + " forks | " +
(.watchers.totalCount | tostring) + " watchers | " +
(.mentionableUsers.totalCount | tostring) + " contributors" +
"\n📋 " + (.issues.totalCount | tostring) + " open issues | " +
(.pullRequests.totalCount | tostring) + " open PRs" +
"\n🔤 " + (.primaryLanguage.name // "N/A") +
" (" + ([.languages.nodes[].name] | join(", ")) + ")" +
"\n📦 Branch: " + (.defaultBranchRef.name // "N/A") +
" | License: " + (.licenseInfo.spdxId // "N/A") +
(if (.repositoryTopics.nodes | length) > 0 then
"\n🏷️ " + ([.repositoryTopics.nodes[].topic.name] | join(", "))
else "" end) +
(if (.releases.nodes | length) > 0 then
"\n\nRecent releases:" +
([.releases.nodes[] | "\n " + .tagName + " (" + (.publishedAt | split("T")[0]) + ")"] | join(""))
else "" end)
'