Last active
January 21, 2018 03:14
-
-
Save mavimo/d764488ec2b791e83dae to your computer and use it in GitHub Desktop.
phpci-gitlab-integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/models/project.rb b/app/models/project.rb | |
index 3391431..e88c73e 100644 | |
--- a/app/models/project.rb | |
+++ b/app/models/project.rb | |
@@ -55,6 +55,7 @@ class Project < ActiveRecord::Base | |
# Project services | |
has_many :services | |
has_one :gitlab_ci_service, dependent: :destroy | |
+ has_one :phpci_ci_service, dependent: :destroy | |
has_one :campfire_service, dependent: :destroy | |
has_one :emails_on_push_service, dependent: :destroy | |
has_one :pivotaltracker_service, dependent: :destroy | |
@@ -312,13 +313,17 @@ class Project < ActiveRecord::Base | |
end | |
def available_services_names | |
- %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack) | |
+ %w(gitlab_ci phpci_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack) | |
end | |
def gitlab_ci? | |
gitlab_ci_service && gitlab_ci_service.active | |
end | |
+ def phpci_ci? | |
+ phpci_ci_service && phpci_ci_service.active | |
+ end | |
+ | |
def ci_services | |
services.select { |service| service.category == :ci } | |
end | |
diff --git a/app/models/project_services/phpci_ci_service.rb b/app/models/project_services/phpci_ci_service.rb | |
new file mode 100644 | |
index 0000000..cd378bb | |
--- /dev/null | |
+++ b/app/models/project_services/phpci_ci_service.rb | |
@@ -0,0 +1,92 @@ | |
+# == Schema Information | |
+# | |
+# Table name: services | |
+# | |
+# id :integer not null, primary key | |
+# type :string(255) | |
+# title :string(255) | |
+# token :string(255) | |
+# project_id :integer not null | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# active :boolean default(FALSE), not null | |
+# project_url :string(255) | |
+# subdomain :string(255) | |
+# room :string(255) | |
+# recipients :text | |
+# api_key :string(255) | |
+# | |
+ | |
+class PhpciCiService < CiService | |
+ validates :project_url, presence: true, if: :activated? | |
+ validates :token, presence: true, if: :activated? | |
+ | |
+ delegate :execute, to: :service_hook, prefix: nil | |
+ | |
+ after_save :compose_service_hook, if: :activated? | |
+ | |
+ def compose_service_hook | |
+ hook = service_hook || build_service_hook | |
+ hook.url = [project_url, "/build-status/", "?token=#{token}"].join("") | |
+ hook.save | |
+ end | |
+ | |
+ def commit_status_path sha | |
+ phpci_servername + "/build-status/status/#{phpci_projectid}/#{sha}?auth_token=#{token}" | |
+ end | |
+ | |
+ def commit_status sha | |
+ response = HTTParty.get(commit_status_path(sha), verify: false) | |
+ | |
+ if response.code == 200 and response["status"] | |
+ response["status"] | |
+ else | |
+ :error | |
+ end | |
+ end | |
+ | |
+ def build_page sha | |
+ response = HTTParty.get(commit_status_path(sha), verify: false) | |
+ | |
+ if response.code == 200 and response["status"] | |
+ build_id = response["id"] | |
+ end | |
+ | |
+ phpci_servername + "/build/view/#{build_id}" | |
+ end | |
+ | |
+ def builds_path | |
+ project_url | |
+ end | |
+ | |
+ def status_img_path | |
+ phpci_servername + "/build-status/image/" + phpci_projectid | |
+ end | |
+ | |
+ def title | |
+ 'PHPCI' | |
+ end | |
+ | |
+ def description | |
+ 'Continuous integration server for PHP Projects.' | |
+ end | |
+ | |
+ def to_param | |
+ 'phpci_ci' | |
+ end | |
+ | |
+ def fields | |
+ [ | |
+ { type: 'text', name: 'token', placeholder: 'PHPCI project specific token' }, | |
+ { type: 'text', name: 'project_url', placeholder: 'http://phpci.com/project/view/3'} | |
+ ] | |
+ end | |
+ | |
+ def phpci_projectid | |
+ project_url.split('/').last | |
+ end | |
+ | |
+ def phpci_servername | |
+ project_url.split('/').reverse.drop(3).reverse.join('/') | |
+ end | |
+end | |
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml | |
index c4e5087..204ce38 100644 | |
--- a/app/views/projects/show.html.haml | |
+++ b/app/views/projects/show.html.haml | |
@@ -66,3 +66,9 @@ | |
%hr | |
= link_to @project.gitlab_ci_service.builds_path do | |
= image_tag @project.gitlab_ci_service.status_img_path, alt: "build status" | |
+ | |
+ | |
+ - if @project.phpci_ci? | |
+ %hr | |
+ = link_to @project.phpci_ci_service.builds_path do | |
+ = image_tag @project.phpci_ci_service.status_img_path, alt: "build status" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment