From 4394d1ff0a731b207cf9d8006a8c87f36246b6b2 Mon Sep 17 00:00:00 2001 From: ryo-ma Date: Thu, 6 May 2021 20:33:36 +0900 Subject: [PATCH] Fix to get the repository data from treding api --- README.md | 2 ++ go.mod | 1 + go.sum | 53 +++++++++++++++++++++++++++++++++++++++++++++ lib/githubclient.go | 47 ++++++++++++++++++++++++++-------------- main.go | 5 +++++ 5 files changed, 92 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4e36b05..3b5fdc0 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ Open the README Copy the clone command to clipboard * o Open the repository page on your browser +* CTRL+f +Search repositories # Using API diff --git a/go.mod b/go.mod index 06cbe54..0674cfa 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.14 require ( github.com/atotto/clipboard v0.1.2 + github.com/go-delve/delve v1.6.0 // indirect github.com/jroimartin/gocui v0.4.0 github.com/mattn/go-runewidth v0.0.9 // indirect github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be // indirect diff --git a/go.sum b/go.sum index 175aa7b..0a46869 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,61 @@ github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY= github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/cosiner/argv v0.1.0 h1:BVDiEL32lwHukgJKP87btEPenzrrHUjajs/8yzaqcXg= +github.com/cosiner/argv v0.1.0/go.mod h1:EusR6TucWKX+zFgtdUsKT2Cvg45K5rtpCcWz4hK06d8= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-delve/delve v1.6.0 h1:NImdy7K9essqNU8sazLhbX/oCicpmlapmjgA3qL1LZM= +github.com/go-delve/delve v1.6.0/go.mod h1:Gne5G0YHAbX+7bE5tvdSApTxUs6DtxjE14hVGgvkOD4= +github.com/google/go-dap v0.4.0 h1:bWSjcM9zp/jEFD4YbWERcHSed8vHbEdk0rmTvqgXDAs= +github.com/google/go-dap v0.4.0/go.mod h1:5q8aYQFnHOAZEMP+6vmq25HKYAEwE+LF5yh7JKrrhSQ= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8= github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY= +github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561 h1:isR/L+BIZ+rqODWYR/f526ygrBMGKZYFhaaFRDGvuZ8= +github.com/mattn/go-colorable v0.0.0-20170327083344-ded68f7a9561/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be h1:yzmWtPyxEUIKdZg4RcPq64MfS8NA6A5fNOJgYhpR9EQ= github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= +github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b h1:8uaXtUkxiy+T/zdLWuxa/PG4so0TPZDZfafFNNSaptE= +github.com/peterh/liner v0.0.0-20170317030525-88609521dc4b/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= +github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372 h1:eRfW1vRS4th8IX2iQeyqQ8cOUNOySvAYJ0IUvTXGoYA= +github.com/spf13/cobra v0.0.0-20170417170307-b6cb39589372/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1 h1:7bozMfSdo41n2NOc0GsVTTVUiA+Ncaj6pXNpm4UHKys= +github.com/spf13/pflag v0.0.0-20170417173400-9e4c21054fa1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +go.starlark.net v0.0.0-20200821142938-949cc6f4b097 h1:YiRMXXgG+Pg26t1fjq+iAjaauKWMC9cmGFrtOEuwDDg= +go.starlark.net v0.0.0-20200821142938-949cc6f4b097/go.mod h1:f0znQkUKRrkk36XxWbGjMqQM8wGv/xHBVE2qc3B5oFU= +golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 h1:QlVATYS7JBoZMVaf+cNjb90WD/beKVHnIxFKT4QaHVI= +golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= +golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/lib/githubclient.go b/lib/githubclient.go index 3309a79..abfd55a 100644 --- a/lib/githubclient.go +++ b/lib/githubclient.go @@ -22,17 +22,19 @@ type Client struct { type Item struct { ID int `json:"id"` - Name string `json:"name"` + Name string `json:"name,repo"` FullName string `json:"full_name"` - URL string `json:"url"` + URL string `json:"repo_link"` HTMLURL string `json:"html_url"` CloneURL string `json:"clone_url"` Description string `json:"description"` + Desc string `json:"desc"` StargazersCount int `json:"stargazers_count,stars"` - Stars int `json:"stars"` + Stars string `json:"stars"` Watchers int `json:"watchers"` Topics []string `json:"topics"` Language string `json:"language"` + Lang string `json:"lang"` DefaultBranch string `json:"default_branch"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` @@ -64,10 +66,11 @@ func (item *Item) GetRepositoryName() string { } func (item *Item) GetStars() int { - if item.Stars == 0 { + stars, _ := strconv.Atoi(strings.Replace(item.Stars, ",", "", -1)) + if stars == 0 { return item.StargazersCount } - return item.Stars + return stars } func (item *Item) GetRepositoryURL() string { @@ -77,6 +80,20 @@ func (item *Item) GetRepositoryURL() string { } return url } +func (item *Item) GetDescription() string { + description := item.Description + if description == "" { + return item.Desc + } + return description +} +func (item *Item) GetLanguage() string { + language := item.Language + if language == "" { + return item.Lang + } + return language +} func (item *Item) GetCloneURL() string { url := item.GetRepositoryURL() if !strings.HasSuffix(url, ".git") { @@ -103,8 +120,8 @@ func (item *Item) String() string { URL : {{.GetRepositoryURL}} Star : ⭐️ {{.Stars}} Clone URL : {{.GetCloneURL}} - Description: {{.Description}} - Language : {{.Language}} + Description: {{.GetDescription}} + Language : {{.GetLanguage}} ` templateText := trendingTemplateText if item.DataSource == "OfficialAPI" { @@ -134,7 +151,7 @@ func NewClient() (*Client, error) { if err != nil { return nil, err } - trendingRepositoryURL, err := url.Parse("https://github-trending-api.now.sh/repositories") + trendingRepositoryURL, err := url.Parse("https://trendings.herokuapp.com/repo") if err != nil { return nil, err } @@ -199,7 +216,7 @@ func (client *Client) GetReadme(item Item) (*Readme, error) { func (client *Client) GetTrendingRepository(language string, since string) (*Result, error) { q := client.TrendingRepositoryURL.Query() if language != "" { - q.Set("language", language) + q.Set("lang", language) } if since != "" { q.Set("since", since) @@ -222,14 +239,12 @@ func (client *Client) GetTrendingRepository(language string, since string) (*Res if err != nil { return nil, err } - var items []Item - if err = json.Unmarshal(body, &items); err != nil { + var result *Result + if err = json.Unmarshal(body, &result); err != nil { return nil, err } - for i := range items { - items[i].DataSource = "TrendingAPI" + for i := range result.Items { + result.Items[i].DataSource = "TrendingAPI" } - return &Result{ - Items: items, - }, nil + return result, nil } diff --git a/main.go b/main.go index d6949e5..0570229 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,11 @@ var searchPanel *ui.SearchPanel var loadingPanel *ui.LoadingPanel var cursor *ui.Cursor +func _main() { + client, _ = lib.NewClient() + _, _ = client.GetTrendingRepository("", "") +} + func main() { g, err := gocui.NewGui(gocui.OutputNormal) if err != nil {