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
92f1f08d
Commit
92f1f08d
authored
5 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Refactor code
parent
7c7df691
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
+14
-15
14 additions, 15 deletions
rtlinks.py
with
14 additions
and
15 deletions
rtlinks.py
+
14
−
15
View file @
92f1f08d
...
...
@@ -46,7 +46,12 @@ class RTLinksPlugin(Plugin):
return
True
return
False
async
def
show_ticket
(
self
,
number
:
str
)
->
dict
:
async
def
get_markdown_link
(
self
,
number
:
str
)
->
str
:
link
=
"
{}/Ticket/Display.html?id={}
"
.
format
(
self
.
config
[
'
url
'
],
number
)
markdown
=
"
[rt#{}]({})
"
.
format
(
number
,
link
)
return
markdown
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
:
...
...
@@ -54,18 +59,13 @@ class RTLinksPlugin(Plugin):
ticket
=
dict
(
self
.
regex_properties
.
findall
(
content
))
return
ticket
async
def
get_markdown_link
(
self
,
number
:
str
)
->
str
:
link
=
"
{}/Ticket/Display.html?id={}
"
.
format
(
self
.
config
[
'
url
'
],
number
)
markdown
=
"
[rt#{}]({})
"
.
format
(
number
,
link
)
return
markdown
async
def
edit_ticket
(
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
_ticket
(
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
}
...
...
@@ -106,8 +106,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
.
show_ticket
(
number
)
properties_dict
=
await
self
.
show_ticket
(
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
))
...
...
@@ -119,7 +118,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
_ticket
(
number
,
'
resolved
'
)
await
self
.
edit
(
number
,
'
resolved
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} resolved
'
.
format
(
markdown_link
))
...
...
@@ -129,7 +128,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
_ticket
(
number
,
'
open
'
)
await
self
.
edit
(
number
,
'
open
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} opened
'
.
format
(
markdown_link
))
...
...
@@ -139,7 +138,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
_ticket
(
number
,
'
stalled
'
)
await
self
.
edit
(
number
,
'
stalled
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} stalled
'
.
format
(
markdown_link
))
...
...
@@ -149,7 +148,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
_ticket
(
number
,
'
deleted
'
)
await
self
.
edit
(
number
,
'
deleted
'
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} deleted
'
.
format
(
markdown_link
))
...
...
@@ -167,6 +166,6 @@ 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
_ticket
(
number
,
comment
)
await
self
.
comment
(
number
,
comment
)
markdown_link
=
await
self
.
get_markdown_link
(
number
)
await
evt
.
respond
(
'
{} comment added
'
.
format
(
markdown_link
))
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