connector/gitlab: Fix regexp in Link parser
This commit is contained in:
committed by
Lars Sjöström
parent
0aabf2d1ea
commit
4605fdd551
@@ -22,6 +22,11 @@ const (
|
||||
scopeAPI = "api"
|
||||
)
|
||||
|
||||
var (
|
||||
reNext = regexp.MustCompile("<([^>]+)>; rel=\"next\"")
|
||||
reLast = regexp.MustCompile("<([^>]+)>; rel=\"last\"")
|
||||
)
|
||||
|
||||
// Config holds configuration options for gilab logins.
|
||||
type Config struct {
|
||||
BaseURL string `json:"baseURL"`
|
||||
@@ -236,9 +241,6 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
|
||||
|
||||
apiURL := c.baseURL + "/api/v4/groups"
|
||||
|
||||
reNext := regexp.MustCompile("<(.*)>; rel=\"next\"")
|
||||
reLast := regexp.MustCompile("<(.*)>; rel=\"last\"")
|
||||
|
||||
groups := []string{}
|
||||
var gitlabGroups []gitlabGroup
|
||||
for {
|
||||
@@ -272,22 +274,28 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
|
||||
|
||||
link := resp.Header.Get("Link")
|
||||
|
||||
if len(reLast.FindStringSubmatch(link)) > 1 {
|
||||
lastPageURL := reLast.FindStringSubmatch(link)[1]
|
||||
|
||||
if apiURL == lastPageURL {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
apiURL = nextURL(apiURL, link)
|
||||
if apiURL == "" {
|
||||
break
|
||||
}
|
||||
|
||||
if len(reNext.FindStringSubmatch(link)) > 1 {
|
||||
apiURL = reNext.FindStringSubmatch(link)[1]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func nextURL(url string, link string) string {
|
||||
if len(reLast.FindStringSubmatch(link)) > 1 {
|
||||
lastPageURL := reLast.FindStringSubmatch(link)[1]
|
||||
|
||||
if url == lastPageURL {
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(reNext.FindStringSubmatch(link)) > 1 {
|
||||
return reNext.FindStringSubmatch(link)[1]
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user