Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
4605fdd5
Commit
4605fdd5
authored
Sep 28, 2017
by
Lars Sjöström
Committed by
Lars Sjöström
Sep 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
connector/gitlab: Fix regexp in Link parser
parent
0aabf2d1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
11 deletions
+49
-11
gitlab.go
connector/gitlab/gitlab.go
+19
-11
gitlab_test.go
connector/gitlab/gitlab_test.go
+30
-0
No files found.
connector/gitlab/gitlab.go
View file @
4605fdd5
...
...
@@ -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"
)
apiURL
=
nextURL
(
apiURL
,
link
)
if
apiURL
==
""
{
break
}
}
return
groups
,
nil
}
func
nextURL
(
url
string
,
link
string
)
string
{
if
len
(
reLast
.
FindStringSubmatch
(
link
))
>
1
{
lastPageURL
:=
reLast
.
FindStringSubmatch
(
link
)[
1
]
if
apiURL
==
lastPageURL
{
break
if
url
==
lastPageURL
{
return
""
}
}
else
{
break
return
""
}
if
len
(
reNext
.
FindStringSubmatch
(
link
))
>
1
{
apiURL
=
reNext
.
FindStringSubmatch
(
link
)[
1
]
}
else
{
break
return
reNext
.
FindStringSubmatch
(
link
)[
1
]
}
}
return
groups
,
nil
return
""
}
connector/gitlab/gitlab_test.go
0 → 100644
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
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment