Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
Add support for KGB webhook.
· a5a1a6cd
Bas Couwenberg
authored
Feb 19, 2018
a5a1a6cd
Disable Irker in favor of KGB.
· b3c8e6af
Bas Couwenberg
authored
Feb 19, 2018
b3c8e6af
Show whitespace changes
Inline
Side-by-side
salsa-configure-repositories.pl
View file @
b3c8e6af
...
...
@@ -38,6 +38,9 @@ my %cfg = (
ci_cfg_path
=>
'
debian/.gitlab-ci.yml
',
email_recipients
=>
'
pkg-grass-devel@lists.alioth.debian.org
',
irc_recipients
=>
'
#debian-gis
',
kgb_baseurl
=>
'
http://kgb.debian.net:9418/webhook/
',
kgb_network
=>
'
otfc
',
project
=>
'',
debug
=>
0
,
verbose
=>
0
,
help
=>
0
,
...
...
@@ -52,6 +55,9 @@ my $result = GetOptions(
'
c|ci-cfg-path=s
'
=>
\
$cfg
{
ci_cfg_path
},
'
e|email-recipients=s
'
=>
\
$cfg
{
email_recipients
},
'
i|irc-recipients=s
'
=>
\
$cfg
{
irc_recipients
},
'
k|kgb-baseurl=s
'
=>
\
$cfg
{
kgb_baseurl
},
'
N|kgb-network=s
'
=>
\
$cfg
{
kgb_network
},
'
p|project=s
'
=>
\
$cfg
{
project
},
'
d|debug
'
=>
\
$cfg
{
debug
},
'
v|verbose
'
=>
\
$cfg
{
verbose
},
'
h|help
'
=>
\
$cfg
{
help
},
...
...
@@ -73,6 +79,10 @@ if(!$result || $cfg{help}) {
print
"
-c, --ci-cfg-path <PATH> CI Config Path (
$cfg
{ci_cfg_path})
\n
";
print
"
-e, --email-recipients <EMAIL> Email recipients (
$cfg
{email_recipients})
\n
";
print
"
-i, --irc-recipients <CHANNEL> IRC recipients (
$cfg
{irc_recipients})
\n
";
print
"
-k, --kgb-baseurl <URL> KGB base URL (
$cfg
{kgb_baseurl})
\n
";
print
"
-N, --kgb-network <NAME> KGB network name (
$cfg
{kgb_network})
\n
";
print
"
\n
";
print
"
-p, --project <NAME> Project to configure, instead of all
\n
";
print
"
\n
";
print
"
-d, --debug Enable debug output
\n
";
print
"
-v, --verbose Enable verbose output
\n
";
...
...
@@ -106,6 +116,8 @@ print "team projects:\n".Dumper($team_projects) if($cfg{debug});
# Get service settings
foreach
my
$project
(
@
{
$team_projects
})
{
next
if
(
$cfg
{
project
}
&&
lc
(
$project
->
{
name
})
ne
lc
(
$cfg
{
project
})
&&
lc
(
$project
->
{
path
})
ne
lc
(
$cfg
{
project
}));
print
"
\n
Project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
# Disable issues
...
...
@@ -132,6 +144,11 @@ foreach my $project (@{$team_projects}) {
if
(
!
configure_irker_service
(
$project
))
{
exit
1
;
}
# Configure KGB webhook
if
(
!
configure_kgb_webhook
(
$project
))
{
exit
1
;
}
}
exit
0
;
...
...
@@ -482,14 +499,135 @@ sub configure_irker_service {
print
"
Irker:
\n
"
.
Dumper
(
$data
)
if
(
$cfg
{
debug
});
if
(
!
$data
->
{
active
})
{
print
"
A
ctivating Irker for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
if
(
$data
->
{
active
})
{
print
"
Dea
ctivating Irker for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/services/irker
';
my
$req
=
HTTP::Request::Common::
DELETE
(
$url
);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
print
"
Content:
\n
"
.
Dumper
(
$content
)
if
(
$cfg
{
debug
});
print
"
Deactivated Irker service for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
1
;
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}
else
{
print
"
Irker service already deactivated for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
2
;
}
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}
sub
configure_kgb_webhook
{
my
(
$project
)
=
@_
;
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks
';
my
$req
=
new
HTTP::
Request
(
GET
=>
$url
);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
my
$data
=
decode_json
(
$content
);
print
"
hooks:
\n
"
.
Dumper
(
$data
)
if
(
$cfg
{
debug
});
my
$kgb_url
=
$cfg
{
kgb_baseurl
}
.
'
?channel=
'
.
uri_escape
(
$cfg
{
irc_recipients
})
.
'
&network=
'
.
uri_escape
(
$cfg
{
kgb_network
});
my
$hook_id
=
0
;
my
$same_url
=
0
;
foreach
my
$hook
(
@
{
$data
})
{
if
(
$hook
->
{
url
}
=~
/\Q$cfg{kgb_baseurl}\E/
)
{
$hook_id
=
$hook
->
{
id
};
if
(
$hook
->
{
url
}
eq
$kgb_url
)
{
$same_url
=
1
;
}
last
;
}
}
if
(
!
$hook_id
)
{
print
"
Adding KGB webhook for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks
';
my
%param
=
(
id
=>
$project
->
{
id
},
url
=>
$kgb_url
,
push_events
=>
'
true
',
issues_events
=>
'
true
',
merge_requests_events
=>
'
true
',
tag_push_events
=>
'
true
',
note_events
=>
'
true
',
job_events
=>
'
true
',
pipeline_events
=>
'
true
',
wiki_events
=>
'
true
',
);
print
"
param:
\n
"
.
Dumper
(
\
%param
)
if
(
$cfg
{
debug
});
my
$req
=
HTTP::Request::Common::
POST
(
$url
,
[
%param
]);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
print
"
Content:
\n
"
.
Dumper
(
$content
)
if
(
$cfg
{
debug
});
print
"
Added KGB webhook for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
1
;
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}
elsif
(
$hook_id
&&
!
$same_url
)
{
print
"
Editing KGB webhook for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks/
'
.
uri_escape
(
$hook_id
);
my
%param
=
(
recipients
=>
$cfg
{
irc_recipients
},
colorize_messages
=>
'
true
',
id
=>
$project
->
{
id
},
hook_id
=>
$hook_id
,
url
=>
$kgb_url
,
push_events
=>
'
true
',
issues_events
=>
'
true
',
merge_requests_events
=>
'
true
',
tag_push_events
=>
'
true
',
note_events
=>
'
true
',
job_events
=>
'
true
',
pipeline_events
=>
'
true
',
wiki_events
=>
'
true
',
);
print
"
param:
\n
"
.
Dumper
(
\
%param
)
if
(
$cfg
{
debug
});
...
...
@@ -503,7 +641,7 @@ sub configure_irker_service {
print
"
Content:
\n
"
.
Dumper
(
$content
)
if
(
$cfg
{
debug
});
print
"
Activated Irker service
for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
print
"
Edited KGB webhook
for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
1
;
}
...
...
@@ -516,7 +654,7 @@ sub configure_irker_service {
}
}
else
{
print
"
Irker service
already a
ctive
for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
print
"
KGB webhook
already a
dded
for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
2
;
}
...
...
salsa-create-repository.pl
View file @
b3c8e6af
...
...
@@ -38,9 +38,14 @@ my %cfg = (
ci_cfg_path
=>
'
debian/.gitlab-ci.yml
',
email_recipients
=>
'
pkg-grass-devel@lists.alioth.debian.org
',
irc_recipients
=>
'
#debian-gis
',
kgb_baseurl
=>
'
http://kgb.debian.net:9418/webhook/
',
kgb_network
=>
'
otfc
',
project
=>
'',
description
=>
'',
visibility
=>
'
public
',
enable_emails
=>
1
,
enable_irker
=>
0
,
enable_kgb
=>
1
,
debug
=>
0
,
verbose
=>
0
,
help
=>
0
,
...
...
@@ -55,9 +60,14 @@ my $result = GetOptions(
'
c|ci-cfg-path=s
'
=>
\
$cfg
{
ci_cfg_path
},
'
e|email-recipients=s
'
=>
\
$cfg
{
email_recipients
},
'
i|irc-recipients=s
'
=>
\
$cfg
{
irc_recipients
},
'
k|kgb-baseurl=s
'
=>
\
$cfg
{
kgb_baseurl
},
'
N|kgb-network=s
'
=>
\
$cfg
{
kgb_network
},
'
p|project=s
'
=>
\
$cfg
{
project
},
'
D|description=s
'
=>
\
$cfg
{
description
},
'
V|visibility=s
'
=>
\
$cfg
{
visibility
},
'
enable-emails!
'
=>
\
$cfg
{
enable_emails
},
'
enable-irker!
'
=>
\
$cfg
{
enable_irker
},
'
enable-kgb!
'
=>
\
$cfg
{
enable_kgb
},
'
d|debug
'
=>
\
$cfg
{
debug
},
'
v|verbose
'
=>
\
$cfg
{
verbose
},
'
h|help
'
=>
\
$cfg
{
help
},
...
...
@@ -79,6 +89,8 @@ if(!$result || $cfg{help} || !$cfg{project}) {
print
"
-c, --ci-cfg-path <PATH> CI Config Path (
$cfg
{ci_cfg_path})
\n
";
print
"
-e, --email-recipients <EMAIL> Email recipients (
$cfg
{email_recipients})
\n
";
print
"
-i, --irc-recipients <CHANNEL> IRC recipients (
$cfg
{irc_recipients})
\n
";
print
"
-k, --kgb-baseurl <URL> KGB base URL (
$cfg
{kgb_baseurl})
\n
";
print
"
-N, --kgb-network <NAME> KGB network name (
$cfg
{kgb_network})
\n
";
print
"
\n
";
print
"
-p, --project <NAME> Project name to create
\n
";
print
"
-D, --description <STRING> Project description
\n
";
...
...
@@ -140,12 +152,17 @@ if(!$project) {
}
# Configure Emails on push service
if
(
!
configure_emails_on_push_service
(
$project
))
{
if
(
$cfg
{
enable_emails
}
&&
!
configure_emails_on_push_service
(
$project
))
{
exit
1
;
}
# Configure Irker service
if
(
!
configure_irker_service
(
$project
))
{
if
(
$cfg
{
enable_irker
}
&&
!
configure_irker_service
(
$project
))
{
exit
1
;
}
# Configure kgb webhook
if
(
$cfg
{
enable_kgb
}
&&
!
configure_kgb_webhook
(
$project
))
{
exit
1
;
}
...
...
@@ -458,3 +475,131 @@ sub configure_irker_service {
}
}
sub
configure_kgb_webhook
{
my
(
$project
)
=
@_
;
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks
';
my
$req
=
new
HTTP::
Request
(
GET
=>
$url
);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
my
$data
=
decode_json
(
$content
);
print
"
hooks:
\n
"
.
Dumper
(
$data
)
if
(
$cfg
{
debug
});
my
$kgb_url
=
$cfg
{
kgb_baseurl
}
.
'
?channel=
'
.
uri_escape
(
$cfg
{
irc_recipients
})
.
'
&network=
'
.
uri_escape
(
$cfg
{
kgb_network
});
my
$hook_id
=
0
;
my
$same_url
=
0
;
foreach
my
$hook
(
@
{
$data
})
{
if
(
$hook
->
{
url
}
=~
/\Q$cfg{kgb_baseurl}\E/
)
{
$hook_id
=
$hook
->
{
id
};
if
(
$hook
->
{
url
}
eq
$kgb_url
)
{
$same_url
=
1
;
}
last
;
}
}
if
(
!
$hook_id
)
{
print
"
Adding KGB webhook for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks
';
my
%param
=
(
id
=>
$project
->
{
id
},
url
=>
$kgb_url
,
push_events
=>
'
true
',
issues_events
=>
'
true
',
merge_requests_events
=>
'
true
',
tag_push_events
=>
'
true
',
note_events
=>
'
true
',
job_events
=>
'
true
',
pipeline_events
=>
'
true
',
wiki_events
=>
'
true
',
);
print
"
param:
\n
"
.
Dumper
(
\
%param
)
if
(
$cfg
{
debug
});
my
$req
=
HTTP::Request::Common::
POST
(
$url
,
[
%param
]);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
print
"
Content:
\n
"
.
Dumper
(
$content
)
if
(
$cfg
{
debug
});
print
"
Added KGB webhook for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
1
;
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}
elsif
(
$hook_id
&&
!
$same_url
)
{
print
"
Editing KGB webhook for:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
my
$url
=
$cfg
{
url
}
.
'
/projects/
'
.
uri_escape
(
$project
->
{
id
})
.
'
/hooks/
'
.
uri_escape
(
$hook_id
);
my
%param
=
(
id
=>
$project
->
{
id
},
hook_id
=>
$hook_id
,
url
=>
$kgb_url
,
push_events
=>
'
true
',
issues_events
=>
'
true
',
merge_requests_events
=>
'
true
',
tag_push_events
=>
'
true
',
note_events
=>
'
true
',
job_events
=>
'
true
',
pipeline_events
=>
'
true
',
wiki_events
=>
'
true
',
);
print
"
param:
\n
"
.
Dumper
(
\
%param
)
if
(
$cfg
{
debug
});
my
$req
=
HTTP::Request::Common::
PUT
(
$url
,
[
%param
]);
$req
->
header
('
PRIVATE-TOKEN
'
=>
$cfg
{
token
});
my
$res
=
$ua
->
request
(
$req
);
if
(
$res
->
is_success
)
{
my
$content
=
$res
->
content
;
print
"
Content:
\n
"
.
Dumper
(
$content
)
if
(
$cfg
{
debug
});
print
"
Edited KGB webhook for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
1
;
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}
else
{
print
"
KGB webhook already added for project:
"
.
$project
->
{
name
}
.
"
(
"
.
$project
->
{
id
}
.
"
)
\n
"
if
(
$cfg
{
verbose
});
return
2
;
}
}
else
{
print
"
Error: Request failed! (
$url
)
\n
";
print
"
HTTP Status:
"
.
$res
->
code
.
"
"
.
$res
->
message
.
"
\n
";
print
$res
->
content
if
(
$res
->
content
);
return
;
}
}