Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
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
tools
gitbot
Commits
748aa1e8
Commit
748aa1e8
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat: add param GITBOT_EXCLUDED_REPOSITORIES to exclude some repos
parent
5c7ffff3
No related branches found
No related tags found
No related merge requests found
Pipeline
#12797
failed
3 years ago
Stage: quality
Stage: package
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+9
-8
9 additions, 8 deletions
README.md
src/main.rs
+7
-2
7 additions, 2 deletions
src/main.rs
src/webhook.rs
+20
-9
20 additions, 9 deletions
src/webhook.rs
with
36 additions
and
19 deletions
README.md
+
9
−
8
View file @
748aa1e8
...
...
@@ -13,10 +13,11 @@ Use docker image `duniter/gitbot:master`.
The configuration is done entirely by environment variables:
| Environment variable | Default value | description |
|------------------------|---------------|--------------------------------------------------------------------------|
|------------------------
--------
|---------------|--------------------------------------------------------------------------|
|
`GITBOT_XMPP_JID`
| Mandatory | Gitbot xmpp account full JID (user@host) |
|
`GITBOT_XMPP_PASSWORD`
| Mandatory | Gitbot xmpp account password |
|
`GITBOT_XMPP_MUC`
| Mandatory | Full jib of target xmpp room (room@host) |
|
`GITBOT_IP`
|
`0.0.0.0`
| IP address on which the gitbot server is listening (to receive webwook) |
|
`GITBOT_PORT`
|
`8080`
| port number on which the gitbot server is listening (to receive webwook) |
|
`GITLAB_TOKEN`
| Mandatory | The secret token that gitlab must use for the webhook |
|
`GITBOT_EXCLUDED_REPOSITORIES`
|
`""`
| List of git repositories that should not be tracked |
This diff is collapsed.
Click to expand it.
src/main.rs
+
7
−
2
View file @
748aa1e8
...
...
@@ -2,6 +2,7 @@ use bytes::Bytes;
use
gitlab
::
webhooks
::{
IssueAction
,
MergeRequestAction
,
WebHook
,
WikiPageAction
};
use
log
::{
info
,
warn
};
use
std
::{
collections
::
HashSet
,
net
::{
IpAddr
,
SocketAddr
},
str
::
FromStr
,
};
...
...
@@ -35,6 +36,9 @@ struct Opt {
/// Gitlab token ("X-Gitlab-Token")
#[structopt(short
=
"H"
,
long
=
"header"
,
env(
"GITLAB_TOKEN"
))]
gitlab_token
:
String
,
/// List of git repositories that should not be tracked
#[structopt(short,
long,
env(
"GITBOT_EXCLUDED_REPOSITORIES"
))]
excluded_repositories
:
Vec
<
String
>
,
}
#[tokio::main]
...
...
@@ -47,6 +51,7 @@ async fn main() -> anyhow::Result<()> {
let
ip
=
opt
.ip
;
let
port
=
opt
.port
;
let
gitlab_token
=
opt
.gitlab_token
;
let
excluded_repositories
=
opt
.excluded_repositories
.into_iter
()
.collect
();
pretty_env_logger
::
init
();
...
...
@@ -64,11 +69,11 @@ async fn main() -> anyhow::Result<()> {
// Functional logic: convert each received webhook to text message and send it to xmpp room
while
let
Some
(
gitlab_web_hook
)
=
receiver
.recv
()
.await
{
if
let
Some
(
message
)
=
webhook
::
format_webhook
(
&
gitlab_web_hook
)
{
if
let
Some
(
message
)
=
webhook
::
format_webhook
(
&
excluded_repositories
,
&
gitlab_web_hook
)
{
info!
(
"message: {}"
,
message
);
xmpp_agent
.send_message
(
&
message
,
&
muc_jid
)
.await
;
}
else
{
warn!
(
"Unhandl
ed webhook
payload
: {:?}"
,
gitlab_web_hook
);
info!
(
"Ignor
ed webhook: {:?}"
,
gitlab_web_hook
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/webhook.rs
+
20
−
9
View file @
748aa1e8
use
crate
::
*
;
pub
(
super
)
fn
format_webhook
(
wh
:
&
WebHook
)
->
Option
<
String
>
{
pub
(
super
)
fn
format_webhook
(
excluded_repositories
:
&
HashSet
<
String
>
,
wh
:
&
WebHook
,
)
->
Option
<
String
>
{
log
::
debug!
(
"receive webhook: {:?}"
,
wh
);
Some
(
match
wh
{
WebHook
::
Build
(
build
)
=>
{
println
!
(
"Build: {:?}"
,
build
);
info
!
(
"Build: {:?}"
,
build
);
return
None
;
}
WebHook
::
Issue
(
issue
)
=>
{
// Error("invalid value: web hook, expected
// Error(\"invalid value: hook date, expected
// ParseError(Invalid)\", line: 0, column: 0)", line: 0,
// column: 0)
if
excluded_repositories
.contains
(
&
issue
.project.path_with_namespace
)
{
return
None
;
}
let
action
=
match
issue
.object_attributes.action
{
Some
(
IssueAction
::
Update
)
=>
"updated"
,
Some
(
IssueAction
::
Open
)
=>
"opened"
,
...
...
@@ -35,6 +37,9 @@ pub(super) fn format_webhook(wh: &WebHook) -> Option<String> {
)
}
WebHook
::
MergeRequest
(
merge_req
)
=>
{
if
excluded_repositories
.contains
(
&
merge_req
.project.path_with_namespace
)
{
return
None
;
}
let
action
=
match
merge_req
.object_attributes.action
{
Some
(
MergeRequestAction
::
Approved
)
=>
"approved"
,
Some
(
MergeRequestAction
::
Update
)
=>
"updated"
,
...
...
@@ -61,14 +66,17 @@ pub(super) fn format_webhook(wh: &WebHook) -> Option<String> {
)
}
WebHook
::
Note
(
note
)
=>
{
println
!
(
"Note: {:?}"
,
note
);
info
!
(
"Note: {:?}"
,
note
);
return
None
;
}
WebHook
::
Pipeline
(
_
pipeline
)
=>
{
// TODO create text for
pipeline
WebHook
::
Pipeline
(
pipeline
)
=>
{
info!
(
"Pipeline: {:?}"
,
pipeline
);
return
None
;
}
WebHook
::
Push
(
push
)
=>
{
if
excluded_repositories
.contains
(
&
push
.project.path_with_namespace
)
{
return
None
;
}
let
branch_name
=
if
push
.ref_
.starts_with
(
"refs/heads/"
)
{
&
push
.ref_
[
11
..
]
}
else
{
...
...
@@ -89,6 +97,9 @@ pub(super) fn format_webhook(wh: &WebHook) -> Option<String> {
text
}
WebHook
::
WikiPage
(
page
)
=>
{
if
excluded_repositories
.contains
(
&
page
.project.path_with_namespace
)
{
return
None
;
}
let
action
=
match
page
.object_attributes.action
{
WikiPageAction
::
Update
=>
"updated"
,
WikiPageAction
::
Create
=>
"created"
,
...
...
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