Commit 593c9121 authored by Robert Schilling's avatar Robert Schilling

Grapify the service API

parent 0f90fd63
......@@ -3,7 +3,8 @@ require "addressable/uri"
class BuildkiteService < CiService
ENDPOINT = "https://buildkite.com"
prop_accessor :project_url, :token, :enable_ssl_verification
prop_accessor :project_url, :token
boolean_accessor :enable_ssl_verification
validates :project_url, presence: true, url: true, if: :activated?
validates :token, presence: true, if: :activated?
......
class DroneCiService < CiService
prop_accessor :drone_url, :token, :enable_ssl_verification
prop_accessor :drone_url, :token
boolean_accessor :enable_ssl_verification
validates :drone_url, presence: true, url: true, if: :activated?
validates :token, presence: true, if: :activated?
......
class EmailsOnPushService < Service
prop_accessor :send_from_committer_email
prop_accessor :disable_diffs
boolean_accessor :send_from_committer_email
boolean_accessor :disable_diffs
prop_accessor :recipients
validates :recipients, presence: true, if: :activated?
......@@ -24,20 +24,20 @@ class EmailsOnPushService < Service
return unless supported_events.include?(push_data[:object_kind])
EmailsOnPushWorker.perform_async(
project_id,
recipients,
push_data,
send_from_committer_email: send_from_committer_email?,
disable_diffs: disable_diffs?
project_id,
recipients,
push_data,
send_from_committer_email: send_from_committer_email?,
disable_diffs: disable_diffs?
)
end
def send_from_committer_email?
self.send_from_committer_email == "1"
Gitlab::Utils.to_boolean(self.send_from_committer_email)
end
def disable_diffs?
self.disable_diffs == "1"
Gitlab::Utils.to_boolean(self.disable_diffs)
end
def fields
......
......@@ -8,8 +8,8 @@ class HipchatService < Service
ul ol li dl dt dd
]
prop_accessor :token, :room, :server, :notify, :color, :api_version
boolean_accessor :notify_only_broken_builds
prop_accessor :token, :room, :server, :color, :api_version
boolean_accessor :notify_only_broken_builds, :notify
validates :token, presence: true, if: :activated?
def initialize_properties
......@@ -75,7 +75,7 @@ class HipchatService < Service
end
def message_options(data = nil)
{ notify: notify.present? && notify == '1', color: message_color(data) }
{ notify: notify.present? && Gitlab::Utils.to_boolean(notify), color: message_color(data) }
end
def create_message(data)
......
......@@ -2,7 +2,8 @@ require 'uri'
class IrkerService < Service
prop_accessor :server_host, :server_port, :default_irc_uri
prop_accessor :colorize_messages, :recipients, :channels
prop_accessor :recipients, :channels
boolean_accessor :colorize_messages
validates :recipients, presence: true, if: :activated?
before_validation :get_channels
......
......@@ -139,6 +139,40 @@ Get Buildkite service settings for a project.
GET /projects/:id/services/buildkite
```
## Build-Emails
Get emails for GitLab CI builds.
### Create/Edit Build-Emails service
Set Build-Emails service for a project.
```
PUT /projects/:id/services/builds-email
```
Parameters:
- `recipients` (**required**) - Comma-separated list of recipient email addresses
- `add_pusher` (optional) - Add pusher to recipients list
- `notify_only_broken_builds` (optional) -Notify only broken builds
### Delete Build-Emails service
Delete Build-Emails service for a project.
```
DELETE /projects/:id/services/builds-email
```
### Get Build-Emails service settings
Get Build-Emails service settings for a project.
```
GET /projects/:id/services/builds-email
```
## Campfire
Simple web-based real-time group chat
......@@ -476,12 +510,11 @@ PUT /projects/:id/services/jira
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `active` | boolean| no | Enable/disable the JIRA service. |
| `url` | string | yes | The URL to the JIRA project which is being linked to this GitLab project, e.g., `https://jira.example.com`. |
| `project_key` | string | yes | The short identifier for your JIRA project, all uppercase, e.g., `PROJ`. |
| `username` | string | no | The username of the user created to be used with GitLab/JIRA. |
| `password` | string | no | The password of the user created to be used with GitLab/JIRA. |
| `jira_issue_transition_id` | string | no | The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`. |
| `jira_issue_transition_id` | integer | no | The ID of a transition that moves issues to a closed state. You can find this number under the JIRA workflow administration (**Administration > Issues > Workflows**) by selecting **View** under **Operations** of the desired workflow of your project. The ID of each state can be found inside the parenthesis of each transition name under the **Transitions (id)** column ([see screenshot][trans]). By default, this ID is set to `2`. |
### Delete JIRA service
......@@ -491,6 +524,71 @@ Remove all previously JIRA settings from a project.
DELETE /projects/:id/services/jira
```
## Mattermost Slash Commands
Ability to receive slash commands from a Mattermost chat instance.
### Create/Edit Mattermost Slash Command service
Set Mattermost Slash Command for a project.
```
PUT /projects/:id/services/mattermost-slash-commands
```
Parameters:
- `token` (**required**) - The Mattermost token
### Delete Mattermost Slash Command service
Delete Mattermost Slash Command service for a project.
```
DELETE /projects/:id/services/mattermost-slash-commands
```
### Get Mattermost Slash Command service settings
Get Mattermost Slash Command service settings for a project.
```
GET /projects/:id/services/mattermost-slash-commands
```
## Pipeline-Emails
Get emails for GitLab CI pipelines.
### Create/Edit Pipeline-Emails service
Set Pipeline-Emails service for a project.
```
PUT /projects/:id/services/pipelines-email
```
Parameters:
- `recipients` (**required**) - Comma-separated list of recipient email addresses
- `notify_only_broken_builds` (optional) -Notify only broken pipelines
### Delete Pipeline-Emails service
Delete Pipeline-Emails service for a project.
```
DELETE /projects/:id/services/pipelines-email
```
### Get Pipeline-Emails service settings
Get Pipeline-Emails service settings for a project.
```
GET /projects/:id/services/pipelines-email
```
## PivotalTracker
Project Management Software (Source Commits Endpoint)
......
......@@ -93,17 +93,6 @@ module API
end
end
def project_service(project = user_project)
@project_service ||= project.find_or_initialize_service(params[:service_slug].underscore)
@project_service || not_found!("Service")
end
def service_attributes
@service_attributes ||= project_service.fields.inject([]) do |arr, hash|
arr << hash[:name].to_sym
end
end
def find_group(id)
if id =~ /^\d+$/
Group.find_by(id: id)
......
This diff is collapsed.
......@@ -358,7 +358,7 @@ describe HipchatService, models: true do
context 'with a failed build' do
it 'uses the red color' do
build_data = { object_kind: 'build', commit: { status: 'failed' } }
expect(hipchat.__send__(:message_options, build_data)).to eq({ notify: false, color: 'red' })
end
end
......
......@@ -2,6 +2,7 @@ require "spec_helper"
describe API::Services, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:user2) { create(:user) }
......@@ -98,7 +99,7 @@ describe API::Services, api: true do
post api("/projects/#{project.id}/services/idonotexist/trigger")
expect(response).to have_http_status(404)
expect(json_response["message"]).to eq("404 Service Not Found")
expect(json_response["error"]).to eq("404 Not Found")
end
end
......@@ -114,7 +115,7 @@ describe API::Services, api: true do
end
it 'when the service is inactive' do
post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger")
post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params
expect(response).to have_http_status(404)
end
......
......@@ -16,8 +16,14 @@ Service.available_services_names.each do |service|
hash.merge!(k => 'secrettoken')
elsif k =~ /^(.*_url|url|webhook)/
hash.merge!(k => "http://example.com")
elsif service_klass.method_defined?("#{k}?")
hash.merge!(k => true)
elsif service == 'irker' && k == :recipients
hash.merge!(k => 'irc://irc.network.net:666/#channel')
elsif service == 'irker' && k == :server_port
hash.merge!(k => 1234)
elsif service == 'jira' && k == :jira_issue_transition_id
hash.merge!(k => 1234)
else
hash.merge!(k => "someword")
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