Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
vilaca committed Sep 28, 2024
1 parent fda4ea3 commit 5e56b73
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions build/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,37 @@ type RepoInfo struct {
Description string `json:"description"`
}

func getRepoInfo(repo string, token string) (RepoInfo, error) {
func getRepoInfo(repo string, token string) RepoInfo {
url := fmt.Sprintf("https://api.github.com/repos/%s", repo)
fmt.Println(url)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return RepoInfo{}, err
return RepoInfo{}
}

req.Header.Set("Authorization", "Bearer "+token)
resp, err := client.Do(req)
if err != nil {
return RepoInfo{}, err
return RepoInfo{}
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
return RepoInfo{}, fmt.Errorf("failed to fetch repo: %s, status: %s", repo, resp.Status)
return RepoInfo{}
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return RepoInfo{}, err
return RepoInfo{}
}

var repoInfo RepoInfo
err = json.Unmarshal(body, &repoInfo)
if err != nil {
return RepoInfo{}, err
return RepoInfo{}
}

return repoInfo, nil
return repoInfo
}

func main() {
Expand All @@ -69,13 +68,13 @@ func main() {
if repo == "" || owner == "" {
continue
}
info, err := getRepoInfo(fmt.Sprintf("%s/%s", owner, repo), token)
if err != nil {
fmt.Printf("Error fetching repo: %v\n", err)
name := fmt.Sprintf("%s/%s", owner, repo)
info := getRepoInfo(name, token)
if info == nil {
//fmt.Printf("Error fetching repo: %v\n", err)
continue
}

fmt.Printf("%d,%s,%s\n", info.StargazersCount, repo, info.Description)
fmt.Printf("%d,%s,%s\n", info.StargazersCount, name, info.Description)
}

if err := scanner.Err(); err != nil {
Expand Down

0 comments on commit 5e56b73

Please sign in to comment.