Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
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
maubot
gitlab
Commits
915cdb04
Commit
915cdb04
authored
7 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Split opening and reading issues to own function
* Add shorthand for issue creating (!gitlab create ...)
parent
5ffbf10c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
commands.go
+52
-43
52 additions, 43 deletions
commands.go
with
52 additions
and
43 deletions
commands.go
+
52
−
43
View file @
915cdb04
...
@@ -50,8 +50,9 @@ var Commands = map[string]GitlabCommand{
...
@@ -50,8 +50,9 @@ var Commands = map[string]GitlabCommand{
"diff"
:
commandDiff
,
"diff"
:
commandDiff
,
"log"
:
commandLog
,
"log"
:
commandLog
,
"whoami"
:
commandWhoami
,
"whoami"
:
commandWhoami
,
"issue"
:
commandIssue
,
"help"
:
commandHelp
,
"help"
:
commandHelp
,
"issue"
:
commandIssue
,
"create"
:
commandCreateIssue
,
}
}
func
commandPing
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
func
commandPing
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
...
@@ -83,7 +84,7 @@ func commandHelp(git *gitlab.Client, room *mautrix.Room, sender string, args []s
...
@@ -83,7 +84,7 @@ func commandHelp(git *gitlab.Client, room *mautrix.Room, sender string, args []s
if
len
(
args
)
>
0
{
if
len
(
args
)
>
0
{
if
args
[
0
]
==
"issue"
{
if
args
[
0
]
==
"issue"
{
room
.
SendHTML
(
`<pre><code>Commands are prefixed with !gitlab issue
room
.
SendHTML
(
`<pre><code>Commands are prefixed with !gitlab issue
-
open
<repo> <title>
- Open
an issue. The issue body can be placed on a new line.
-
create
<repo> <title>
- Create
an issue. The issue body can be placed on a new line.
- close <repo> <id> - Close an issue.
- close <repo> <id> - Close an issue.
- comment <repo> <id> <message> - Comment on an issue.
- comment <repo> <id> <message> - Comment on an issue.
- read <repo> <id> - Read an issue.
- read <repo> <id> - Read an issue.
...
@@ -219,6 +220,51 @@ func commandLog(git *gitlab.Client, room *mautrix.Room, sender string, args []st
...
@@ -219,6 +220,51 @@ func commandLog(git *gitlab.Client, room *mautrix.Room, sender string, args []st
room
.
SendHTML
(
buf
.
String
())
room
.
SendHTML
(
buf
.
String
())
}
}
func
commandReadIssue
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
if
len
(
args
)
<
2
{
room
.
Send
(
"Usage: !gitlab issue read <repo> <issue id>"
)
return
}
id
,
err
:=
strconv
.
Atoi
(
args
[
1
])
if
err
!=
nil
{
room
.
Send
(
"Usage: !gitlab issue read <repo> <issue id>"
)
return
}
issue
,
_
,
err
:=
git
.
Issues
.
GetIssue
(
args
[
0
],
id
)
if
err
!=
nil
{
room
.
Sendf
(
"An error occurred: %s"
,
err
)
return
}
var
buf
bytes
.
Buffer
fmt
.
Fprintf
(
&
buf
,
"Issue #%[2]d by %[3]s: <a href='%[1]s'>%[4]s</a>."
,
issue
.
WebURL
,
issue
.
IID
,
issue
.
Author
.
Name
,
issue
.
Title
)
if
len
(
issue
.
Assignee
.
Name
)
>
0
{
fmt
.
Fprintf
(
&
buf
,
" Assigned to %s."
,
issue
.
Assignee
.
Name
)
}
fmt
.
Fprintf
(
&
buf
,
"<br/>
\n
<blockquote>%s</blockquote><br/>
\n
"
,
strings
.
Replace
(
issue
.
Description
,
"
\n
"
,
"<br/>
\n
"
,
-
1
))
room
.
SendHTML
(
buf
.
String
())
}
func
commandCreateIssue
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
if
len
(
args
)
<
2
{
room
.
Send
(
"Usage: !gitlab issue create <repo> <title>
\\
n <body>"
)
return
}
title
:=
strings
.
Join
(
args
[
1
:
],
" "
)
description
:=
strings
.
Join
(
lines
,
"
\n
"
)
_
,
_
,
err
:=
git
.
Issues
.
CreateIssue
(
args
[
0
],
&
gitlab
.
CreateIssueOptions
{
Title
:
&
title
,
Description
:
&
description
,
})
if
err
!=
nil
{
room
.
Sendf
(
"Failed to create issue: %s"
,
err
)
}
}
func
commandIssue
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
func
commandIssue
(
git
*
gitlab
.
Client
,
room
*
mautrix
.
Room
,
sender
string
,
args
[]
string
,
lines
[]
string
)
{
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
{
room
.
SendHTML
(
"Unknown subcommand. Try <code>!gitlab help issue</code> for help."
)
room
.
SendHTML
(
"Unknown subcommand. Try <code>!gitlab help issue</code> for help."
)
...
@@ -238,48 +284,11 @@ func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []
...
@@ -238,48 +284,11 @@ func commandIssue(git *gitlab.Client, room *mautrix.Room, sender string, args []
case
"view"
:
case
"view"
:
fallthrough
fallthrough
case
"read"
:
case
"read"
:
if
len
(
args
)
<
2
{
commandReadIssue
(
git
,
room
,
sender
,
args
,
lines
)
room
.
Send
(
"Usage: !gitlab issue read <repo> <issue id>"
)
return
}
id
,
err
:=
strconv
.
Atoi
(
args
[
1
])
if
err
!=
nil
{
room
.
Send
(
"Usage: !gitlab issue read <repo> <issue id>"
)
return
}
issue
,
_
,
err
:=
git
.
Issues
.
GetIssue
(
args
[
0
],
id
)
if
err
!=
nil
{
room
.
Sendf
(
"An error occurred: %s"
,
err
)
return
}
var
buf
bytes
.
Buffer
fmt
.
Fprintf
(
&
buf
,
"Issue #%[2]d by %[3]s: <a href='%[1]s'>%[4]s</a>."
,
issue
.
WebURL
,
issue
.
IID
,
issue
.
Author
.
Name
,
issue
.
Title
)
if
len
(
issue
.
Assignee
.
Name
)
>
0
{
fmt
.
Fprintf
(
&
buf
,
" Assigned to %s."
,
issue
.
Assignee
.
Name
)
}
fmt
.
Fprintf
(
&
buf
,
"<br/>
\n
<blockquote>%s</blockquote><br/>
\n
"
,
strings
.
Replace
(
issue
.
Description
,
"
\n
"
,
"<br/>
\n
"
,
-
1
))
room
.
SendHTML
(
buf
.
String
())
case
"create"
:
fallthrough
case
"open"
:
case
"open"
:
if
len
(
args
)
<
2
{
fallthrough
room
.
Send
(
"Usage: !gitlab issue open <repo> <title>
\\
n <body>"
)
case
"create"
:
return
commandCreateIssue
(
git
,
room
,
sender
,
args
,
lines
)
}
title
:=
strings
.
Join
(
args
[
1
:
],
" "
)
description
:=
strings
.
Join
(
lines
,
"
\n
"
)
_
,
_
,
err
:=
git
.
Issues
.
CreateIssue
(
args
[
0
],
&
gitlab
.
CreateIssueOptions
{
Title
:
&
title
,
Description
:
&
description
,
})
if
err
!=
nil
{
room
.
Sendf
(
"Failed to create issue: %s"
,
err
)
}
case
"close"
:
case
"close"
:
fallthrough
fallthrough
case
"reopen"
:
case
"reopen"
:
...
...
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