Permalink
Browse files

make comment on jira issue when new pull request is created

  • Loading branch information...
1 parent 91364f1 commit d6011e5a4cf444bac715e3fca05f823874c019a6 @chriskite committed Aug 27, 2013
Showing with 42 additions and 10 deletions.
  1. +21 −0 app/models/pull_request.rb
  2. +21 −10 app/models/repo.rb
View
@@ -28,6 +28,19 @@ def sync_with_jira(client)
end
end
+ def comment_on_jira_issue(client)
+ return unless !!jira_issue && jira_issue != ""
+ issue = client.Issue.find(jira_issue)
+ if !!issue
+ comment = issue.comments.build
+ comment_body = "A pull request has been created for this issue: #{url}"
+ if repo.should_provision_nginx
+ comment_body += "\n\nView website: http://#{website}"
+ end
+ comment.save({'body': comment_body})
+ end
+ end
+
def jira_issue
matches = title.match(/[A-Z]+-[0-9]+/)
return "" if matches.nil?
@@ -134,6 +147,14 @@ def build_path
builds_dir.join("#{repo.owner}-#{repo.name}-#{number}")
end
+ def website
+ if !!repo.nginx_template && repo.should_provision_nginx
+ match = repo.nginx_template.match(/server_name (.*);/)
+ return !!match[1] ? match[1].gsub('{{number}}', number) : nil
+ end
+ nil
+ end
+
private
def ensure_builds_dir_exists
View
@@ -21,17 +21,9 @@ class Repo < ActiveRecord::Base
def self.sync_all_with_jira
all.each do |repo|
- options = {
- :username => repo.jira_username,
- :password => repo.jira_password,
- :use_ssl => false,
- :context_path => '/',
- :site => repo.jira_url,
- :auth_type => :basic
- }
-
- client = JIRA::Client.new(options)
+ next unless !!repo.jira_url # skip if this repo isn't configured for jira
+ client = repo.jira_client
begin
repo.pull_requests.each { |pull_request| pull_request.sync_with_jira(client) }
rescue
@@ -57,6 +49,12 @@ def self.sync_all_with_github
if existing_pull.nil?
new_pull = repo.new_pull_from_api(pull)
new_pull.delayed_build
+
+ if !!repo.jira_url
+ # Comment on the jira issue
+ client = repo.jira_client
+ new_pull.comment_on_jira_issue(client)
+ end
else
# If the remote pull request has been updated, save and rebuild
if DateTime.parse(pull.updated_at) > existing_pull.updated_at
@@ -88,6 +86,19 @@ def self.sync_all_with_github
end
end
+ def jira_client
+ options = {
+ :username => jira_username,
+ :password => jira_password,
+ :use_ssl => false,
+ :context_path => '/',
+ :site => jira_url,
+ :auth_type => :basic
+ }
+
+ JIRA::Client.new(options)
+ end
+
def clone_url
"git@github.com:#{owner}/#{name}.git"
end

0 comments on commit d6011e5

Please sign in to comment.