Commit 406a0c809b3c10d8fb2754cf626094b98ee78aeb
1 parent
85007434
Exists in
master
and in
4 other branches
GitLabCi Service imtegration
Showing
16 changed files
with
158 additions
and
7 deletions
Show diff stats
2.13 KB
app/assets/images/service-gitlab-ci.png
app/assets/stylesheets/gitlab_bootstrap/common.scss
... | ... | @@ -73,6 +73,7 @@ img.avatar.s16 { width:16px; height:16px; margin-right:6px; } |
73 | 73 | img.avatar.s24 { width:24px; height:24px; margin-right:8px; } |
74 | 74 | img.avatar.s32 { width:32px; height:32px; margin-right:10px; } |
75 | 75 | img.lil_av { padding-left: 4px; padding-right:3px; } |
76 | +img.small { width: 80px; } | |
76 | 77 | |
77 | 78 | /** HELPERS **/ |
78 | 79 | .nothing_here_message { text-align:center; padding:20px; color:#777; } |
... | ... | @@ -87,3 +88,5 @@ input[type='search'].search-text-input { |
87 | 88 | @include border-radius(4px); |
88 | 89 | border:1px solid #ccc; |
89 | 90 | } |
91 | + | |
92 | +fieldset legend { font-size: 17px; } | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +class ServicesController < ProjectResourceController | |
2 | + # Authorize | |
3 | + before_filter :authorize_admin_project! | |
4 | + | |
5 | + respond_to :html | |
6 | + | |
7 | + def index | |
8 | + @gitlab_ci_service = @project.gitlab_ci_service | |
9 | + end | |
10 | + | |
11 | + def edit | |
12 | + @service = @project.gitlab_ci_service | |
13 | + | |
14 | + # Create if missing | |
15 | + @service = @project.create_gitlab_ci_service unless @service | |
16 | + end | |
17 | + | |
18 | + def update | |
19 | + @service = @project.gitlab_ci_service | |
20 | + | |
21 | + if @service.update_attributes(params[:service]) | |
22 | + redirect_to :back | |
23 | + else | |
24 | + render 'edit' | |
25 | + end | |
26 | + end | |
27 | + | |
28 | + def test | |
29 | + commits = project.commits(project.default_branch, nil, 3) | |
30 | + data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) | |
31 | + | |
32 | + @service = project.gitlab_ci_service | |
33 | + @service.execute(data) | |
34 | + | |
35 | + redirect_to :back | |
36 | + end | |
37 | +end | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +# == Schema Information | |
2 | +# | |
3 | +# Table name: services | |
4 | +# | |
5 | +# id :integer not null, primary key | |
6 | +# type :string(255) | |
7 | +# title :string(255) | |
8 | +# token :string(255) | |
9 | +# project_id :integer not null | |
10 | +# created_at :datetime not null | |
11 | +# updated_at :datetime not null | |
12 | +# | |
13 | + | |
14 | +class GitlabCiService < Service | |
15 | + attr_accessible :project_url | |
16 | + | |
17 | + validates :project_url, presence: true | |
18 | + validates :token, presence: true | |
19 | + | |
20 | + delegate :execute, to: :service_hook, prefix: nil | |
21 | + | |
22 | + after_save :compose_service_hook | |
23 | + | |
24 | + def compose_service_hook | |
25 | + hook = service_hook || build_service_hook | |
26 | + hook.url = [project_url, "/build", "?token=#{token}"].join("") | |
27 | + hook.save | |
28 | + end | |
29 | +end | ... | ... |
app/models/project.rb
... | ... | @@ -48,6 +48,7 @@ class Project < ActiveRecord::Base |
48 | 48 | has_many :protected_branches, dependent: :destroy |
49 | 49 | has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' |
50 | 50 | has_many :services, dependent: :destroy |
51 | + has_one :gitlab_ci_service, dependent: :destroy | |
51 | 52 | |
52 | 53 | delegate :name, to: :owner, allow_nil: true, prefix: true |
53 | 54 | ... | ... |
app/models/service.rb
app/roles/push_observer.rb
... | ... | @@ -56,8 +56,8 @@ module PushObserver |
56 | 56 | def execute_services(data) |
57 | 57 | services.each do |service| |
58 | 58 | |
59 | - # Call service hook for service if it has one | |
60 | - service.service_hook.execute if service.service_hook | |
59 | + # Call service hook only if it is active | |
60 | + service.execute if service.active | |
61 | 61 | end |
62 | 62 | end |
63 | 63 | ... | ... |
app/views/projects/_project_head.html.haml
... | ... | @@ -21,6 +21,10 @@ |
21 | 21 | = link_to project_hooks_path(@project) do |
22 | 22 | %span |
23 | 23 | Hooks |
24 | + = nav_link(controller: :services, html_options: {class: 'right'}) do | |
25 | + = link_to project_services_path(@project) do | |
26 | + %span | |
27 | + Services | |
24 | 28 | = nav_link(path: 'projects#edit', html_options: {class: 'right'}) do |
25 | 29 | = link_to edit_project_path(@project), class: "stat-tab tab " do |
26 | 30 | %i.icon-edit | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +%h3.page_title | |
2 | + Services → GitLab CI Integration | |
3 | + | |
4 | + .right | |
5 | + .thumbnail | |
6 | + - if @service.active | |
7 | + = image_tag 'service-gitlab-ci.png', class: 'small' | |
8 | + - else | |
9 | + = image_tag 'service-disabled-gitlab-ci.png', class: 'small' | |
10 | + | |
11 | +%hr | |
12 | + | |
13 | + | |
14 | += form_for(@service, :as => :service, :url => project_service_path(@project, @service), :method => :put) do |f| | |
15 | + - if @service.errors.any? | |
16 | + .alert-message.block-message.error | |
17 | + %ul | |
18 | + - @service.errors.full_messages.each do |msg| | |
19 | + %li= msg | |
20 | + | |
21 | + | |
22 | + .control-group | |
23 | + = f.label :active, "Active", class: "control-label" | |
24 | + .controls | |
25 | + = f.check_box :active | |
26 | + | |
27 | + .control-group | |
28 | + = f.label :active, "Project URL", class: "control-label" | |
29 | + .controls | |
30 | + = f.text_field :project_url, class: "input-xlarge", placeholder: "http://ci.gitlabhq.com/projects/3" | |
31 | + | |
32 | + .control-group | |
33 | + = f.label :token, class: "control-label" do | |
34 | + CI Project token | |
35 | + .controls | |
36 | + = f.text_field :token, class: "input-xlarge", placeholder: "GitLab CI project specific token" | |
37 | + | |
38 | + | |
39 | + .form-actions | |
40 | + = f.submit 'Save', class: 'btn save-btn' | |
41 | + | |
42 | + = link_to 'Test settings', test_project_service_path(@project), class: 'btn btn-small' | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | += render "projects/project_head" | |
2 | +%h3.page_title Services | |
3 | +%hr | |
4 | + | |
5 | +.row | |
6 | + .span6 | |
7 | + .padded | |
8 | + %p.slead Continuous integration server from GitLab | |
9 | + .thumbnail.left | |
10 | + = link_to edit_project_service_path(@project, :gitlab_ci) do | |
11 | + - if @gitlab_ci_service.try :active | |
12 | + = image_tag 'service-gitlab-ci.png' | |
13 | + - else | |
14 | + = image_tag 'service-disabled-gitlab-ci.png' | |
15 | + | ... | ... |
config/routes.rb
... | ... | @@ -133,6 +133,12 @@ Gitlab::Application.routes.draw do |
133 | 133 | end |
134 | 134 | end |
135 | 135 | |
136 | + resources :services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do | |
137 | + member do | |
138 | + get :test | |
139 | + end | |
140 | + end | |
141 | + | |
136 | 142 | resources :deploy_keys |
137 | 143 | resources :protected_branches, only: [:index, :create, :destroy] |
138 | 144 | ... | ... |
db/schema.rb
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | # |
12 | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | |
14 | -ActiveRecord::Schema.define(:version => 20121120051432) do | |
14 | +ActiveRecord::Schema.define(:version => 20121120113838) do | |
15 | 15 | |
16 | 16 | create_table "events", :force => true do |t| |
17 | 17 | t.string "target_type" |
... | ... | @@ -131,9 +131,11 @@ ActiveRecord::Schema.define(:version => 20121120051432) do |
131 | 131 | t.string "type" |
132 | 132 | t.string "title" |
133 | 133 | t.string "token" |
134 | - t.integer "project_id", :null => false | |
135 | - t.datetime "created_at", :null => false | |
136 | - t.datetime "updated_at", :null => false | |
134 | + t.integer "project_id", :null => false | |
135 | + t.datetime "created_at", :null => false | |
136 | + t.datetime "updated_at", :null => false | |
137 | + t.boolean "active", :default => false, :null => false | |
138 | + t.string "project_url" | |
137 | 139 | end |
138 | 140 | |
139 | 141 | create_table "snippets", :force => true do |t| | ... | ... |