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
a8610ab3
Commit
a8610ab3
authored
Oct 08, 2015
by
A. Wilcox
🦊
Browse files
Emily now works for push events from GitLab :D
parent
d109b936
Changes
4
Hide whitespace changes
Inline
Side-by-side
emily/core.py
View file @
a8610ab3
...
...
@@ -2,6 +2,11 @@
import
asyncio
from
collections
import
defaultdict
import
logging
from
taillight.signal
import
Signal
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
in_plugins
=
[]
...
...
@@ -13,6 +18,22 @@ out_plugins = []
event_loop
=
asyncio
.
get_event_loop
()
push_event
=
Signal
((
'source'
,
'push'
))
"""A push occurred.
Caller is project name (group if available, otherwise 'default').
Push details are:
* User {name, email}
* Commits [{id,msg,url,author:{name,email}}]
* Branch
"""
issue_open_event
=
Signal
((
'issue'
,
'open'
))
issue_comment_event
=
Signal
((
'issue'
,
'comment'
))
issue_close_event
=
Signal
((
'issue'
,
'close'
))
def
register_in
(
plugin
):
inst
=
plugin
()
...
...
emily/inp/gitlab.py
View file @
a8610ab3
import
asyncio
from
emily.core
import
push_event
from
emily.protocols.http
import
http_handle
,
HTTPProtocol
import
json
class
GitLab
:
""" Processes information from GitLab Web Hooks. """
...
...
@@ -8,8 +10,29 @@ class GitLab:
def
__init__
(
self
):
http_handle
.
add
(
self
.
http_handle
)
@
asyncio
.
coroutine
def
http_handle
(
self
,
request
):
if
'X-Gitlab-Event'
not
in
request
.
headers
:
return
False
json
=
yield
from
request
.
json
()
if
'object_kind'
not
in
json
or
json
[
'object_kind'
]
!=
'push'
:
return
False
# why?!
push_info
=
{}
push_info
[
'user'
]
=
{
'name'
:
json
[
'user_name'
],
'email'
:
json
[
'user_email'
]}
push_info
[
'branch'
]
=
json
[
'ref'
].
split
(
'/'
)[
-
1
]
push_info
[
'commits'
]
=
[]
for
commit
in
json
[
'commits'
]:
push_info
[
'commits'
].
append
({
'id'
:
commit
[
'id'
],
'url'
:
commit
[
'url'
],
'msg'
:
commit
[
'message'
],
'author'
:
commit
[
'author'
]})
project
=
request
.
match_info
.
get
(
'grp'
,
'default'
)
+
'/'
+
\
request
.
match_info
.
get
(
'project'
)
yield
from
push_event
.
call_async
(
project
,
push_info
)
return
True
emily/out/irc.py
View file @
a8610ab3
...
...
@@ -5,6 +5,7 @@ from PyIRC.io.asyncio import IRCProtocol
from
PyIRC.signal
import
event
from
emily
import
config
from
emily.core
import
push_event
class
IRCNetwork
(
IRCProtocol
):
"""The basic IRC network representation. Each network has an instance."""
...
...
@@ -33,6 +34,8 @@ class IRC:
network_channel_projects = comma separated list of projects.
"""
def
__init__
(
self
,
loop
):
push_event
.
add
(
self
.
push
)
myconf
=
config
[
'irc'
]
self
.
networks
=
[
network
.
strip
()
for
network
in
myconf
[
'networks'
].
split
(
','
)]
...
...
@@ -62,7 +65,7 @@ class IRC:
args
[
'join'
].
append
(
'#'
+
channel
)
proj_setting
=
network
+
'_'
+
channel
+
'_projects'
for
project
in
[
proj
.
strip
()
for
proj
in
myconf
[
proj_setting
]]:
for
proj
in
myconf
[
proj_setting
]
.
split
(
','
)
]:
self
.
projects
[
project
].
append
(
'{}:{}'
.
format
(
network
,
'#'
+
channel
))
...
...
@@ -73,4 +76,34 @@ class IRC:
return
[
inst
.
connect
()
for
inst
in
self
.
network_instances
.
values
()]
def
push
(
self
,
project
,
push
):
pass
\ No newline at end of file
channels
=
set
(
self
.
projects
[
project
]
+
self
.
projects
[
project
.
split
(
'/'
,
1
)[
0
]
+
'/*'
]
+
self
.
projects
[
'*/*'
])
commit_msgs
=
[]
push_msg
=
'
\x02
{}
\x02
: {} pushed '
.
format
(
project
,
push
[
'user'
][
'name'
])
count
=
len
(
push
[
'commits'
])
if
count
>
1
:
push_msg
+=
'{} commits '
.
format
(
count
)
else
:
push_msg
+=
'a commit '
push_msg
+=
'to the
\x02
{}
\x02
branch:'
.
format
(
push
[
'branch'
])
for
commit
in
push
[
'commits'
]:
msg
=
'{} ({}) by
\x02
{}
\x02
: {}'
.
format
(
commit
[
'id'
][:
7
],
commit
[
'url'
],
commit
[
'author'
][
'name'
],
commit
[
'msg'
])
commit_msgs
.
append
(
msg
)
if
len
(
commit_msgs
)
>
2
:
msg
+=
' [... and {} more]'
.
format
(
count
-
3
)
commit_msgs
[
-
1
]
=
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
])
emily/protocols/http.py
View file @
a8610ab3
...
...
@@ -23,7 +23,7 @@ class HTTPProtocol():
self
.
app
.
router
.
add_route
(
'POST'
,
'/{grp}/{project}'
,
self
.
handler
)
self
.
server
=
loop
.
create_server
(
self
.
app
.
make_handler
(),
'
0.0.0.0
'
,
int
(
config
[
'http'
][
'port'
]))
'
::
'
,
int
(
config
[
'http'
][
'port'
]))
def
coros
(
self
):
return
[
self
.
server
]
...
...
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