Skip to content

Commit 4cafdc4

Browse files
authored
Merge pull request #188 from mona-actions/feat/json-output
Add JSON output for repo statistics
2 parents 62a2f2a + 2c3c91e commit 4cafdc4

File tree

3 files changed

+284
-46
lines changed

3 files changed

+284
-46
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Options:
2727
-H, --hostname : The GitHub hostname for the request
2828
Default: github.com
2929
-i, --input : Set path to a file with a list of organizations to scan, one per line, newline delimited
30+
-J, --json : Output results in JSON format instead of CSV
31+
Conforms to the schema defined in json-schema.md
3032
-o, --org : Name of the GitHub Organization to be analyzed
3133
-O, --output : Format of output, can either be "CSV" or "Table"
3234
Default: CSV
@@ -49,6 +51,7 @@ Description:
4951
Example:
5052
gh repo-stats -o my-org-name
5153
gh repo-stats -o my-org-name -H github.example.com
54+
gh repo-stats -o my-org-name --json
5255
```
5356
5457
## Permissions
@@ -69,7 +72,7 @@ The permissions needed by `gh repo-stats` depends based on `-y, --token-type`:
6972
7073
## Output
7174
72-
`gh repo-stats` produces either a visual table or `*.csv` file containing detailed information about various records within repositories.
75+
`gh repo-stats` produces either a visual table or `*.csv` file containing detailed information about various records within repositories. When the `--json` (`-J`) flag is provided, output is written as JSON conforming to the schema defined in [`json-schema.md`](docs/json-schema.md). The output conforms to the [gh-stats-visualizer](https://github.com/mona-actions/gh-stats-visualizer) input format.
7376
7477
```csv
7578
Org_Name,Repo_Name,Is_Empty,Last_Push,Last_Update,isFork,isArchive,Repo_Size(mb),Record_Count,Collaborator_Count,Protected_Branch_Count,PR_Review_Count,Milestone_Count,Issue_Count,PR_Count,PR_Review_Comment_Count,Commit_Comment_Count,Issue_Comment_Count,Issue_Event_Count,Release_Count,Project_Count,Branch_Count,Tag_Count,Discussion_Count,Has_Wiki,Full_URL,Migration_Issue,Created

docs/json-schema.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# gh-repo-stats JSON Schema Specification
2+
3+
This document defines the JSON output format produced by `gh-repo-stats --json`.
4+
5+
---
6+
7+
## Table of Contents
8+
9+
- [Top-Level Structure](#top-level-structure)
10+
- [Repository Object](#repository-object-repos)
11+
- [Core Fields](#core-fields)
12+
- [Example](#example)
13+
14+
---
15+
16+
## Top-Level Structure
17+
18+
```json
19+
{
20+
"repos": []
21+
}
22+
```
23+
24+
| Field | Type | Required | Description |
25+
| ------ | ------- | -------- | ---------------------------------------------------------- |
26+
| `repos`| `array` || Array of [repository objects](#repository-object-repos) |
27+
28+
---
29+
30+
## Repository Object (`repos[]`)
31+
32+
### Core Fields
33+
34+
| Field | Type | Description |
35+
| ------------------- | --------- | ----------------------------------------------------- |
36+
| `org` | `string` | Organization name |
37+
| `name` | `string` | Repository name |
38+
| `url` | `string` | Repository URL |
39+
| `isFork` | `boolean` | Whether the repository is a fork |
40+
| `isArchived` | `boolean` | Whether the repository is archived |
41+
| `diskUsage` | `number` | Repository size in **KB** |
42+
| `sizeMB` | `number` | Repository size in **MB** |
43+
| `hasWikiEnabled` | `boolean` | Whether the wiki is enabled |
44+
| `createdAt` | `string` | ISO 8601 creation timestamp |
45+
| `updatedAt` | `string` | ISO 8601 last update timestamp |
46+
| `pushedAt` | `string` | ISO 8601 last push timestamp |
47+
| `collaborators` | `number` | Number of collaborators |
48+
| `branches` | `number` | Number of branches |
49+
| `tags` | `number` | Number of tags |
50+
| `branchProtections` | `number` | Number of branch protection rules |
51+
| `issues` | `number` | Total issue count |
52+
| `pullRequests` | `number` | Total pull request count |
53+
| `milestones` | `number` | Number of milestones |
54+
| `releases` | `number` | Number of releases |
55+
| `projects` | `number` | Number of projects |
56+
| `discussions` | `number` | Number of discussions |
57+
| `commitComments` | `number` | Number of commit comments |
58+
| `issueEvents` | `number` | Number of issue events |
59+
60+
All fields are always present in the output.
61+
62+
---
63+
64+
## Example
65+
66+
```json
67+
{
68+
"repos": [
69+
{
70+
"org": "my-org",
71+
"name": "my-repo",
72+
"url": "https://github.com/my-org/my-repo",
73+
"isFork": false,
74+
"isArchived": false,
75+
"diskUsage": 51200,
76+
"sizeMB": 50,
77+
"hasWikiEnabled": false,
78+
"createdAt": "2024-01-15T10:30:00Z",
79+
"updatedAt": "2025-06-01T14:00:00Z",
80+
"pushedAt": "2025-06-01T14:00:00Z",
81+
"collaborators": 12,
82+
"branches": 8,
83+
"tags": 15,
84+
"branchProtections": 2,
85+
"issues": 45,
86+
"pullRequests": 120,
87+
"milestones": 4,
88+
"releases": 12,
89+
"projects": 2,
90+
"discussions": 8,
91+
"commitComments": 5,
92+
"issueEvents": 350
93+
}
94+
]
95+
}
96+
```

0 commit comments

Comments
 (0)