diff --git a/Gemfile b/Gemfile
index 5b55ef1..67b13d0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1 +1,2 @@
gem 'gitlab', '~> 3.1.0'
+gem 'jenkins_api_client', '~> 0.14.1'
diff --git a/lib/ext/community.rb b/lib/ext/community.rb
index caadf98..14fbb20 100644
--- a/lib/ext/community.rb
+++ b/lib/ext/community.rb
@@ -1,6 +1,4 @@
require_dependency 'community'
-require 'gitlab'
-#require 'jenkins_api_client'
class Community
@@ -13,11 +11,16 @@ class Community
attr_accessible :allow_unauthenticated_comments, :allow_gitlab_integration, :gitlab, :allow_sonar_integration, :sonar, :allow_jenkins_integration, :jenkins
- ##########################################
- # Gitlab stuff #
- ##########################################
+ after_update :create_integration_projects
- #after_create :create_gitlab_project
+ def create_integration_projects
+ gitlab_project = SerproIntegrationPlugin::GitlabIntegration.create_gitlab_project(self)
+ SerproIntegrationPlugin::JenkinsIntegration.create_jenkis_project(self, jenkins_project_name, gitlab_project.path_with_namespace, gitlab_project.web_url, gitlab_project.http_url_to_repo)
+ end
+
+ def serpro_integration_plugin_settings
+ @settings ||= Noosfero::Plugin::Settings.new(environment, SerproIntegrationPlugin)
+ end
def gitlab= params
self.serpro_integration_plugin[:gitlab] = params
@@ -27,202 +30,36 @@ class Community
self.serpro_integration_plugin[:gitlab] ||= {}
end
- def serpro_integration_plugin_settings
- @settings ||= Noosfero::Plugin::Settings.new(environment, SerproIntegrationPlugin)
- end
-
- def create_gitlab_project
- Gitlab.endpoint = gitlab_host
- Gitlab.private_token = serpro_integration_plugin_settings.gitlab[:private_token]
-
- #Find user by email
- begin
- gitlab_user = Gitlab.users(:search => gitlab[:email])
- rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing
- gitlab_user = nil
- end
-
- #User not found, create user
- if gitlab_user == nil || gitlab_user.count == 0
- gitlab_user = Gitlab.create_user(user.email, '123456', {:username => user.identifier, :name => user.name, :provider => 'ldap'})
- end
-
- if gitlab_user.nil?
- self.gitlab[:errors] = _('Gitlab user could not be created')
- return nil
- end
-
- #Create project for user
- begin
- #FIXME Why this?
- if gitlab_user.is_a?(Array)
- gitlab_user = gitlab_user[0]
- end
-
- project_options = {}
- project_options[:user_id] = gitlab_user.id
- project_options[:issues_enabled ] = true
- project_options[:wall_enabled] = true
- project_options[:wiki_enabled] = true
- project_options[:public] = true
- project = Gitlab.create_project(gitlab_project_name, project_options)
-
- #Create Web Hook for Jenkins' integration
-# Gitlab.add_project_hook(project.id, "#{self.jenkins[:url]}/gitlab/build_now")
-# createJenkinsJob(project.name, project.path_with_namespace, project.web_url, project.http_url_to_repo)
-
- rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing
- #Project already exists
- end
-
- self.gitlab[:errors] = nil
- end
-
def gitlab_project_name
gitlab[:project_name] || self.identifier
end
- # set an API endpoint
def gitlab_host
serpro_integration_plugin_settings.gitlab[:host]
end
- # set a user private token
def gitlab_private_token
serpro_integration_plugin_settings.gitlab[:private_token]
end
- ##########################################
- # Sonar stuff #
- ##########################################
-
-# after_create :create_sonar_project
-
def sonar= params
self.serpro_integration_plugin[:sonar] = params
end
def sonar
self.serpro_integration_plugin[:sonar] ||= {}
- self.serpro_integration_plugin[:sonar]
end
- ##########################################
- # Jenkins stuff #
- ##########################################
-
-# after_create :create_jenkis_project
-
def jenkins= params
self.serpro_integration_plugin[:jenkins] = params
end
def jenkins
self.serpro_integration_plugin[:jenkins] ||= {}
- url = "#{self.serpro_integration_plugin[:jenkins][:host]}:"
- url += "#{self.serpro_integration_plugin[:jenkins][:port]}/"
- url += "#{self.serpro_integration_plugin[:jenkins][:context_name]}"
- self.serpro_integration_plugin[:jenkins][:url] = url
- self.serpro_integration_plugin[:jenkins]
end
-
- #FIXME make jenkins integration works
- def create_jenkis_project
-#(projectName, repositoryPath, webUrl, gitUrl)
-
- @client = JenkinsApi::Client.new(:server_url => "#{$jenkins_url}/",
- :password => $jenkins_private_token,
- :username => $jenkins_user)
-
- xmlJenkins = ""
-
-# xmlJenkins = "
-#
-#
-# Projeto criado para o repositório #{repositoryPath} do Gitlab - #{webUrl}
-#
-# -1
-# 2
-# -1
-# -1
-#
-# false
-#
-#
-# 2
-#
-#
-# #{gitUrl}
-#
-#
-#
-#
-# */master
-#
-#
-# false
-#
-#
-#
-# true
-# false
-# false
-# false
-# (Inherit From Job)
-#
-# false
-# clean package install deploy
-# true
-# false
-# true
-# false
-# false
-# false
-# false
-# -1
-# false
-# false
-#
-#
-#
-#
-#
-# false
-# true
-# true
-#
-#
-#
-#
-# (Inherit From Job)
-#
-#
-#
-#
-#
-#
-# false
-#
-#
-#
-#
-#
-#
-# FAILURE
-# 2
-# RED
-#
-#
-# "
-
- begin
- @client.job.create(projectName, xmlJenkins)
- rescue JenkinsApi::Exceptions::ApiException
-
- end
-
+ def jenkins_project_name
+ jenkins[:project_name] || self.identifier
end
-
end
diff --git a/lib/serpro_integration_plugin/gitlab_integration.rb b/lib/serpro_integration_plugin/gitlab_integration.rb
new file mode 100644
index 0000000..2a99156
--- /dev/null
+++ b/lib/serpro_integration_plugin/gitlab_integration.rb
@@ -0,0 +1,54 @@
+require 'gitlab'
+
+class SerproIntegrationPlugin::GitlabIntegration
+
+ def self.create_gitlab_project(profile)
+ Gitlab.endpoint = profile.gitlab_host
+ Gitlab.private_token = profile.serpro_integration_plugin_settings.gitlab[:private_token]
+
+ #Find user by email
+ begin
+ gitlab_user = Gitlab.users(:search => profile.gitlab[:email])
+ rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing
+ gitlab_user = nil
+ end
+
+ #User not found, create user
+ #FIXME
+ if gitlab_user == nil || gitlab_user.count == 0
+ gitlab_user = Gitlab.create_user(user.email, '123456', {:username => user.identifier, :name => user.name, :provider => 'ldap'})
+ end
+
+ if gitlab_user.nil?
+ profile.gitlab[:errors] = _('Gitlab user could not be created')
+ return nil
+ end
+
+ #Create project for user
+ begin
+ #FIXME Why this?
+ if gitlab_user.is_a?(Array)
+ gitlab_user = gitlab_user[0]
+ end
+
+ project_options = {}
+ project_options[:user_id] = gitlab_user.id
+ project_options[:issues_enabled ] = true
+ project_options[:wall_enabled] = true
+ project_options[:wiki_enabled] = true
+ project_options[:public] = true
+ project = Gitlab.create_project(profile.gitlab_project_name, project_options)
+
+ #Create Web Hook for Jenkins' integration
+# Gitlab.add_project_hook(project.id, "#{self.jenkins[:url]}/gitlab/build_now")
+# createJenkinsJob(project.name, project.path_with_namespace, project.web_url, project.http_url_to_repo)
+
+ rescue Gitlab::Error::NotFound, Gitlab::Error::Parsing
+ #Project already exists
+ end
+ profile.gitlab[:errors] = nil
+ project
+ end
+
+
+end
diff --git a/lib/serpro_integration_plugin/jenkins_integration.rb b/lib/serpro_integration_plugin/jenkins_integration.rb
new file mode 100644
index 0000000..0a23305
--- /dev/null
+++ b/lib/serpro_integration_plugin/jenkins_integration.rb
@@ -0,0 +1,101 @@
+# encoding: UTF-8
+require 'jenkins_api_client'
+
+class SerproIntegrationPlugin::JenkinsIntegration
+ #FIXME make jenkins integration works
+ def self.create_jenkis_project(profile, projectName, repositoryPath, webUrl, gitUrl)
+
+ @client = JenkinsApi::Client.new(:server_url => profile.serpro_integration_plugin_settings.jenkins[:host],
+ :password => profile.serpro_integration_plugin_settings.jenkins[:private_token],
+ :username => profile.serpro_integration_plugin_settings.jenkins[:user])
+
+ #begin
+ @client.job.create(projectName, xml_jenkins(repositoryPath, webUrl, gitUrl))
+ #rescue JenkinsApi::Exceptions::ApiException
+
+ #end
+
+ end
+
+ #FIXME
+ def self.xml_jenkins(repositoryPath, webUrl, gitUrl)
+ "
+
+
+ Projeto criado para o repositório #{repositoryPath} do Gitlab - #{webUrl}
+
+ -1
+ 2
+ -1
+ -1
+
+ false
+
+
+ 2
+
+
+ #{gitUrl}
+
+
+
+
+ */master
+
+
+ false
+
+
+
+ true
+ false
+ false
+ false
+ (Inherit From Job)
+
+ false
+ clean package install deploy
+ true
+ false
+ true
+ false
+ false
+ false
+ false
+ -1
+ false
+ false
+
+
+
+
+
+ false
+ true
+ true
+
+
+
+
+ (Inherit From Job)
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+ FAILURE
+ 2
+ RED
+
+
+ "
+ end
+end
diff --git a/views/profile-editor-extras.html.erb b/views/profile-editor-extras.html.erb
index e628e9d..8aae89c 100644
--- a/views/profile-editor-extras.html.erb
+++ b/views/profile-editor-extras.html.erb
@@ -20,6 +20,7 @@ jQuery( document ).ready(function( $ ) {
<%= _('Serpro Integration') %>
<%= render :partial => 'gitlab' %>
+ <%= render :partial => 'jenkins' %>
@@ -36,30 +37,4 @@ jQuery( document ).ready(function( $ ) {
-
-
- <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %>
- <%= _('Jenkins Integration') %>
-
-
- -
- <%= labelled_text_field(_('Server Host'), 'profile_data[jenkins][host]', profile.jenkins[:host]) %>
-
- -
- <%= labelled_text_field(_('Server Port'), 'profile_data[jenkins][port]', profile.jenkins[:port]) %>
-
- -
- <%= labelled_text_field(_('Server Context Name'), 'profile_data[jenkins][context_name]', profile.jenkins[:context_name]) %>
-
- -
- <%= labelled_text_field(_('Server User'), 'profile_data[jenkins][user]', profile.jenkins[:user]) %>
-
- -
- <%= labelled_text_field(_('Server Private Token'), 'profile_data[jenkins][private_token]', profile.jenkins[:private_token]) %>
-
- -
- <%= labelled_text_field(_('Server Url'), 'profile_data[jenkins][url]', profile.jenkins[:url], {:disabled => true}) %>
-
-
-
diff --git a/views/profile_editor/_jenkins.html.erb b/views/profile_editor/_jenkins.html.erb
new file mode 100644
index 0000000..5624a31
--- /dev/null
+++ b/views/profile_editor/_jenkins.html.erb
@@ -0,0 +1,11 @@
+
+
+ <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %>
+ <%= _('Jenkins Integration') %>
+
+
+ -
+ <%= labelled_text_field(_('Project Name:'), 'profile_data[jenkins][project_name]', profile.jenkins_project_name ) %>
+
+
+
diff --git a/views/serpro_integration_plugin_admin/index.html.erb b/views/serpro_integration_plugin_admin/index.html.erb
index 8cfa641..fe08779 100644
--- a/views/serpro_integration_plugin_admin/index.html.erb
+++ b/views/serpro_integration_plugin_admin/index.html.erb
@@ -10,6 +10,15 @@
<% end %>
+
+
<%= _('Jenkins Settings')%>
+ <%= f.fields_for :jenkins, OpenStruct.new(@settings.jenkins) do |g| %>
+ <%= labelled_form_field _('Server Host'), g.text_field("host") %>
+ <%= labelled_form_field _('Server User'), g.text_field(:user) %>
+ <%= labelled_form_field _('Private Token'), g.text_field(:private_token) %>
+ <% end %>
+
+
<% button_bar do %>
<%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
<% end %>
--
libgit2 0.21.2