Skip to content

Commit 7417918

Browse files
committed
Add field configuration support for customizable CSV output
- Add -c/--config option to specify field configuration CSV file - Add LoadFieldConfig() function to parse Field_Name,Should_Fetch format - Add IsFieldEnabled() function to check if a field should be included - Add BuildOutputRow() function to dynamically build output based on config - Add GetAllBranchesWithLatestCommit() for repos with >100 branches - Update README with new configuration options and examples - Include sample fields-config.csv file
1 parent 62a2f2a commit 7417918

2 files changed

Lines changed: 376 additions & 16 deletions

File tree

README.md

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ $ gh repo-stats --help
2020
Usage: gh repo-stats [options]
2121

2222
Options:
23+
-c, --config : Path to field configuration CSV file (Field_Name,Should_Fetch format)
24+
If not provided, all fields are fetched
2325
-d, --debug : Enable Debug logging
2426
-e, --extra-page-size : Set the pagination size for subsequent, paginated GraphQL queries; reduce if timeout occurs
2527
Default: 50
@@ -72,14 +74,8 @@ The permissions needed by `gh repo-stats` depends based on `-y, --token-type`:
7274
`gh repo-stats` produces either a visual table or `*.csv` file containing detailed information about various records within repositories.
7375
7476
```csv
75-
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
76-
tinyfists,actions-experiments,false,2023-03-10T16:15:27Z,2022-10-28T19:38:34Z,false,false,0,19,18,0,0,0,0,1,0,0,0,0,0,0,2,0,0,true,https://github.com/tinyfists/actions-experiments,FALSE,2020-01-01T13:37:00Z
77-
tinyfists,git-xargs,false,2022-12-09T03:44:39Z,2022-11-01T03:19:49Z,false,false,0,19,18,0,0,0,0,1,0,0,0,0,0,0,2,0,0,true,https://github.com/tinyfists/git-xargs,FALSE,2020-01-01T13:37:00Z
78-
tinyfists,githubcustomer,false,2022-06-04T17:00:43Z,2022-05-10T03:05:16Z,false,false,0,25,18,0,0,0,4,0,0,0,0,3,0,0,1,0,0,true,https://github.com/tinyfists/githubcustomer,FALSE,2020-01-01T13:37:00Z
79-
tinyfists,issue-driven-github-admin,false,2022-12-09T03:44:36Z,2022-10-14T22:03:38Z,false,false,2,1644,37,1,1,0,140,4,1,0,897,552,10,1,4,10,1,true,https://github.com/tinyfists/issue-driven-github-admin,FALSE,2020-01-01T13:37:00Z
80-
tinyfists,multi-runner-poc,false,2022-12-09T03:43:30Z,2022-08-03T12:44:35Z,false,false,0,19,18,0,0,0,0,1,0,0,0,0,0,0,2,0,0,true,https://github.com/tinyfists/multi-runner-poc,FALSE,2020-01-01T13:37:00Z
81-
tinyfists,pages-demo,false,2022-12-09T03:43:29Z,2022-11-17T23:44:50Z,false,false,0,19,18,0,0,0,0,1,0,0,0,0,0,0,2,0,0,true,https://github.com/tinyfists/pages-demo,FALSE,2020-01-01T13:37:00Z
82-
tinyfists,publish-packages-to-repo-demo,false,2022-12-09T03:43:31Z,2021-10-11T19:39:32Z,false,false,0,24,18,0,0,0,0,3,0,0,0,3,0,0,2,0,0,true,https://github.com/tinyfists/publish-packages-to-repo-demo,FALSE,2020-01-01T13:37:00Z
77+
Org_Name,Repo_Name,Is_Empty,Last_Push,Last_Update,Latest_Commit_SHA,Latest_Committed_At,Latest_Commit_Branch,Default_Branch,isFork,isArchived,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
78+
tinyfists,actions-experiments,false,2023-03-10T16:15:27Z,2022-10-28T19:38:34Z,abc123def456,2023-03-10T16:15:27Z,feature-branch,main,false,false,0,19,18,0,0,0,0,1,0,0,0,0,0,0,2,0,0,true,https://github.com/tinyfists/actions-experiments,FALSE,2020-01-01T13:37:00Z
8379
```
8480
8581
**Columns**
@@ -89,9 +85,13 @@ tinyfists,publish-packages-to-repo-demo,false,2022-12-09T03:43:31Z,2021-10-11T19
8985
- `Is_Empty`: Whether the repository is empty; only available for GitHub.com and GHES >= 3.0
9086
- `Last_Push`: Date/time when a push was last made
9187
- `Last_Update`: Date/time when an update was last made
88+
- `Latest_Commit_SHA`: SHA of the most recent commit across all branches
89+
- `Latest_Committed_At`: Date/time when the most recent commit was made
90+
- `Latest_Commit_Branch`: Branch name where the most recent commit was made
91+
- `Default_Branch`: Default branch of the repository (e.g., main, master), or "No default branch" if none exists
9292
- `isFork`: Whether the repository is a fork
9393
- `isArchive`: Whether the repository is archived
94-
- `Repo_Size(mb)`: Size of the repository in megabytes
94+
- `Repo_Size_mb`: Size of the repository in megabytes
9595
- `Record_Count`: Number of database records this repository represents
9696
- `Collaborator_Count`: Number of users who have contributed to this repository
9797
- `Protected_Branch_Count`: Number of branch protection rules on this repository
@@ -114,3 +114,71 @@ tinyfists,publish-packages-to-repo-demo,false,2022-12-09T03:43:31Z,2021-10-11T19
114114
- 60,000 or more number of objects being imported
115115
- 1.5 GB or larger size on disk
116116
- `Created`: Date/time when the repository was created
117+
118+
## Field Configuration
119+
120+
You can customize which fields are included in the output by using a field configuration CSV file with the `-c` or `--config` option. This is useful when you only need specific fields and want to reduce the output size.
121+
122+
### Configuration File Format
123+
124+
Create a CSV file with the following format:
125+
126+
```csv
127+
Field_Name,Should_Fetch
128+
Org_Name,true
129+
Repo_Name,true
130+
Is_Empty,false
131+
Last_Push,true
132+
...
133+
```
134+
135+
- `Field_Name`: The name of the field (must match exactly)
136+
- `Should_Fetch`: `true` to include the field, `false` to exclude it
137+
138+
### Example Configuration File
139+
140+
A sample configuration file `fields-config.csv` is provided in the repository with all fields enabled. You can copy and modify it to suit your needs:
141+
142+
```shell
143+
# Use custom field configuration
144+
gh repo-stats -o my-org-name -c fields-config.csv
145+
```
146+
147+
### Available Fields
148+
149+
| Field Name | Description |
150+
|------------|-------------|
151+
| `Org_Name` | Organization login |
152+
| `Repo_Name` | Repository name |
153+
| `Is_Empty` | Whether the repository is empty |
154+
| `Last_Push` | Date/time when a push was last made |
155+
| `Last_Update` | Date/time when an update was last made |
156+
| `Latest_Commit_SHA` | SHA of the most recent commit |
157+
| `Latest_Committed_At` | Date/time of the most recent commit |
158+
| `Latest_Commit_Branch` | Branch of the most recent commit |
159+
| `Default_Branch` | Default branch of the repository |
160+
| `isFork` | Whether the repository is a fork |
161+
| `isArchived` | Whether the repository is archived |
162+
| `Repo_Size_mb` | Size of the repository in MB |
163+
| `Record_Count` | Number of database records |
164+
| `Collaborator_Count` | Number of collaborators |
165+
| `Protected_Branch_Count` | Number of branch protection rules |
166+
| `PR_Review_Count` | Number of pull request reviews |
167+
| `Milestone_Count` | Number of milestones |
168+
| `Issue_Count` | Number of issues |
169+
| `PR_Count` | Number of pull requests |
170+
| `PR_Review_Comment_Count` | Number of PR review comments |
171+
| `Commit_Comment_Count` | Number of commit comments |
172+
| `Issue_Comment_Count` | Number of issue comments |
173+
| `Issue_Event_Count` | Number of issue events |
174+
| `Release_Count` | Number of releases |
175+
| `Project_Count` | Number of projects |
176+
| `Branch_Count` | Number of branches |
177+
| `Tag_Count` | Number of tags |
178+
| `Discussion_Count` | Number of discussions |
179+
| `Has_Wiki` | Whether wiki is enabled |
180+
| `Full_URL` | Repository URL |
181+
| `Migration_Issue` | Migration issue indicator |
182+
| `Created` | Repository creation date |
183+
184+
**Note**: If no configuration file is specified or the file doesn't exist, all fields will be fetched by default.

0 commit comments

Comments
 (0)