コード例 #1
0
ファイル: context.go プロジェクト: yichengq/issue-analyzer
func allIssuesInRepo(client *github.Client, owner, repo string) []github.Issue {
	rate, _, err := client.RateLimits()
	if err != nil {
		fmt.Printf("error fetching rate limit (%v)\n", err)
	} else {
		fmt.Printf("API Rate Limit: %s\n", rate)
	}

	opt := &github.IssueListByRepoOptions{
		State: "all",
		ListOptions: github.ListOptions{
			PerPage: 100,
		},
	}
	var issues []github.Issue
	for i := 0; ; i++ {
		is, resp, err := client.Issues.ListByRepo(owner, repo, opt)
		if err != nil {
			fmt.Printf("error listing issues (%v)\n", err)
			os.Exit(1)
		}
		issues = append(issues, is...)
		if resp.NextPage == 0 {
			break
		}
		opt.ListOptions.Page = resp.NextPage
		fmt.Printf("list %d issues...\n", len(issues))
	}
	return issues
}
コード例 #2
0
func simulateAPIRequest(t *testing.T, c *gh.Client) []*http.Request {
	var requests []*http.Request
	mux := http.NewServeMux()
	mux.HandleFunc("/rate_limit", func(w http.ResponseWriter, req *http.Request) {
		requests = append(requests, req)
		w.Write([]byte("{}"))
	})

	srv := httptest.NewServer(mux)
	defer srv.Close()

	c.BaseURL, _ = url.Parse(srv.URL)
	if _, _, err := c.RateLimits(); err != nil {
		t.Fatalf("failed to retrieve rate limits; %v", err)
	}
	return requests
}