Skip to content

Commit c93cf88

Browse files
committed
use k in star & fork
1 parent 6bd9e2f commit c93cf88

5 files changed

Lines changed: 52 additions & 3 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module github.com/po3rin/github_link_creator
33
go 1.12
44

55
require (
6+
github.com/aws/aws-sdk-go v1.25.11
67
github.com/certifi/gocertifi v0.0.0-20190506164543-d2eda7129713 // indirect
78
github.com/evalphobia/logrus_sentry v0.8.2
89
github.com/getsentry/raven-go v0.2.0
910
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
1011
github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15
1112
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
12-
github.com/pkg/errors v0.8.1 // indirect
13+
github.com/pkg/errors v0.8.1
1314
github.com/po3rin/img2circle v0.1.3
1415
github.com/po3rin/txt2img v0.0.0-20190712152905-47c0a1bd247a
1516
github.com/sirupsen/logrus v1.4.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/aws/aws-sdk-go v1.20.19 h1:RQDLGGlcffQzAceEXGdMu+uGGPGhNu+vNG3BrUZAMPI=
22
github.com/aws/aws-sdk-go v1.20.19/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
3+
github.com/aws/aws-sdk-go v1.25.11 h1:wUivbsVOH3LpHdC3Rl5i+FLHfg4sOmYgv4bvHe7+/Pg=
4+
github.com/aws/aws-sdk-go v1.25.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
35
github.com/certifi/gocertifi v0.0.0-20190506164543-d2eda7129713 h1:UNOqI3EKhvbqV8f1Vm3NIwkrhq388sGCeAH2Op7w0rc=
46
github.com/certifi/gocertifi v0.0.0-20190506164543-d2eda7129713/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
57
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pipeline/export_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package pipeline
2+
3+
var ExportNum2StringWithSINortion = num2StringWithSINortion

pipeline/pipeline.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,24 @@ func ProcessingImg(ctx context.Context, r Repoitory, userName string, repoName s
7979
}
8080
}
8181
}
82-
img, err = processing.DrawText(img, config.Star, strconv.Itoa(repo.Stars))
82+
img, err = processing.DrawText(img, config.Star, num2StringWithSINortion(repo.Stars))
8383
if err != nil {
8484
l.Error(err)
8585
return nil, err
8686
}
87-
img, err = processing.DrawText(img, config.Fork, strconv.Itoa(repo.Forks))
87+
img, err = processing.DrawText(img, config.Fork, num2StringWithSINortion(repo.Forks))
8888
if err != nil {
8989
l.Error(err)
9090
return nil, err
9191
}
9292

9393
return img, nil
9494
}
95+
96+
func num2StringWithSINortion(i int) string {
97+
if i > 999 {
98+
i = i / 1000
99+
return strconv.Itoa(i) + "k"
100+
}
101+
return strconv.Itoa(i)
102+
}

pipeline/pipeline_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,38 @@ func TestProcessingImg(t *testing.T) {
5050
t.Fatalf("unexpected error, %v", err.Error())
5151
}
5252
}
53+
54+
func TestNum2StringWithSINortion(t *testing.T) {
55+
tests := []struct {
56+
name string
57+
num int
58+
want string
59+
}{
60+
{
61+
name: "1000000",
62+
num: 1000000,
63+
want: "1000k",
64+
},
65+
{
66+
name: "100",
67+
num: 100,
68+
want: "100",
69+
},
70+
{
71+
name: "123456",
72+
num: 123456,
73+
want: "123k",
74+
},
75+
}
76+
77+
for _, tt := range tests {
78+
tt := tt
79+
t.Run(tt.name, func(t *testing.T) {
80+
t.Parallel()
81+
got := pipeline.ExportNum2StringWithSINortion(tt.num)
82+
if got != tt.want {
83+
t.Errorf("unexpected value. want: %v, got: %v\n", tt.want, got)
84+
}
85+
})
86+
}
87+
}

0 commit comments

Comments
 (0)