Commit ce122cb5 authored by GitLab Bot's avatar GitLab Bot

Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-11-12

# Conflicts:
#	Gemfile.lock
#	Gemfile.rails5.lock

[ci skip]
parents 1fc0f096 e4b00acd
...@@ -214,6 +214,9 @@ gem 'redis-rails', '~> 5.0.2' ...@@ -214,6 +214,9 @@ gem 'redis-rails', '~> 5.0.2'
gem 'redis', '~> 3.2' gem 'redis', '~> 3.2'
gem 'connection_pool', '~> 2.0' gem 'connection_pool', '~> 2.0'
# Discord integration
gem 'discordrb-webhooks-blackst0ne', '~> 3.3', require: false
# HipChat integration # HipChat integration
gem 'hipchat', '~> 1.5.0' gem 'hipchat', '~> 1.5.0'
......
...@@ -170,6 +170,8 @@ GEM ...@@ -170,6 +170,8 @@ GEM
rotp (~> 2.0) rotp (~> 2.0)
diff-lcs (1.3) diff-lcs (1.3)
diffy (3.1.0) diffy (3.1.0)
discordrb-webhooks-blackst0ne (3.3.0)
rest-client (~> 2.0)
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20180417) domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
...@@ -296,7 +298,10 @@ GEM ...@@ -296,7 +298,10 @@ GEM
gitaly-proto (0.123.0) gitaly-proto (0.123.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
<<<<<<< HEAD
gitlab-license (1.0.0) gitlab-license (1.0.0)
=======
>>>>>>> upstream/master
gitlab-markup (1.6.5) gitlab-markup (1.6.5)
gitlab-sidekiq-fetcher (0.3.0) gitlab-sidekiq-fetcher (0.3.0)
sidekiq (~> 5) sidekiq (~> 5)
...@@ -995,6 +1000,7 @@ DEPENDENCIES ...@@ -995,6 +1000,7 @@ DEPENDENCIES
devise (~> 4.4) devise (~> 4.4)
devise-two-factor (~> 3.0.0) devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0) diffy (~> 3.1.0)
discordrb-webhooks-blackst0ne (~> 3.3)
doorkeeper (~> 4.3) doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5) doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2) ed25519 (~> 1.2)
...@@ -1029,7 +1035,10 @@ DEPENDENCIES ...@@ -1029,7 +1035,10 @@ DEPENDENCIES
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.123.0) gitaly-proto (~> 0.123.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
<<<<<<< HEAD
gitlab-license (~> 1.0) gitlab-license (~> 1.0)
=======
>>>>>>> upstream/master
gitlab-markup (~> 1.6.5) gitlab-markup (~> 1.6.5)
gitlab-sidekiq-fetcher gitlab-sidekiq-fetcher
gitlab-styles (~> 2.4) gitlab-styles (~> 2.4)
......
...@@ -173,6 +173,8 @@ GEM ...@@ -173,6 +173,8 @@ GEM
rotp (~> 2.0) rotp (~> 2.0)
diff-lcs (1.3) diff-lcs (1.3)
diffy (3.1.0) diffy (3.1.0)
discordrb-webhooks-blackst0ne (3.3.0)
rest-client (~> 2.0)
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20180417) domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
...@@ -299,7 +301,10 @@ GEM ...@@ -299,7 +301,10 @@ GEM
gitaly-proto (0.123.0) gitaly-proto (0.123.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
<<<<<<< HEAD
gitlab-license (1.0.0) gitlab-license (1.0.0)
=======
>>>>>>> upstream/master
gitlab-markup (1.6.5) gitlab-markup (1.6.5)
gitlab-sidekiq-fetcher (0.3.0) gitlab-sidekiq-fetcher (0.3.0)
sidekiq (~> 5) sidekiq (~> 5)
...@@ -1004,6 +1009,7 @@ DEPENDENCIES ...@@ -1004,6 +1009,7 @@ DEPENDENCIES
devise (~> 4.4) devise (~> 4.4)
devise-two-factor (~> 3.0.0) devise-two-factor (~> 3.0.0)
diffy (~> 3.1.0) diffy (~> 3.1.0)
discordrb-webhooks-blackst0ne (~> 3.3)
doorkeeper (~> 4.3) doorkeeper (~> 4.3)
doorkeeper-openid_connect (~> 1.5) doorkeeper-openid_connect (~> 1.5)
ed25519 (~> 1.2) ed25519 (~> 1.2)
...@@ -1038,7 +1044,10 @@ DEPENDENCIES ...@@ -1038,7 +1044,10 @@ DEPENDENCIES
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 0.123.0) gitaly-proto (~> 0.123.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
<<<<<<< HEAD
gitlab-license (~> 1.0) gitlab-license (~> 1.0)
=======
>>>>>>> upstream/master
gitlab-markup (~> 1.6.5) gitlab-markup (~> 1.6.5)
gitlab-sidekiq-fetcher gitlab-sidekiq-fetcher
gitlab-styles (~> 2.4) gitlab-styles (~> 2.4)
......
...@@ -138,6 +138,7 @@ class Project < ActiveRecord::Base ...@@ -138,6 +138,7 @@ class Project < ActiveRecord::Base
# Project services # Project services
has_one :campfire_service has_one :campfire_service
has_one :discord_service
has_one :drone_ci_service has_one :drone_ci_service
has_one :emails_on_push_service has_one :emails_on_push_service
has_one :pipelines_email_service has_one :pipelines_email_service
......
# frozen_string_literal: true
require "discordrb/webhooks"
class DiscordService < ChatNotificationService
def title
"Discord Notifications"
end
def description
"Receive event notifications in Discord"
end
def self.to_param
"discord"
end
def help
"This service sends notifications about project events to Discord channels.<br />
To set up this service:
<ol>
<li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li>
<li>Paste the <strong>Webhook URL</strong> into the field below.</li>
<li>Select events below to enable notifications.</li>
</ol>"
end
def event_field(event)
# No-op.
end
def default_channel_placeholder
# No-op.
end
def default_fields
[
{ type: "text", name: "webhook", placeholder: "e.g. https://discordapp.com/api/webhooks/…" },
{ type: "checkbox", name: "notify_only_broken_pipelines" },
{ type: "checkbox", name: "notify_only_default_branch" }
]
end
private
def notify(message, opts)
client = Discordrb::Webhooks::Client.new(url: webhook)
client.execute do |builder|
builder.content = message.pretext
end
end
def custom_data(data)
super(data).merge(markdown: true)
end
end
...@@ -254,6 +254,7 @@ class Service < ActiveRecord::Base ...@@ -254,6 +254,7 @@ class Service < ActiveRecord::Base
bugzilla bugzilla
campfire campfire
custom_issue_tracker custom_issue_tracker
discord
drone_ci drone_ci
emails_on_push emails_on_push
external_wiki external_wiki
......
---
title: Add Discord integration
merge_request: 22684
author: "@blackst0ne"
type: added
...@@ -4,9 +4,7 @@ description: "Set and configure Git protocol v2" ...@@ -4,9 +4,7 @@ description: "Set and configure Git protocol v2"
# Configuring Git Protocol v2 # Configuring Git Protocol v2
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/46555) in GitLab 11.4. > [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/46555) in GitLab 11.4.
---
Git protocol v2 improves the v1 wire protocol in several ways and is Git protocol v2 improves the v1 wire protocol in several ways and is
enabled by default in GitLab for HTTP requests. In order to enable SSH, enabled by default in GitLab for HTTP requests. In order to enable SSH,
......
...@@ -10,7 +10,7 @@ Asana - Teamwork without email ...@@ -10,7 +10,7 @@ Asana - Teamwork without email
Set Asana service for a project. Set Asana service for a project.
> This service adds commit messages as comments to Asana tasks. Once enabled, commit messages are checked for Asana task URLs (for example, `https://app.asana.com/0/123456/987654`) or task IDs starting with # (for example, `#987654`). Every task ID found will get the commit comment added to it. You can also close a task with a message containing: `fix #123456`. You can find your Api Keys here: https://asana.com/developers/documentation/getting-started/auth#api-key > This service adds commit messages as comments to Asana tasks. Once enabled, commit messages are checked for Asana task URLs (for example, `https://app.asana.com/0/123456/987654`) or task IDs starting with # (for example, `#987654`). Every task ID found will get the commit comment added to it. You can also close a task with a message containing: `fix #123456`. You can find your Api Keys here: <https://asana.com/developers/documentation/getting-started/auth#api-key>.
``` ```
PUT /projects/:id/services/asana PUT /projects/:id/services/asana
...@@ -92,7 +92,7 @@ Parameters: ...@@ -92,7 +92,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `bamboo_url` | string | true | Bamboo root URL like https://bamboo.example.com | | `bamboo_url` | string | true | Bamboo root URL. For example, `https://bamboo.example.com`. |
| `build_key` | string | true | Bamboo build plan key like KEY | | `build_key` | string | true | Bamboo build plan key like KEY |
| `username` | string | true | A user with API access, if applicable | | `username` | string | true | A user with API access, if applicable |
| `password` | string | true | Password of the user | | `password` | string | true | Password of the user |
...@@ -117,7 +117,7 @@ GET /projects/:id/services/bamboo ...@@ -117,7 +117,7 @@ GET /projects/:id/services/bamboo
Bugzilla Issue Tracker Bugzilla Issue Tracker
### Create/Edit Buildkite service ### Create/Edit Bugzilla service
Set Bugzilla service for a project. Set Bugzilla service for a project.
...@@ -168,7 +168,7 @@ Parameters: ...@@ -168,7 +168,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `token` | string | true | Buildkite project GitLab token | | `token` | string | true | Buildkite project GitLab token |
| `project_url` | string | true | https://buildkite.com/example/project | | `project_url` | string | true | `https://buildkite.com/example/project` |
| `enable_ssl_verification` | boolean | false | Enable SSL verification | | `enable_ssl_verification` | boolean | false | Enable SSL verification |
### Delete Buildkite service ### Delete Buildkite service
...@@ -278,7 +278,7 @@ Parameters: ...@@ -278,7 +278,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `token` | string | true | Drone CI project specific token | | `token` | string | true | Drone CI project specific token |
| `drone_url` | string | true | http://drone.example.com | | `drone_url` | string | true | `http://drone.example.com` |
| `enable_ssl_verification` | boolean | false | Enable SSL verification | | `enable_ssl_verification` | boolean | false | Enable SSL verification |
### Delete Drone CI service ### Delete Drone CI service
...@@ -421,7 +421,7 @@ Parameters: ...@@ -421,7 +421,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `webhook` | string | true | The Hangouts Chat webhook. e.g. https://chat.googleapis.com/v1/spaces... | | `webhook` | string | true | The Hangouts Chat webhook. For example, `https://chat.googleapis.com/v1/spaces...`. |
| `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines | | `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines |
| `notify_only_default_branch` | boolean | false | Send notifications only for the default branch | | `notify_only_default_branch` | boolean | false | Send notifications only for the default branch |
| `push_events` | boolean | false | Enable notifications for push events | | `push_events` | boolean | false | Enable notifications for push events |
...@@ -470,7 +470,7 @@ Parameters: ...@@ -470,7 +470,7 @@ Parameters:
| `notify` | boolean | false | Enable notifications | | `notify` | boolean | false | Enable notifications |
| `room` | string | false |Room name or ID | | `room` | string | false |Room name or ID |
| `api_version` | string | false | Leave blank for default (v2) | | `api_version` | string | false | Leave blank for default (v2) |
| `server` | string | false | Leave blank for default. https://hipchat.example.com | | `server` | string | false | Leave blank for default. For example, `https://hipchat.example.com`. |
### Delete HipChat service ### Delete HipChat service
...@@ -496,7 +496,7 @@ Send IRC messages, on update, to a list of recipients through an Irker gateway. ...@@ -496,7 +496,7 @@ Send IRC messages, on update, to a list of recipients through an Irker gateway.
Set Irker (IRC gateway) service for a project. Set Irker (IRC gateway) service for a project.
> NOTE: Irker does NOT have built-in authentication, which makes it vulnerable to spamming IRC channels if it is hosted outside of a firewall. Please make sure you run the daemon within a secured network to prevent abuse. For more details, read: http://www.catb.org/~esr/irker/security.html. > NOTE: Irker does NOT have built-in authentication, which makes it vulnerable to spamming IRC channels if it is hosted outside of a firewall. Please make sure you run the daemon within a secured network to prevent abuse. For more details, read: <http://www.catb.org/~esr/irker/security.html>.
``` ```
PUT /projects/:id/services/irker PUT /projects/:id/services/irker
...@@ -546,7 +546,7 @@ Set JIRA service for a project. ...@@ -546,7 +546,7 @@ Set JIRA service for a project.
> **Notes:** > **Notes:**
> - Starting with GitLab 8.14, `api_url`, `issues_url`, `new_issue_url` and > - Starting with GitLab 8.14, `api_url`, `issues_url`, `new_issue_url` and
> `project_url` are replaced by `project_key`, `url`. If you are using an > `project_url` are replaced by `project_key`, `url`. If you are using an
> older version, [follow this documentation][old-jira-api]. > older version, [follow this documentation][old-jira-api].
``` ```
...@@ -557,7 +557,7 @@ Parameters: ...@@ -557,7 +557,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `url` | string | yes | The URL to the JIRA project which is being linked to this GitLab project, e.g., `https://jira.example.com`. | | `url` | string | yes | The URL to the JIRA project which is being linked to this GitLab project. For example, `https://jira.example.com`. |
| `project_key` | string | yes | The short identifier for your JIRA project, all uppercase, e.g., `PROJ`. | | `project_key` | string | yes | The short identifier for your JIRA project, all uppercase, e.g., `PROJ`. |
| `username` | string | yes | The username of the user created to be used with GitLab/JIRA. | | `username` | string | yes | The username of the user created to be used with GitLab/JIRA. |
| `password` | string | yes | The password of the user created to be used with GitLab/JIRA. | | `password` | string | yes | The password of the user created to be used with GitLab/JIRA. |
...@@ -589,7 +589,7 @@ PUT /projects/:id/services/kubernetes ...@@ -589,7 +589,7 @@ PUT /projects/:id/services/kubernetes
Parameters: Parameters:
- `namespace` (**required**) - The Kubernetes namespace to use - `namespace` (**required**) - The Kubernetes namespace to use
- `api_url` (**required**) - The URL to the Kubernetes cluster API, e.g., https://kubernetes.example.com - `api_url` (**required**) - The URL to the Kubernetes cluster API. For example, `https://kubernetes.example.com`
- `token` (**required**) - The service token to authenticate against the Kubernetes cluster with - `token` (**required**) - The service token to authenticate against the Kubernetes cluster with
- `ca_pem` (optional) - A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format) - `ca_pem` (optional) - A custom certificate authority bundle to verify the Kubernetes cluster with (PEM format)
...@@ -658,7 +658,6 @@ Parameters: ...@@ -658,7 +658,6 @@ Parameters:
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `token` | string | yes | The Slack token | | `token` | string | yes | The Slack token |
### Delete Slack slash command service ### Delete Slack slash command service
Delete Slack slash command service for a project. Delete Slack slash command service for a project.
...@@ -823,7 +822,7 @@ Parameters: ...@@ -823,7 +822,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `api_url` | string | true | Prometheus API Base URL, like http://prometheus.example.com/ | | `api_url` | string | true | Prometheus API Base URL. For example, `http://prometheus.example.com/`. |
### Delete Prometheus service ### Delete Prometheus service
...@@ -934,7 +933,7 @@ Parameters: ...@@ -934,7 +933,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `webhook` | string | true | https://hooks.slack.com/services/... | | `webhook` | string | true | `https://hooks.slack.com/services/...` |
| `username` | string | false | username | | `username` | string | false | username |
| `channel` | string | false | Default channel to use if others are not configured | | `channel` | string | false | Default channel to use if others are not configured |
| `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines | | `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines |
...@@ -988,7 +987,7 @@ Parameters: ...@@ -988,7 +987,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `webhook` | string | true | The Microsoft Teams webhook. e.g. https://outlook.office.com/webhook/... | | `webhook` | string | true | The Microsoft Teams webhook. For example, `https://outlook.office.com/webhook/...` |
### Delete Microsoft Teams service ### Delete Microsoft Teams service
...@@ -1024,7 +1023,7 @@ Parameters: ...@@ -1024,7 +1023,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `webhook` | string | true | The Mattermost webhook. e.g. http://mattermost_host/hooks/... | | `webhook` | string | true | The Mattermost webhook. For example, `http://mattermost_host/hooks/...` |
| `username` | string | false | username | | `username` | string | false | username |
| `channel` | string | false | Default channel to use if others are not configured | | `channel` | string | false | Default channel to use if others are not configured |
| `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines | | `notify_only_broken_pipelines` | boolean | false | Send notifications for broken pipelines |
...@@ -1080,7 +1079,7 @@ Parameters: ...@@ -1080,7 +1079,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `teamcity_url` | string | true | TeamCity root URL like https://teamcity.example.com | | `teamcity_url` | string | true | TeamCity root URL. For example, `https://teamcity.example.com` |
| `build_type` | string | true | Build configuration ID | | `build_type` | string | true | Build configuration ID |
| `username` | string | true | A user with permissions to trigger a manual build | | `username` | string | true | A user with permissions to trigger a manual build |
| `password` | string | true | The password of the user | | `password` | string | true | The password of the user |
...@@ -1175,7 +1174,6 @@ GET /projects/:id/services/jenkins-deprecated ...@@ -1175,7 +1174,6 @@ GET /projects/:id/services/jenkins-deprecated
[jira-doc]: ../user/project/integrations/jira.md [jira-doc]: ../user/project/integrations/jira.md
[old-jira-api]: https://gitlab.com/gitlab-org/gitlab-ce/blob/8-13-stable/doc/api/services.md#jira [old-jira-api]: https://gitlab.com/gitlab-org/gitlab-ce/blob/8-13-stable/doc/api/services.md#jira
## MockCI ## MockCI
Mock an external CI. See [`gitlab-org/gitlab-mock-ci-service`](https://gitlab.com/gitlab-org/gitlab-mock-ci-service) for an example of a companion mock service. Mock an external CI. See [`gitlab-org/gitlab-mock-ci-service`](https://gitlab.com/gitlab-org/gitlab-mock-ci-service) for an example of a companion mock service.
...@@ -1194,7 +1192,7 @@ Parameters: ...@@ -1194,7 +1192,7 @@ Parameters:
| Parameter | Type | Required | Description | | Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `mock_service_url` | string | true | http://localhost:4004 | | `mock_service_url` | string | true | `http://localhost:4004` |
### Delete MockCI service ### Delete MockCI service
......
...@@ -29,7 +29,7 @@ Below is a valid example of a manifest file: ...@@ -29,7 +29,7 @@ Below is a valid example of a manifest file:
```xml ```xml
<manifest> <manifest>
<remote review="https://android-review.googlesource.com/" /> <remote review="https://android.googlesource.com/" />
<project path="build/make" name="platform/build" /> <project path="build/make" name="platform/build" />
<project path="build/blueprint" name="platform/build/blueprint" /> <project path="build/blueprint" name="platform/build/blueprint" />
...@@ -38,10 +38,10 @@ Below is a valid example of a manifest file: ...@@ -38,10 +38,10 @@ Below is a valid example of a manifest file:
As a result, the following projects will be created: As a result, the following projects will be created:
| GitLab | Import URL | | GitLab | Import URL |
|---|---| |:------------------------------------------------|:------------------------------------------------------------|
| https://gitlab.com/YOUR_GROUP/build/make | https://android-review.googlesource.com/platform/build | | `https://gitlab.com/YOUR_GROUP/build/make` | <https://android.googlesource.com/platform/build> |
| https://gitlab.com/YOUR_GROUP/build/blueprint | https://android-review.googlesource.com/platform/build/blueprint | | `https://gitlab.com/YOUR_GROUP/build/blueprint` | <https://android.googlesource.com/platform/build/blueprint> |
## Importing the repositories ## Importing the repositories
......
# Discord Notifications service
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22684) in GitLab 11.5.
The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created.
To send GitLab event notifications to a Discord channel, create a webhook in Discord and configure it in GitLab.
## Create webhook
1. Open the Discord channel you want to receive GitLab event notifications.
1. From the channel menu, select **Edit channel**.
1. Click on **Webhooks** menu item.
1. Click the **Create Webhook** button and fill in the name of the bot that will post the messages. Optionally, edit the avatar.
1. Note the URL from the **WEBHOOK URL** field.
1. Click the **Save** button.
## Configure created webhook in GitLab
With the webhook URL created in the Discord channel, you can set up the Discord Notifications service in GitLab.
1. Navigate to the [Integrations page](project_services.md#accessing-the-project-services) in your project's settings. That is, **Project > Settings > Integrations**.
1. Select the **Discord Notifications** project service to configure it.
1. Check the **Active** checkbox to turn on the service.
1. Check the checkboxes corresponding to the GitLab events for which you want to send notifications to Discord.
1. Paste the webhook URL that you copied from the create Discord webhook step.
1. Configure the remaining options and click the **Save changes** button.
The Discord channel you created the webhook for will now receive notification of the GitLab events that were configured.
...@@ -30,6 +30,7 @@ Click on the service links to see further configuration instructions and details ...@@ -30,6 +30,7 @@ Click on the service links to see further configuration instructions and details
| [Bugzilla](bugzilla.md) | Bugzilla issue tracker | | [Bugzilla](bugzilla.md) | Bugzilla issue tracker |
| Campfire | Simple web-based real-time group chat | | Campfire | Simple web-based real-time group chat |
| Custom Issue Tracker | Custom issue tracker | | Custom Issue Tracker | Custom issue tracker |
| [Discord Notifications](discord_notifications.md) | Receive event notifications in Discord |
| Drone CI | Continuous Integration platform built on Docker, written in Go | | Drone CI | Continuous Integration platform built on Docker, written in Go |
| [Emails on push](emails_on_push.md) | Email the commits and diff of each push to a list of recipients | | [Emails on push](emails_on_push.md) | Email the commits and diff of each push to a list of recipients |
| External Wiki | Replaces the link to the internal wiki with a link to an external wiki | | External Wiki | Replaces the link to the internal wiki with a link to an external wiki |
......
...@@ -298,6 +298,14 @@ module API ...@@ -298,6 +298,14 @@ module API
desc: 'Title' desc: 'Title'
} }
], ],
'discord' => [
{
required: true,
name: :webhook,
type: String,
desc: 'Discord webhook. e.g. https://discordapp.com/api/webhooks/…'
}
],
'drone-ci' => [ 'drone-ci' => [
{ {
required: true, required: true,
...@@ -737,6 +745,7 @@ module API ...@@ -737,6 +745,7 @@ module API
BuildkiteService, BuildkiteService,
CampfireService, CampfireService,
CustomIssueTrackerService, CustomIssueTrackerService,
DiscordService,
DroneCiService, DroneCiService,
EmailsOnPushService, EmailsOnPushService,
ExternalWikiService, ExternalWikiService,
......
require "spec_helper" require "spec_helper"
describe "User views issue" do describe "User views issue" do
set(:project) { create(:project_empty_repo, :public) } let(:project) { create(:project_empty_repo, :public) }
set(:user) { create(:user) } let(:user) { create(:user) }
set(:issue) { create(:issue, project: project, description: "# Description header", author: user) } let(:issue) { create(:issue, project: project, description: "# Description header", author: user) }
before do before do
project.add_developer(user) project.add_developer(user)
......
...@@ -198,6 +198,7 @@ project: ...@@ -198,6 +198,7 @@ project:
- last_event - last_event
- services - services
- campfire_service - campfire_service
- discord_service
- drone_ci_service - drone_ci_service
- emails_on_push_service - emails_on_push_service
- pipelines_email_service - pipelines_email_service
......
# frozen_string_literal: true
require "spec_helper"
describe DiscordService do
it_behaves_like "chat service", "Discord notifications" do
let(:client) { Discordrb::Webhooks::Client }
let(:client_arguments) { { url: webhook_url } }
let(:content_key) { :content }
end
end
require 'spec_helper' # frozen_string_literal: true
describe HangoutsChatService do require "spec_helper"
describe 'Associations' do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
describe 'Validations' do
context 'when service is active' do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:webhook) }
it_behaves_like 'issue tracker service URL attribute', :webhook
end
context 'when service is inactive' do
before do
subject.active = false
end
it { is_expected.not_to validate_presence_of(:webhook) }
end
end
describe '#execute' do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:webhook_url) { 'https://example.gitlab.com/' }
before do
allow(subject).to receive_messages(
project: project,
project_id: project.id,
service_hook: true,
webhook: webhook_url
)
WebMock.stub_request(:post, webhook_url)
end
shared_examples 'Hangouts Chat service' do
it 'calls Hangouts Chat API' do
subject.execute(sample_data)
expect(WebMock)
.to have_requested(:post, webhook_url)
.with { |req| req.body =~ /\A{"text":.+}\Z/ }
.once
end
end
context 'with push events' do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
it_behaves_like 'Hangouts Chat service'
it 'specifies the webhook when it is configured' do
expect(HangoutsChat::Sender).to receive(:new).with(webhook_url).and_return(double(:hangouts_chat_service).as_null_object)
subject.execute(sample_data)
end
context 'with not default branch' do
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project, user, nil, nil, 'not-the-default-branch')
end
context 'when notify_only_default_branch enabled' do
before do
subject.notify_only_default_branch = true
end
it 'does not call the Hangouts Chat API' do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context 'when notify_only_default_branch disabled' do
before do
subject.notify_only_default_branch = false
end
it_behaves_like 'Hangouts Chat service'
end
end
end
context 'with issue events' do
let(:opts) { { title: 'Awesome issue', description: 'please fix' } }
let(:sample_data) do
service = Issues::CreateService.new(project, user, opts)
issue = service.execute
service.hook_data(issue, 'open')
end
it_behaves_like 'Hangouts Chat service'
end
context 'with merge events' do
let(:opts) do
{
title: 'Awesome merge_request',
description: 'please fix',
source_branch: 'feature',
target_branch: 'master'
}
end
let(:sample_data) do
service = MergeRequests::CreateService.new(project, user, opts)
merge_request = service.execute
service.hook_data(merge_request, 'open')
end
before do
project.add_developer(user)
end
it_behaves_like 'Hangouts Chat service' describe HangoutsChatService do
end it_behaves_like "chat service", "Hangouts Chat" do
let(:client) { HangoutsChat::Sender }
context 'with wiki page events' do let(:client_arguments) { webhook_url }
let(:opts) do let(:content_key) { :text }
{
title: 'Awesome wiki_page',
content: 'Some text describing some thing or another',
format: 'md',
message: 'user created page: Awesome wiki_page'
}
end
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
it_behaves_like 'Hangouts Chat service'
end
context 'with note events' do
let(:sample_data) { Gitlab::DataBuilder::Note.build(note, user) }
context 'with commit comment' do
let(:note) do
create(:note_on_commit, author: user,
project: project,
commit_id: project.repository.commit.id,
note: 'a comment on a commit')
end
it_behaves_like 'Hangouts Chat service'
end
context 'with merge request comment' do
let(:note) do
create(:note_on_merge_request, project: project,
note: 'merge request note')
end
it_behaves_like 'Hangouts Chat service'
end
context 'with issue comment' do
let(:note) do
create(:note_on_issue, project: project, note: 'issue note')
end
it_behaves_like 'Hangouts Chat service'
end
context 'with snippet comment' do
let(:note) do
create(:note_on_project_snippet, project: project,
note: 'snippet note')
end
it_behaves_like 'Hangouts Chat service'
end
end
context 'with pipeline events' do
let(:pipeline) do
create(:ci_pipeline,
project: project, status: status,
sha: project.commit.sha, ref: project.default_branch)
end
let(:sample_data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
context 'with failed pipeline' do
let(:status) { 'failed' }
it_behaves_like 'Hangouts Chat service'
end
context 'with succeeded pipeline' do
let(:status) { 'success' }
context 'with default notify_only_broken_pipelines' do
it 'does not call Hangouts Chat API' do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context 'when notify_only_broken_pipelines is false' do
before do
subject.notify_only_broken_pipelines = false
end
it_behaves_like 'Hangouts Chat service'
end
end
context 'with not default branch' do
let(:pipeline) do
create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch')
end
context 'when notify_only_default_branch enabled' do
before do
subject.notify_only_default_branch = true
end
it 'does not call the Hangouts Chat API' do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context 'when notify_only_default_branch disabled' do
before do
subject.notify_only_default_branch = false
end
it_behaves_like 'Hangouts Chat service'
end
end
end
end end
end end
...@@ -33,6 +33,7 @@ describe Project do ...@@ -33,6 +33,7 @@ describe Project do
it { is_expected.to have_one(:asana_service) } it { is_expected.to have_one(:asana_service) }
it { is_expected.to have_many(:boards) } it { is_expected.to have_many(:boards) }
it { is_expected.to have_one(:campfire_service) } it { is_expected.to have_one(:campfire_service) }
it { is_expected.to have_one(:discord_service) }
it { is_expected.to have_one(:drone_ci_service) } it { is_expected.to have_one(:drone_ci_service) }
it { is_expected.to have_one(:emails_on_push_service) } it { is_expected.to have_one(:emails_on_push_service) }
it { is_expected.to have_one(:pipelines_email_service) } it { is_expected.to have_one(:pipelines_email_service) }
......
require "spec_helper"
shared_examples_for "chat service" do |service_name|
describe "Associations" do
it { is_expected.to belong_to :project }
it { is_expected.to have_one :service_hook }
end
describe "Validations" do
context "when service is active" do
before do
subject.active = true
end
it { is_expected.to validate_presence_of(:webhook) }
it_behaves_like "issue tracker service URL attribute", :webhook
end
context "when service is inactive" do
before do
subject.active = false
end
it { is_expected.not_to validate_presence_of(:webhook) }
end
end
describe "#execute" do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:webhook_url) { "https://example.gitlab.com/" }
before do
allow(subject).to receive_messages(
project: project,
project_id: project.id,
service_hook: true,
webhook: webhook_url
)
WebMock.stub_request(:post, webhook_url)
end
shared_examples "#{service_name} service" do
it "calls #{service_name} API" do
subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"#{content_key}":.+}\Z/ }.once
end
end
context "with push events" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
it_behaves_like "#{service_name} service"
it "specifies the webhook when it is configured" do
expect(client).to receive(:new).with(client_arguments).and_return(double(:chat_service).as_null_object)
subject.execute(sample_data)
end
context "with not default branch" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project, user, nil, nil, "not-the-default-branch")
end
context "when notify_only_default_branch enabled" do
before do
subject.notify_only_default_branch = true
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when notify_only_default_branch disabled" do
before do
subject.notify_only_default_branch = false
end
it_behaves_like "#{service_name} service"
end
end
end
context "with issue events" do
let(:opts) { { title: "Awesome issue", description: "please fix" } }
let(:sample_data) do
service = Issues::CreateService.new(project, user, opts)
issue = service.execute
service.hook_data(issue, "open")
end
it_behaves_like "#{service_name} service"
end
context "with merge events" do
let(:opts) do
{
title: "Awesome merge_request",
description: "please fix",
source_branch: "feature",
target_branch: "master"
}
end
let(:sample_data) do
service = MergeRequests::CreateService.new(project, user, opts)
merge_request = service.execute
service.hook_data(merge_request, "open")
end
before do
project.add_developer(user)
end
it_behaves_like "#{service_name} service"
end
context "with wiki page events" do
let(:opts) do
{
title: "Awesome wiki_page",
content: "Some text describing some thing or another",
format: "md",
message: "user created page: Awesome wiki_page"
}
end
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") }
it_behaves_like "#{service_name} service"
end
context "with note events" do
let(:sample_data) { Gitlab::DataBuilder::Note.build(note, user) }
context "with commit comment" do
let(:note) do
create(:note_on_commit,
author: user,
project: project,
commit_id: project.repository.commit.id,
note: "a comment on a commit")
end
it_behaves_like "#{service_name} service"
end
context "with merge request comment" do
let(:note) do
create(:note_on_merge_request, project: project, note: "merge request note")
end
it_behaves_like "#{service_name} service"
end
context "with issue comment" do
let(:note) do
create(:note_on_issue, project: project, note: "issue note")
end
it_behaves_like "#{service_name} service"
end
context "with snippet comment" do
let(:note) do
create(:note_on_project_snippet, project: project, note: "snippet note")
end
it_behaves_like "#{service_name} service"
end
end
context "with pipeline events" do
let(:pipeline) do
create(:ci_pipeline,
project: project, status: status,
sha: project.commit.sha, ref: project.default_branch)
end
let(:sample_data) { Gitlab::DataBuilder::Pipeline.build(pipeline) }
context "with failed pipeline" do
let(:status) { "failed" }
it_behaves_like "#{service_name} service"
end
context "with succeeded pipeline" do
let(:status) { "success" }
context "with default notify_only_broken_pipelines" do
it "does not call Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when notify_only_broken_pipelines is false" do
before do
subject.notify_only_broken_pipelines = false
end
it_behaves_like "#{service_name} service"
end
end
context "with not default branch" do
let(:pipeline) do
create(:ci_pipeline, project: project, status: "failed", ref: "not-the-default-branch")
end
context "when notify_only_default_branch enabled" do
before do
subject.notify_only_default_branch = true
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when notify_only_default_branch disabled" do
before do
subject.notify_only_default_branch = false
end
it_behaves_like "#{service_name} service"
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment