Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
4605fdd5
Commit
4605fdd5
authored
7 years ago
by
Lars Sjöström
Committed by
Lars Sjöström
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
connector/gitlab: Fix regexp in Link parser
parent
0aabf2d1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connector/gitlab/gitlab.go
+23
-15
23 additions, 15 deletions
connector/gitlab/gitlab.go
connector/gitlab/gitlab_test.go
+30
-0
30 additions, 0 deletions
connector/gitlab/gitlab_test.go
with
53 additions
and
15 deletions
connector/gitlab/gitlab.go
+
23
−
15
View file @
4605fdd5
...
@@ -22,6 +22,11 @@ const (
...
@@ -22,6 +22,11 @@ const (
scopeAPI
=
"api"
scopeAPI
=
"api"
)
)
var
(
reNext
=
regexp
.
MustCompile
(
"<([^>]+)>; rel=
\"
next
\"
"
)
reLast
=
regexp
.
MustCompile
(
"<([^>]+)>; rel=
\"
last
\"
"
)
)
// Config holds configuration options for gilab logins.
// Config holds configuration options for gilab logins.
type
Config
struct
{
type
Config
struct
{
BaseURL
string
`json:"baseURL"`
BaseURL
string
`json:"baseURL"`
...
@@ -236,9 +241,6 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
...
@@ -236,9 +241,6 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
apiURL
:=
c
.
baseURL
+
"/api/v4/groups"
apiURL
:=
c
.
baseURL
+
"/api/v4/groups"
reNext
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
next
\"
"
)
reLast
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
last
\"
"
)
groups
:=
[]
string
{}
groups
:=
[]
string
{}
var
gitlabGroups
[]
gitlabGroup
var
gitlabGroups
[]
gitlabGroup
for
{
for
{
...
@@ -272,22 +274,28 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
...
@@ -272,22 +274,28 @@ func (c *gitlabConnector) groups(ctx context.Context, client *http.Client) ([]st
link
:=
resp
.
Header
.
Get
(
"Link"
)
link
:=
resp
.
Header
.
Get
(
"Link"
)
if
len
(
reLast
.
FindStringSubmatch
(
link
))
>
1
{
apiURL
=
nextURL
(
apiURL
,
link
)
lastPageURL
:=
reLast
.
FindStringSubmatch
(
link
)[
1
]
if
apiURL
==
""
{
if
apiURL
==
lastPageURL
{
break
}
}
else
{
break
break
}
}
}
return
groups
,
nil
}
if
len
(
reNext
.
FindStringSubmatch
(
link
))
>
1
{
func
nextURL
(
url
string
,
link
string
)
string
{
apiURL
=
reNext
.
FindStringSubmatch
(
link
)[
1
]
if
len
(
reLast
.
FindStringSubmatch
(
link
))
>
1
{
}
else
{
lastPageURL
:=
reLast
.
FindStringSubmatch
(
link
)[
1
]
break
if
url
==
lastPageURL
{
return
""
}
}
}
else
{
return
""
}
if
len
(
reNext
.
FindStringSubmatch
(
link
))
>
1
{
return
reNext
.
FindStringSubmatch
(
link
)[
1
]
}
}
return
groups
,
nil
return
""
}
}
This diff is collapsed.
Click to expand it.
connector/gitlab/gitlab_test.go
0 → 100644
+
30
−
0
View file @
4605fdd5
package
gitlab
import
"testing"
var
nextURLTests
=
[]
struct
{
link
string
expected
string
}{
{
"<https://gitlab.com/api/v4/groups?page=2&per_page=20>; rel=
\"
next
\"
, "
+
"<https://gitlab.com/api/v4/groups?page=1&per_page=20>; rel=
\"
prev
\"
; pet=
\"
cat
\"
, "
+
"<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=
\"
last
\"
"
,
"https://gitlab.com/api/v4/groups?page=2&per_page=20"
},
{
"<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=
\"
next
\"
, "
+
"<https://gitlab.com/api/v4/groups?page=2&per_page=20>; rel=
\"
prev
\"
; pet=
\"
dog
\"
, "
+
"<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=
\"
last
\"
"
,
"https://gitlab.com/api/v4/groups?page=3&per_page=20"
},
{
"<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=
\"
prev
\"
; pet=
\"
bunny
\"
, "
+
"<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=
\"
last
\"
"
,
""
},
}
func
TestNextURL
(
t
*
testing
.
T
)
{
apiURL
:=
"https://gitlab.com/api/v4/groups"
for
_
,
tt
:=
range
nextURLTests
{
apiURL
=
nextURL
(
apiURL
,
tt
.
link
)
if
apiURL
!=
tt
.
expected
{
t
.
Errorf
(
"Should have returned %s, got %s"
,
tt
.
expected
,
apiURL
)
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment