Merge branch 'add-packagist-project-service' into 'master'
Add Packagist project service See merge request gitlab-org/gitlab-ce!14493
This commit is contained in:
commit
e829d5a084
13 changed files with 221 additions and 0 deletions
|
@ -120,6 +120,7 @@ class Project < ActiveRecord::Base
|
|||
has_one :mock_deployment_service
|
||||
has_one :mock_monitoring_service
|
||||
has_one :microsoft_teams_service
|
||||
has_one :packagist_service
|
||||
|
||||
# TODO: replace these relations with the fork network versions
|
||||
has_one :forked_project_link, foreign_key: "forked_to_project_id"
|
||||
|
|
65
app/models/project_services/packagist_service.rb
Normal file
65
app/models/project_services/packagist_service.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
class PackagistService < Service
|
||||
include HTTParty
|
||||
|
||||
prop_accessor :username, :token, :server
|
||||
|
||||
validates :username, presence: true, if: :activated?
|
||||
validates :token, presence: true, if: :activated?
|
||||
|
||||
default_value_for :push_events, true
|
||||
default_value_for :tag_push_events, true
|
||||
|
||||
after_save :compose_service_hook, if: :activated?
|
||||
|
||||
def title
|
||||
'Packagist'
|
||||
end
|
||||
|
||||
def description
|
||||
'Update your project on Packagist, the main Composer repository'
|
||||
end
|
||||
|
||||
def self.to_param
|
||||
'packagist'
|
||||
end
|
||||
|
||||
def fields
|
||||
[
|
||||
{ type: 'text', name: 'username', placeholder: '', required: true },
|
||||
{ type: 'text', name: 'token', placeholder: '', required: true },
|
||||
{ type: 'text', name: 'server', placeholder: 'https://packagist.org', required: false }
|
||||
]
|
||||
end
|
||||
|
||||
def self.supported_events
|
||||
%w(push merge_request tag_push)
|
||||
end
|
||||
|
||||
def execute(data)
|
||||
return unless supported_events.include?(data[:object_kind])
|
||||
|
||||
service_hook.execute(data)
|
||||
end
|
||||
|
||||
def test(data)
|
||||
begin
|
||||
result = execute(data)
|
||||
return { success: false, result: result[:message] } if result[:http_status] != 202
|
||||
rescue StandardError => error
|
||||
return { success: false, result: error }
|
||||
end
|
||||
|
||||
{ success: true, result: result[:message] }
|
||||
end
|
||||
|
||||
def compose_service_hook
|
||||
hook = service_hook || build_service_hook
|
||||
hook.url = hook_url
|
||||
hook.save
|
||||
end
|
||||
|
||||
def hook_url
|
||||
base_url = server.present? ? server : 'https://packagist.org'
|
||||
"#{base_url}/api/update-package?username=#{username}&apiToken=#{token}"
|
||||
end
|
||||
end
|
|
@ -238,6 +238,7 @@ class Service < ActiveRecord::Base
|
|||
kubernetes
|
||||
mattermost_slash_commands
|
||||
mattermost
|
||||
packagist
|
||||
pipelines_email
|
||||
pivotaltracker
|
||||
prometheus
|
||||
|
|
5
changelogs/unreleased/add-packagist-project-service.yml
Normal file
5
changelogs/unreleased/add-packagist-project-service.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add Packagist project service
|
||||
merge_request: 14493
|
||||
author: Matt Coleman
|
||||
type: added
|
|
@ -582,6 +582,40 @@ Delete Mattermost slash command service for a project.
|
|||
DELETE /projects/:id/services/mattermost-slash-commands
|
||||
```
|
||||
|
||||
## Packagist
|
||||
|
||||
Update your project on Packagist, the main Composer repository, when commits or tags are pushed to GitLab.
|
||||
|
||||
### Create/Edit Packagist service
|
||||
|
||||
Set Packagist service for a project.
|
||||
|
||||
```
|
||||
PUT /projects/:id/services/packagist
|
||||
```
|
||||
|
||||
Parameters:
|
||||
|
||||
- `username` (**required**)
|
||||
- `token` (**required**)
|
||||
- `server` (optional)
|
||||
|
||||
### Delete Packagist service
|
||||
|
||||
Delete Packagist service for a project.
|
||||
|
||||
```
|
||||
DELETE /projects/:id/services/packagist
|
||||
```
|
||||
|
||||
### Get Packagist service settings
|
||||
|
||||
Get Packagist service settings for a project.
|
||||
|
||||
```
|
||||
GET /projects/:id/services/packagist
|
||||
```
|
||||
|
||||
## Pipeline-Emails
|
||||
|
||||
Get emails for GitLab CI pipelines.
|
||||
|
|
|
@ -43,6 +43,7 @@ Click on the service links to see further configuration instructions and details
|
|||
| [Mattermost slash commands](mattermost_slash_commands.md) | Mattermost chat and ChatOps slash commands |
|
||||
| [Mattermost Notifications](mattermost.md) | Receive event notifications in Mattermost |
|
||||
| [Microsoft teams](microsoft_teams.md) | Receive notifications for actions that happen on GitLab into a room on Microsoft Teams using Office 365 Connectors |
|
||||
| Packagist | Update your project on Packagist, the main Composer repository |
|
||||
| Pipelines emails | Email the pipeline status to a list of recipients |
|
||||
| [Slack Notifications](slack.md) | Send GitLab events (e.g. issue created) to Slack as notifications |
|
||||
| [Slack slash commands](slack_slash_commands.md) | Use slash commands in Slack to control GitLab |
|
||||
|
|
|
@ -374,6 +374,26 @@ module API
|
|||
desc: 'The Slack token'
|
||||
}
|
||||
],
|
||||
'packagist' => [
|
||||
{
|
||||
required: true,
|
||||
name: :username,
|
||||
type: String,
|
||||
desc: 'The username'
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
name: :token,
|
||||
type: String,
|
||||
desc: 'The Packagist API token'
|
||||
},
|
||||
{
|
||||
required: false,
|
||||
name: :server,
|
||||
type: String,
|
||||
desc: 'The server'
|
||||
}
|
||||
],
|
||||
'pipelines-email' => [
|
||||
{
|
||||
required: true,
|
||||
|
@ -551,6 +571,7 @@ module API
|
|||
KubernetesService,
|
||||
MattermostSlashCommandsService,
|
||||
SlackSlashCommandsService,
|
||||
PackagistService,
|
||||
PipelinesEmailService,
|
||||
PivotaltrackerService,
|
||||
PrometheusService,
|
||||
|
|
|
@ -395,6 +395,26 @@ module API
|
|||
desc: 'The Slack token'
|
||||
}
|
||||
],
|
||||
'packagist' => [
|
||||
{
|
||||
required: true,
|
||||
name: :username,
|
||||
type: String,
|
||||
desc: 'The username'
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
name: :token,
|
||||
type: String,
|
||||
desc: 'The Packagist API token'
|
||||
},
|
||||
{
|
||||
required: false,
|
||||
name: :server,
|
||||
type: String,
|
||||
desc: 'The server'
|
||||
}
|
||||
],
|
||||
'pipelines-email' => [
|
||||
{
|
||||
required: true,
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'User activates Packagist' do
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
project.add_master(user)
|
||||
sign_in(user)
|
||||
|
||||
visit(project_settings_integrations_path(project))
|
||||
|
||||
click_link('Packagist')
|
||||
end
|
||||
|
||||
it 'activates service' do
|
||||
check('Active')
|
||||
fill_in('Username', with: 'theUser')
|
||||
fill_in('Token', with: 'verySecret')
|
||||
click_button('Save')
|
||||
|
||||
expect(page).to have_content('Packagist activated.')
|
||||
end
|
||||
end
|
|
@ -21,5 +21,6 @@ describe 'User views services' do
|
|||
expect(page).to have_content('JetBrains TeamCity')
|
||||
expect(page).to have_content('Asana')
|
||||
expect(page).to have_content('Irker (IRC gateway)')
|
||||
expect(page).to have_content('Packagist')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -195,6 +195,7 @@ project:
|
|||
- mattermost_slash_commands_service
|
||||
- slack_slash_commands_service
|
||||
- irker_service
|
||||
- packagist_service
|
||||
- pivotaltracker_service
|
||||
- prometheus_service
|
||||
- hipchat_service
|
||||
|
|
46
spec/models/project_services/packagist_service_spec.rb
Normal file
46
spec/models/project_services/packagist_service_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PackagistService do
|
||||
describe "Associations" do
|
||||
it { is_expected.to belong_to :project }
|
||||
it { is_expected.to have_one :service_hook }
|
||||
end
|
||||
|
||||
let(:project) { create(:project) }
|
||||
|
||||
let(:packagist_server) { 'https://packagist.example.com' }
|
||||
let(:packagist_username) { 'theUser' }
|
||||
let(:packagist_token) { 'verySecret' }
|
||||
let(:packagist_hook_url) do
|
||||
"#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}"
|
||||
end
|
||||
|
||||
let(:packagist_params) do
|
||||
{
|
||||
active: true,
|
||||
project: project,
|
||||
properties: {
|
||||
username: packagist_username,
|
||||
token: packagist_token,
|
||||
server: packagist_server
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
describe '#execute' do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:project, :repository) }
|
||||
let(:push_sample_data) { Gitlab::DataBuilder::Push.build_sample(project, user) }
|
||||
let(:packagist_service) { described_class.create(packagist_params) }
|
||||
|
||||
before do
|
||||
stub_request(:post, packagist_hook_url)
|
||||
end
|
||||
|
||||
it 'calls Packagist API' do
|
||||
packagist_service.execute(push_sample_data)
|
||||
|
||||
expect(a_request(:post, packagist_hook_url)).to have_been_made.once
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,6 +24,7 @@ describe Project do
|
|||
it { is_expected.to have_one(:slack_service) }
|
||||
it { is_expected.to have_one(:microsoft_teams_service) }
|
||||
it { is_expected.to have_one(:mattermost_service) }
|
||||
it { is_expected.to have_one(:packagist_service) }
|
||||
it { is_expected.to have_one(:pushover_service) }
|
||||
it { is_expected.to have_one(:asana_service) }
|
||||
it { is_expected.to have_many(:boards) }
|
||||
|
|
Loading…
Reference in a new issue