Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Roman Lacko
gitlab_api
Commits
30dcdd85
Commit
30dcdd85
authored
Nov 02, 2016
by
Roman Lacko
Committed by
Fakultni administrativa
Nov 02, 2016
Browse files
GitLab: better logging messages from API and Iterator
parent
fd732644
Changes
2
Hide whitespace changes
Inline
Side-by-side
GitLab/API.pm
View file @
30dcdd85
...
...
@@ -38,6 +38,7 @@ sub new {
my
(
$class
,
%args
)
=
@_
;
croak
"
URL parameter is required
"
unless
defined
$args
{
URL
};
$log
->
debug
("
initializing GitLab::API for
\"
$args
{URL}
\"
");
my
$self
=
{
api_url
=>
$args
{
URL
},
...
...
@@ -70,13 +71,13 @@ sub new {
keep_alive
=>
$defaults
{
keep_alive
},
);
$log
->
debug
("
setup complete,
testing connection
");
$log
->
debug
("
testing connection
");
my
(
$user
,
$response
)
=
$self
->
whoami
(
-
response
=>
1
);
croak
"
GitLab authentication failed:
",
$response
->
message
unless
$response
->
is_success
;
$log
->
debug
("
logged in as '
$user
->{username}' (
$user
->{name})
");
$log
->
debug
("
setup complete,
logged in as '
$user
->{username}' (
$user
->{name})
");
return
$self
;
}
...
...
GitLab/API/Iterator.pm
View file @
30dcdd85
...
...
@@ -27,9 +27,10 @@ sub new {
};
bless
$self
,
$class
;
$self
->
idebug
("
created for
\"
$url
\"
, per_page=
$self
->{per_page}
");
$self
->
reset
;
$log
->
debug
("
created iterator for
"
.
$self
->
{
tmpl
}
->
{
name
}
.
"
(
$url
), per_page=
$self
->{per_page}
");
return
$self
;
}
...
...
@@ -39,6 +40,8 @@ sub count { return shift->{count}; }
sub
name
{
return
shift
->
{
tmpl
}
->
{
name
};
}
sub
pages
{
return
shift
->
{
pages_read
};
}
sub
idebug
{
$log
->
debug
("
(
"
.
shift
->
name
.
"
)
"
.
join
("",
@
_
));
}
#===============================================================================
# Public methods
#===============================================================================
...
...
@@ -46,8 +49,10 @@ sub pages { return shift->{pages_read}; }
sub
next
{
my
(
$self
)
=
@_
;
return
if
(
$self
->
{
ix
}
+
1
==
$self
->
count
&&
(
$self
->
{
finished
}
||
!
$self
->
next_block
));
if
(
$self
->
{
ix
}
+
1
==
$self
->
count
&&
(
$self
->
{
finished
}
||
!
$self
->
next_block
))
{
$self
->
idebug
("
iterator finished, nothing to do
");
return
;
}
++
$self
->
{
ix
};
return
$self
->
current
;
...
...
@@ -56,7 +61,7 @@ sub next {
sub
reset
{
my
(
$self
)
=
@_
;
$
log
->
debug
("
resetting interator
");
$
self
->
i
debug
("
resetting interator
");
$self
->
{
data
}
=
[]
;
$self
->
{
ix
}
=
-
1
;
$self
->
{
count
}
=
0
;
...
...
@@ -70,7 +75,7 @@ sub reset {
sub
rewind
{
my
(
$self
)
=
@_
;
$
log
->
debug
("
(
"
.
$self
->
name
.
"
)
rewinding
");
$
self
->
i
debug
("
rewinding
");
$self
->
{
ix
}
=
-
1
;
}
...
...
@@ -92,6 +97,7 @@ sub all {
my
(
$self
)
=
@_
;
return
undef
if
!
$self
->
{
good
};
$self
->
idebug
("
retrieving all pages
");
while
(
!
$self
->
{
finished
}
&&
$self
->
next_block
)
{
# nop
}
...
...
@@ -111,10 +117,10 @@ sub next_block {
return
0
;
}
$
log
->
debug
("
(
"
.
$self
->
name
.
"
)
requesting a new block, currently has
$self
->{pages_read} /
"
.
(
$self
->
{
pages_total
}
//
"
unknown
"));
$
self
->
i
debug
("
requesting a new block, currently has
$self
->{pages_read} /
"
.
(
$self
->
{
pages_total
}
//
"
unknown
"));
if
(
defined
$self
->
{
pages_total
}
&&
$self
->
{
pages_total
}
==
$self
->
{
pages_read
})
{
$
log
->
debug
("
(
"
.
$self
->
name
.
"
)
all pages were read, nothing to do
");
$
self
->
i
debug
("
all pages were read, nothing to do
");
$self
->
{
finished
}
=
1
;
return
0
;
}
...
...
@@ -123,7 +129,7 @@ sub next_block {
$xurl
->
query_param
(
page
=>
$self
->
{
pages_read
}
+
1
);
$xurl
->
query_param
(
per_page
=>
$self
->
{
per_page
});
$
log
->
debug
("
(
"
.
$self
->
name
.
"
)
GET
"
.
$xurl
);
$
self
->
i
debug
("
GET
"
.
$xurl
);
my
(
$response
,
$data
)
=
$self
->
api
->
clean_data
(
$self
->
api
->
http
->
get
(
$xurl
));
if
(
$log
->
is_trace
)
{
...
...
@@ -132,7 +138,7 @@ sub next_block {
$log
->
trace
("
--------------------
"
.
("
-
"
x
25
));
}
$
log
->
debug
("
(
"
.
$self
->
name
.
"
)
status:
"
.
$response
->
status_line
);
$
self
->
i
debug
("
status:
"
.
$response
->
status_line
);
if
(
!
$response
->
is_success
)
{
$self
->
{
good
}
=
0
;
...
...
@@ -164,7 +170,8 @@ sub next_block {
++
$self
->
{
pages_read
};
$self
->
{
finished
}
=
$self
->
{
pages_read
}
==
$self
->
{
pages_total
};
$log
->
debug
("
(
"
.
$self
->
name
.
"
) block read successful
");
$self
->
idebug
("
block read successful
");
$self
->
idebug
("
all blocks were read
")
if
$self
->
{
finished
};
return
1
;
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment