Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maubot-rt
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
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
isgphys
maubot-rt
Commits
78321179
Commit
78321179
authored
5 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Add subcommands to show hsitory entries
parent
92f1f08d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rtlinks.py
+68
-10
68 additions, 10 deletions
rtlinks.py
with
68 additions
and
10 deletions
rtlinks.py
+
68
−
10
View file @
78321179
...
...
@@ -19,8 +19,9 @@ class RTLinksPlugin(Plugin):
prefix
:
str
whitelist
:
Set
[
UserID
]
headers
=
{
"
User-agent
"
:
"
rtlinksmaubot
"
}
regex_properties
=
re
.
compile
(
r
'
([a-zA-z]+): (.+)
'
)
regex_number
=
re
.
compile
(
r
'
[0-9]{6}
'
)
regex_properties
=
re
.
compile
(
r
'
([a-zA-z]+): (.+)
'
)
regex_history
=
re
.
compile
(
r
'
([0-9]+): (.+)
'
)
async
def
start
(
self
)
->
None
:
self
.
on_external_config_update
()
...
...
@@ -51,7 +52,7 @@ class RTLinksPlugin(Plugin):
markdown
=
"
[rt#{}]({})
"
.
format
(
number
,
link
)
return
markdown
async
def
show
(
self
,
number
:
str
)
->
dict
:
async
def
_
show
(
self
,
number
:
str
)
->
dict
:
await
self
.
http
.
post
(
self
.
api
,
data
=
self
.
post_data
,
headers
=
self
.
headers
)
api_show
=
'
{}ticket/{}/show
'
.
format
(
self
.
api
,
number
)
async
with
self
.
http
.
get
(
api_show
,
headers
=
self
.
headers
)
as
response
:
...
...
@@ -59,18 +60,34 @@ class RTLinksPlugin(Plugin):
ticket
=
dict
(
self
.
regex_properties
.
findall
(
content
))
return
ticket
async
def
edit
(
self
,
number
:
str
,
status
:
str
)
->
None
:
async
def
_
edit
(
self
,
number
:
str
,
status
:
str
)
->
None
:
api_edit
=
'
{}ticket/{}/edit
'
.
format
(
self
.
api
,
number
)
content
=
{
'
content
'
:
'
Status: {}
'
.
format
(
status
)}
data
=
{
**
self
.
post_data
,
**
content
}
await
self
.
http
.
post
(
api_edit
,
data
=
data
,
headers
=
self
.
headers
)
async
def
comment
(
self
,
number
:
str
,
comment
:
str
)
->
None
:
async
def
_
comment
(
self
,
number
:
str
,
comment
:
str
)
->
None
:
api_comment
=
'
{}ticket/{}/comment
'
.
format
(
self
.
api
,
number
)
content
=
{
'
content
'
:
'
id: {}
\n
Action: comment
\n
Text: {}
'
.
format
(
number
,
comment
)}
data
=
{
**
self
.
post_data
,
**
content
}
await
self
.
http
.
post
(
api_comment
,
data
=
data
,
headers
=
self
.
headers
)
async
def
_history
(
self
,
number
:
str
)
->
dict
:
await
self
.
http
.
post
(
self
.
api
,
data
=
self
.
post_data
,
headers
=
self
.
headers
)
api_history
=
'
{}ticket/{}/history
'
.
format
(
self
.
api
,
number
)
async
with
self
.
http
.
get
(
api_history
,
headers
=
self
.
headers
)
as
response
:
content
=
await
response
.
text
()
ticket
=
dict
(
self
.
regex_history
.
findall
(
content
))
return
ticket
async
def
_entry
(
self
,
number
:
str
,
entry
:
str
)
->
dict
:
await
self
.
http
.
post
(
self
.
api
,
data
=
self
.
post_data
,
headers
=
self
.
headers
)
api_entry
=
'
{}ticket/{}/history/id/{}
'
.
format
(
self
.
api
,
number
,
entry
)
async
with
self
.
http
.
get
(
api_entry
,
headers
=
self
.
headers
)
as
response
:
content
=
await
response
.
text
()
ticket
=
dict
(
self
.
regex_properties
.
findall
(
content
))
return
ticket
@command.passive
(
"
((^| )([rR][tT]#?))([0-9]{6})
"
,
multiple
=
True
)
async
def
handler
(
self
,
evt
:
MessageEvent
,
subs
:
List
[
Tuple
[
str
,
str
]])
->
None
:
await
evt
.
mark_read
()
...
...
@@ -106,7 +123,7 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
properties_dict
=
await
self
.
show
(
number
)
properties_dict
=
await
self
.
_
show
(
number
)
properties_list
=
[
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
properties_dict
.
items
()]
markdown_link
=
await
self
.
get_markdown_link
(
number
)
markdown
=
'
{} properties:
\n
{}
'
.
format
(
markdown_link
,
'
\n
'
.
join
(
properties_list
))
...
...
@@ -118,7 +135,7 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
await
self
.
edit
(
number
,
'
resolved
'
)
await
self
.
_
edit
(
number
,
'
resolved
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} resolved
'
.
format
(
markdown_link
))
...
...
@@ -128,7 +145,7 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
await
self
.
edit
(
number
,
'
open
'
)
await
self
.
_
edit
(
number
,
'
open
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} opened
'
.
format
(
markdown_link
))
...
...
@@ -138,7 +155,7 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
await
self
.
edit
(
number
,
'
stalled
'
)
await
self
.
_
edit
(
number
,
'
stalled
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} stalled
'
.
format
(
markdown_link
))
...
...
@@ -148,7 +165,7 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
await
self
.
edit
(
number
,
'
deleted
'
)
await
self
.
_
edit
(
number
,
'
deleted
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} deleted
'
.
format
(
markdown_link
))
...
...
@@ -166,6 +183,47 @@ class RTLinksPlugin(Plugin):
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
await
self
.
comment
(
number
,
comment
)
await
self
.
_
comment
(
number
,
comment
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} comment added
'
.
format
(
markdown_link
))
@rt.subcommand
(
"
history
"
,
help
=
"
Get a list of all history items for a given ticket.
"
)
@command.argument
(
"
number
"
,
"
ticket number
"
,
pass_raw
=
True
)
async
def
history
(
self
,
evt
:
MessageEvent
,
number
:
str
)
->
None
:
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
history_dict
=
await
self
.
_history
(
number
)
history_list
=
[
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
history_dict
.
items
()]
markdown_link
=
await
self
.
get_markdown_link
(
number
)
markdown
=
'
{} history entries:
\n
{}
'
.
format
(
markdown_link
,
'
\n
'
.
join
(
history_list
))
await
evt
.
respond
(
markdown
)
@rt.subcommand
(
"
entry
"
,
help
=
"
Gets the history information for a single history entry.
"
)
@command.argument
(
"
number
"
,
"
ticket number
"
,
parser
=
str
)
@command.argument
(
"
entry
"
,
"
history entry number
"
,
parser
=
str
)
async
def
entry
(
self
,
evt
:
MessageEvent
,
number
:
str
,
entry
:
str
)
->
None
:
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
entry_dict
=
await
self
.
_entry
(
number
,
entry
)
entry_list
=
[
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
entry_dict
.
items
()]
markdown_link
=
await
self
.
get_markdown_link
(
number
)
markdown
=
'
{} history entry {}:
\n
{}
'
.
format
(
markdown_link
,
entry
,
'
\n
'
.
join
(
entry_list
))
await
evt
.
respond
(
markdown
)
@rt.subcommand
(
"
last
"
,
help
=
"
Gets the history information for the last history entry.
"
)
@command.argument
(
"
number
"
,
"
ticket number
"
,
parser
=
str
)
async
def
last
(
self
,
evt
:
MessageEvent
,
number
:
str
)
->
None
:
if
not
await
self
.
can_manage
(
evt
)
or
not
self
.
is_valid_number
(
number
):
return
await
evt
.
mark_read
()
history_dict
=
await
self
.
_history
(
number
)
entry
=
max
(
history_dict
,
key
=
int
)
entry_dict
=
await
self
.
_entry
(
number
,
entry
)
entry_list
=
[
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
entry_dict
.
items
()]
markdown_link
=
await
self
.
get_markdown_link
(
number
)
markdown
=
'
{} history entry {}:
\n
{}
'
.
format
(
markdown_link
,
entry
,
'
\n
'
.
join
(
entry_list
))
await
evt
.
respond
(
markdown
)
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