Skip to content

Commit

Permalink
Update readme and automatically generate global webhook secret
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jun 12, 2021
1 parent ad9ee5a commit ef4e225
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
49 changes: 12 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@

A GitLab client and webhook receiver for maubot.

## Configure plugin
## Usage

### Set up the plugin like any other maubot plugin

Upload [the plugin](https://mau.dev/maubot/gitlab/-/pipelines) in Maubot Manager, and then create an instance i.e. an association of a plugin and a client.
Upload [the plugin](https://mau.dev/maubot/gitlab/-/pipelines) in Maubot Manager,
and then create an instance (an association of a plugin and a client).

Give this new instance an **ID** / name, for example `my_gitlab_bot`. We will refer to this identifier later as `intance_id`.
Give this new instance an **ID** / name, for example `my_gitlab_bot`.
We will refer to this identifier later as `instance_id`.

### Set up Gitlab plugin specificities

Once the instance is created, make sure to at least replace the `secret` with a real password.

For example, you can generate one with:

```sh
tr -dc A-Za-z0-9 < /dev/urandom | head -c 32
```

And save the configuration.

## Login to Gitlab account from the bot
## Logging into your GitLab account

Create a personal access token, as explained in Gitlab's documentation.

Expand All @@ -48,32 +38,17 @@ Assuming the base command to invoke the bot is `gitlab`, adapt the following com
!gitlab server login https://gitlab.example.org PERSONAL_ACCESS_TOKEN
```

You should now be loggued in your Gitlab account.

## Further Gitlab client functionalities

To access further bot's functionalities from Matrix, invoke the bot with `!gitlab` or `!gitlab <command>` to get some help:

```txt
Usage: !gitlab <subcommand> [...]
room <subcommand> [...] - Manage the settings for this room.
server <subcommand> [...] - Manage GitLab Servers.
alias <subcommand> [...] - Manage Gitlab server aliases.
issue <subcommand> [...] - Manage GitLab issues.
commit <subcommand> [...] - View GitLab commits.
ping - Ping the bot.
whoami [server URL or alias] - Check who you're logged in as.
```
You should now be logged in your Gitlab account. Use `!gitlab` to view the list of commands and `!gitlab <command>` to
view help for subcommands (e.g. `!gitlab webhook`).

## Bind repository events to Matrix room (webhooks)
## Setting up webhooks

_Note: You do not need to be logged-in in order to complete this section._
**The instructions below are for adding webhooks manually. You can also simply use `!gitlab webhook add <repo>`, but
that requires logging into the bot using your GitLab token first.**

Go to the desired repository's webhooks settings, in Gitlab, under **Your repo** > **Settings** > **Webhooks**.

Configure the **URL** as follow:
Configure the **URL** as follows:

```sh
https://${server_name}/${plugin_base_path}/${instance_id}/${instance_path}?room=${room_id}
Expand Down
2 changes: 1 addition & 1 deletion base-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
secret: "passwd"
secret: "put a random password here"
base_command: "gitlab"
send_as_notice: true
time_format: "%d.%m.%Y %H:%M:%S %Z"
7 changes: 6 additions & 1 deletion gitlab_matrix/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import secrets

from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper


class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None:
helper.copy("secret")
if not self["secret"] or self["secret"] == "put a random password here":
helper.base["secret"] = secrets.token_urlsafe(32)
else:
helper.copy("secret")
helper.copy("base_command")
helper.copy("send_as_notice")
helper.copy("time_format")
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
maubot: 0.1.2
id: xyz.maubot.gitlab
version: 0.1.0
version: 0.1.1
license: AGPL-3.0-or-later
modules:
- gitlab_matrix
Expand Down

0 comments on commit ef4e225

Please sign in to comment.