Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
6cacceee
Commit
6cacceee
authored
Aug 20, 2013
by
Robert Ricci
Browse files
Put most debugging statements in if ($verbose)
parent
b2bd8a2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
tools/git/gitmaild
View file @
6cacceee
...
...
@@ -51,6 +51,12 @@ my $DEFAULT_ARCHIVEMAIL = 'ricci@cs.utah.edu';
# End settable options
#
#
# Command line options
# TODO: actually accept on command line
#
my
$verbose
=
0
;
sub
run_gitmail
($);
sub
format_options
(@);
sub
call_gitlab_api
($);
...
...
@@ -63,28 +69,39 @@ my $listen_socket = HTTP::Daemon->new(LocalAddr => 'localhost',
LocalPort
=>
$PORT
)
||
die
;
print
"
gitmaild running at:
",
$listen_socket
->
url
,
"
\n
";
while
(
my
$c
=
$listen_socket
->
accept
)
{
# TODO: Fork
while
(
my
$r
=
$c
->
get_request
)
{
print
$r
->
as_string
;
print
"
=
"
x80
.
"
\n
";
# TODO: Error handling
run_gitmail
(
decode_json
(
$r
->
content
));
#
# Main loop - pretty simple!
#
while
(
my
$connection
=
$listen_socket
->
accept
())
{
while
(
my
$request
=
$connection
->
get_request
())
{
if
(
$verbose
)
{
print
$request
->
as_string
();
print
"
=
"
x80
.
"
\n
";
}
# Fork off child
run_gitmail
(
decode_json
(
$request
->
content
()));
}
$c
->
close
;
undef
(
$c
);
# Both are necessary to make sure the connection is really closed
$connection
->
close
();
undef
(
$connection
);
}
sub
run_gitmail
($)
{
my
(
$data
)
=
@_
;
print
"
Running gitmail
\n
";
if
(
$verbose
)
{
print
"
Running gitmail
\n
";
}
# Make it look like it got called as a regular post-recieve hook
my
$refline
=
$data
->
{"
before
"}
.
"
"
.
$data
->
{"
after
"}
.
"
"
.
$data
->
{"
ref
"};
print
$refline
.
"
\n
";
if
(
$verbose
)
{
print
$refline
.
"
\n
";
}
my
$userinfo
=
call_gitlab_api
("
/users/
"
.
$data
->
{"
user_id
"});
...
...
@@ -113,7 +130,10 @@ sub run_gitmail($) {
$options
{'
weburl
'}
=
$repoinfo
->
{
web_url
};
my
$optionstr
=
format_options
(
%options
);
print
"
optionstr is '
$optionstr
'
\n
";
if
(
$verbose
)
{
print
"
optionstr is '
$optionstr
'
\n
";
}
#
# Run gitmail in test mode for now
...
...
@@ -147,7 +167,9 @@ sub call_gitlab_api($) {
my
$request
=
HTTP::
Request
->
new
(
GET
=>
$url
);
my
$ua
=
LWP::
UserAgent
->
new
;
my
$response
=
$ua
->
request
(
$request
);
print
"
Response:
"
.
$response
->
as_string
.
"
\n
";
if
(
$verbose
)
{
print
"
Response:
"
.
$response
->
as_string
.
"
\n
";
}
# Error checking
return
decode_json
(
$response
->
content
);
}
...
...
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