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
Zach van Rijn
Emily
Commits
4d3b0bba
Verified
Commit
4d3b0bba
authored
Apr 28, 2022
by
A. Wilcox
🦊
Browse files
IRC: Drastically simplify code
DRY up the send message code.
parent
43a273aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
emily/out/irc.py
View file @
4d3b0bba
...
...
@@ -83,10 +83,22 @@ class IRC:
def
coros
(
self
):
return
[
inst
.
connect
()
for
inst
in
self
.
network_instances
.
values
()]
def
push
(
self
,
project
,
push
):
def
_determine_channels
(
self
,
project
:
str
)
->
set
:
"""Determine the channels that are interested in an event."""
channels
=
set
(
self
.
projects
[
project
]
+
self
.
projects
[
project
.
split
(
'/'
,
1
)[
0
]
+
'/*'
]
+
self
.
projects
[
'*/*'
])
return
channels
def
_send_to_proj_channels
(
self
,
project
:
str
,
msgs
:
list
):
"""Send a list of messages to channels interested in a project's events."""
channels
=
self
.
_determine_channels
(
project
)
for
channel
in
channels
:
network
,
irc_chan
=
channel
.
split
(
':'
,
1
)
for
msg
in
msgs
:
self
.
network_instances
[
network
].
send
(
'PRIVMSG'
,
[
irc_chan
,
msg
])
def
push
(
self
,
project
,
push
):
commit_msgs
=
[]
push_msg
=
'
\x02
{}
\x02
: {} pushed '
.
format
(
project
,
push
[
'user'
][
'name'
])
...
...
@@ -96,6 +108,7 @@ class IRC:
else
:
push_msg
+=
'a commit '
push_msg
+=
'to the
\x02
{}
\x02
branch:'
.
format
(
push
[
'branch'
])
commit_msgs
.
append
(
push_msg
)
for
commit
in
push
[
'commits'
]:
try
:
...
...
@@ -114,30 +127,14 @@ class IRC:
commit_msgs
.
append
(
msg
)
break
for
channel
in
channels
:
network
,
irc_chan
=
channel
.
split
(
':'
,
1
)
self
.
network_instances
[
network
].
send
(
'PRIVMSG'
,
[
irc_chan
,
push_msg
])
for
msg
in
commit_msgs
:
self
.
network_instances
[
network
].
send
(
'PRIVMSG'
,
[
irc_chan
,
msg
])
self
.
_send_to_proj_channels
(
project
,
commit_msgs
)
def
merge
(
self
,
project
,
merge
):
channels
=
set
(
self
.
projects
[
project
]
+
self
.
projects
[
project
.
split
(
'/'
,
1
)[
0
]
+
'/*'
]
+
self
.
projects
[
'*/*'
])
msg
=
'
\x02
{}
\x02
: {} opened a merge request for the
\x02
{}
\x02
branch: {}'
msg
=
msg
.
format
(
project
,
merge
[
'user'
][
'name'
],
merge
[
'branch'
],
merge
[
'url'
])
for
channel
in
channels
:
network
,
irc_chan
=
channel
.
split
(
':'
,
1
)
self
.
network_instances
[
network
].
send
(
'PRIVMSG'
,
[
irc_chan
,
msg
])
self
.
_send_to_proj_channels
(
project
,
[
msg
])
def
pipe
(
self
,
project
,
pipe
):
channels
=
set
(
self
.
projects
[
project
]
+
self
.
projects
[
project
.
split
(
'/'
,
1
)[
0
]
+
'/*'
]
+
self
.
projects
[
'*/*'
])
msg
=
'
\x02
{}
\x02
: Pipeline #{} for branch
\x02
{}
\x02
status: {} - {}'
msg
=
msg
.
format
(
project
,
pipe
[
'id'
],
pipe
[
'branch'
],
pipe
[
'status'
],
pipe
[
'url'
])
for
channel
in
channels
:
network
,
irc_chan
=
channel
.
split
(
':'
,
1
)
self
.
network_instances
[
network
].
send
(
'PRIVMSG'
,
[
irc_chan
,
msg
])
self
.
_send_to_proj_channels
(
project
,
[
msg
])
Write
Preview
Supports
Markdown
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