@@ -7,6 +7,7 @@ import (
77 "net/http"
88 "net/url"
99 "path"
10+ "regexp"
1011 "strconv"
1112 "strings"
1213
@@ -148,6 +149,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
148149 }
149150
150151 pn := 1
152+ last := 0
151153 for {
152154 params := url.Values{
153155 "per_page": {"100"},
@@ -170,6 +172,30 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
170172 }
171173
172174 body, err := ioutil.ReadAll(resp.Body)
175+
176+ if last == 0 {
177+ // link header may not be obtained
178+ // When paging is not required and all data can be retrieved with a single call
179+
180+ // Conditions for obtaining the link header.
181+ // 1. When paging is required (Example: When the data size is 100 and the page size is 99 or less)
182+ // 2. When it exceeds the paging frame (Example: When there is only 10 records but the second page is called with a page size of 100)
183+
184+ // link header at not last page
185+ // <https://api.github.com/user/teams?page=1&per_page=100>; rel="prev", <https://api.github.com/user/teams?page=1&per_page=100>; rel="last", <https://api.github.com/user/teams?page=1&per_page=100>; rel="first"
186+ // link header at last page (doesn't exist last info)
187+ // <https://api.github.com/user/teams?page=3&per_page=10>; rel="prev", <https://api.github.com/user/teams?page=1&per_page=10>; rel="first"
188+
189+ link := resp.Header.Get("Link")
190+ rep1 := regexp.MustCompile(`(?s).*\<https://api.github.com/user/teams\?page=(.)&per_page=[0-9]+\>; rel="last".*`)
191+ i, converr := strconv.Atoi(rep1.ReplaceAllString(link, "$1"))
192+
193+ // If the last page cannot be taken from the link in the http header, the last variable remains zero
194+ if converr == nil {
195+ last = i
196+ }
197+ }
198+
173199 resp.Body.Close()
174200 if err != nil {
175201 return false, err
@@ -188,6 +214,14 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
188214 }
189215
190216 teams = append(teams, tp...)
217+
218+ if pn == last {
219+ break
220+ }
221+ if last == 0 {
222+ break
223+ }
224+
191225 pn++
192226 }
193227