Skip to content

Commit e7d9bc1

Browse files
authored
Merge pull request #6 from anqiansong/feat/repo-chart
feat: Add repository charts
2 parents 3972625 + 366b65a commit e7d9bc1

26 files changed

Lines changed: 1461 additions & 159 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
*.DS_Store
2+
*.DS_Store
3+
*/test

README.md

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# github-compare
44

5-
A Command-line tool to statistics the GitHub repositories
5+
A GitHub repositories statistics command-line tool for the terminal
66

77
## Install
88

@@ -12,84 +12,101 @@ $ go install github.com/anqiansong/github-compare@latest
1212

1313
## Example
1414

15-
### TableView
15+
### TermUI-View
16+
17+
#### Single Repository
18+
19+
```bash
20+
$ github-compare spf13/cobra
21+
```
22+
23+
![repo-detail](./resource/repo-detail.png)
24+
25+
#### More than one Repository
1626

1727
```bash
1828
$ github-compare spf13/cobra urfave/cli junegunn/fzf antonmedv/fx
1929
```
30+
2031
![preview](./resource/compare-preview.png)
2132

22-
### JSONView
33+
### JSON-View
2334

2435
```bash
2536
$ github-compare spf13/cobra --json
2637
[
2738
{
28-
"age": "3187 days",
39+
"age": "3191 days",
2940
"avgReleasePeriod": "199 days",
3041
"contributorCount": "246",
31-
"forkCount": "2327(0/d)",
42+
"forkCount": "2331(0/d)",
3243
"fullName": "spf13/cobra",
3344
"homepage": "https://cobra.dev",
34-
"issue": "107/892",
45+
"issue": "0/893",
3546
"language": "Go",
36-
"lastPushedAt": "8 hour(s) ago",
47+
"lastPushedAt": "15 hour(s) ago",
3748
"latestReleaseAt": "2 month(s) ago",
38-
"lastUpdatedAt": "1 hour(s) ago",
39-
"latestDayStarCount": "14 ⇊",
40-
"latestMonthStarCount": "477",
41-
"latestWeekStarCount": "110 ⇈",
49+
"lastUpdatedAt": "3 minute(s) ago",
50+
"latestDayStarCount": "13 ⇈",
51+
"latestMonthStarCount": "455",
52+
"latestWeekStarCount": "93 ⇊",
4253
"license": "Apache License 2.0",
43-
"pull": "55/808",
54+
"pull": "56/809",
4455
"releaseCount": "16",
45-
"starCount": "26774(8/d)",
46-
"watcherCount": "350"
47-
}
56+
"starCount": "26807(8/d)",
57+
"watcherCount": "349",
58+
"description": "A Commander for modern Go CLI interactions",
59+
...
4860
]
4961
```
62+
For details see [cobra.json](./resource/cobra.json)
5063
51-
### YAMLView
64+
### YAML-View
5265
5366
```bash
5467
$ github-compare spf13/cobra --yaml
55-
- age: 3187 days
68+
- age: 3191 days
5669
avgreleaseperiod: 199 days
5770
contributorcount: "246"
58-
forkcount: 2327(0/d)
71+
forkcount: 2331(0/d)
5972
fullname: spf13/cobra
6073
homepage: https://cobra.dev
61-
issue: 107/892
74+
issue: 0/893
6275
language: Go
63-
lastpushedat: 8 hour(s) ago
76+
lastpushedat: 15 hour(s) ago
6477
latestreleaseat: 2 month(s) ago
65-
lastupdatedat: 1 hour(s) ago
66-
latestdaystarcount: 14 ⇊
67-
latestmonthstarcount: "477"
68-
latestweekstarcount: 110 ⇈
78+
lastupdatedat: 7 minute(s) ago
79+
latestdaystarcount: 13 ⇈
80+
latestmonthstarcount: "455"
81+
latestweekstarcount: 93 ⇊
6982
license: Apache License 2.0
70-
pull: 55/808
83+
pull: 56/809
7184
releasecount: "16"
72-
starcount: 26774(8/d)
73-
watchercount: "350"
85+
starcount: 26807(8/d)
86+
watchercount: "349"
87+
description: A Commander for modern Go CLI interactions
88+
...
7489
```
7590
91+
For details see [cobra.yaml](./resource/cobra.yaml)
92+
7693
### Export as a csv file
7794
7895
```bash
7996
$ github-compare spf13/cobra urfave/cli junegunn/fzf antonmedv/fx -f data.csv
8097
```
81-
![csv](./resource/compare-csv.png)
8298
99+
![csv](./resource/compare-csv.png)
83100
84101
## Usage
85102
86103
### Preparation
87104
88105
1. [Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
89106
2. Set access token token
90-
- Copied the access token and export to environment
91-
- Or you can set the access token by passing `github-compare` argument
92-
`--token`
107+
- Copied the access token and export to environment
108+
- Or you can set the access token by passing `github-compare` argument
109+
`--token`
93110
94111
### Execute
95112
@@ -105,7 +122,7 @@ $ github-compare zeromicro/go-zero
105122
106123
```bash
107124
$ github-compare -h
108-
A cli tool to compare two github repositories
125+
A GitHub repositories statistics command-line tool for the terminal
109126

110127
Usage:
111128
github-compare [flags]
@@ -114,21 +131,32 @@ Flags:
114131
-f, --file string output to a specified file
115132
-h, --help help for github-compare
116133
--json print with json style
117-
--table print with table style(default) (default true)
118134
-t, --token string github access token
135+
--ui print with term ui style(default) (default true)
136+
-v, --version version for github-compare
119137
--yaml print with yaml style
120138
```
121139
122140
## Note
123141
124142
1. A GitHub personal access token is required.
125143
2. `github-compare` accepts 1 to 4 repositories data queries.
126-
3. If you prefer to export the access token to environment, you must use
144+
3. If you prefer to export the access token to environment, you must use
127145
environment key `GITHUB_ACCESS_TOKEN`
128146
147+
## Thanks
148+
- [termui](https://github.com/gizak/termui)
149+
- [termui-dpc](https://github.com/dcorbe/termui-dpc)
150+
- [spinner](https://github.com/briandowns/spinner)
151+
- [go-github](https://github.com/google/go-github)
152+
- [githubv4](https://github.com/shurcooL/githubv4)
153+
- [mapreduce](https://github.com/kevwan/mapreduce)
154+
- [cobra](https://github.com/spf13/cobra)
155+
- [lipgloss](https://github.com/charmbracelet/lipgloss)
156+
129157
## Last
130158
131-
If this repository can help you, give a star please!
159+
If this repository can help you, give a star please!
132160
133161
Thanks all!
134162

cmd/export.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ func export(data []stat.Data, tp string) error {
5151
marshal, _ := yaml.Marshal(data)
5252
buffer.Write(marshal)
5353
case exportTPCSV:
54-
list, err := convert2ViperList(data)
54+
t, err := createTable(data, false, true)
5555
if err != nil {
5656
return err
5757
}
58-
t := createTable(list, false)
58+
// solve garbled characters
59+
buffer.WriteString("\xEF\xBB\xBF")
5960
buffer.WriteString(t.RenderCSV())
6061
default:
6162
return fmt.Errorf("invalid type %q", tp)

cmd/pretty.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@
2222

2323
package cmd
2424

25-
type style string
25+
type style = string
2626

2727
const (
28-
styleJSON style = "json"
29-
styleYAML style = "yaml"
30-
styleTable style = "table"
28+
codeFailure = 1
29+
defaultEmptyString = ""
30+
flagFile = "file"
31+
flagFileShortHand = "f"
32+
flagToken = "token"
33+
flagTokenShortHand = "t"
34+
rootCMDDesc = "A GitHub repositories statistics command-line tool for the terminal"
35+
flagTokenDesc = "github access token"
36+
flagTermUIDesc = "print with term ui style(default)"
37+
flagJSONDesc = "print with json style"
38+
flagYAMLDesc = "print with yaml style"
39+
flagFileDesc = "output to a specified file"
40+
41+
styleJSON style = "json"
42+
styleYAML style = "yaml"
43+
styleTermUI style = "ui"
3144
)

0 commit comments

Comments
 (0)