Permalink
Browse files

Add systems table and associate it with projects

Because there are multiple defect systems. Only origin_id won't be
enough to identify a defect. So introduce system to the concept.

Change-Id: Ib2bbcead7828abc4154fb42533bc430a4f8c75fe
  • Loading branch information...
leoli committed Jan 22, 2013
1 parent 711cf40 commit 78ba4f32e778d9dd27c927612b8adf975bc05582
View
@@ -1,9 +1,11 @@
---
pivotal:
-- site_url: 'https://www.pivotaltracker.com/'
+ type: pivotaltracker
+ site_url: 'https://www.pivotaltracker.com/'
token: token
-jira:
-- site_url: 'https://cloudfoundry.atlassian.net'
+cf_public_jira:
+ type: jira
+ site_url: 'https://cloudfoundry.atlassian.net'
username: user
password: password
@@ -0,0 +1,24 @@
+class AddSystem < ActiveRecord::Migration
+
+ def self.up
+
+ create_table :systems do |t|
+ t.string :system_type
+ t.string :name, :unique => true
+ t.string :url
+ t.timestamps
+ end
+
+ add_column :projects, :system_id, :int
+ change_column :projects, :origin_id, :int
+
+ end
+
+ def self.down
+ change_column :projects, :origin_id, :int, :unique => true
+ remove_column :projects, :system_id
+ drop_table :systems
+ end
+
+end
+
View
@@ -14,6 +14,7 @@
require File.join( File.dirname(__FILE__), "defekts/models", "defekt" )
require File.join( File.dirname(__FILE__), "defekts/models", "project" )
require File.join( File.dirname(__FILE__), "defekts/models", "projectdefekt" )
+require File.join( File.dirname(__FILE__), "defekts/models", "system" )
module Defekts
@@ -49,6 +49,34 @@ def self.get_severity
end
+ def self.sync_defkets(config, force=false)
+ if Defekts.check_synced && !force
+ return
+ end
+ config.keys.each do |site_name|
+ system_config = config[site_name]
+ system = sync_defekts_system(site_name, system_config)
+ case system.system_type
+ when 'pivotaltracker'
+ PivotalHelper.sync(system, system_config, false)
+ when 'jira'
+ JiraHelper.sync(system, system_config, false)
+ end
+ end
+ end
+
+ def self.sync_defekts_system(site_name, system_config)
+ system = System.find_by_name(site_name)
+ if system.nil?
+ system = System.create(
+ :system_type => system_config['type'],
+ :name => site_name,
+ :url => system_config['site_url']
+ )
+ end
+ system
+ end
+
end
end
View
@@ -6,29 +6,29 @@ module Defekts
module JiraHelper
- def self.sync(force=false, site_url, username, password)
- if Defekts.check_synced and !force
- return
- end
+ def self.sync(system, system_config, force=false)
options = {
- :site => site_url,
- :username => username,
- :password => password,
+ :site => system.url,
+ :username => system_config['username'],
+ :password => system_config['password'],
:context_path => '',
:auth_type => :basic
}
client = JIRA::Client.new(options)
@projects = client.Project.all
@projects.each do |p|
- project = Project.find_by_origin_id(p.id)
+ project = Project.find_by_origin_id_and_system_id(p.id, system.id)
if project.nil?
- project = Project.create(:name => p.name, :origin_id => p.id)
+ project = Project.create(
+ :name => p.name,
+ :origin_id => p.id,
+ :system_id => system.id)
end
@defeckts = p.issues
@defeckts.each do |d|
severity = d.priority.id
- defekt = Defekt.find_by_origin_id d.id
+ defekt = Defekt.find_by_origin_id_and_project_id(d.id, project.id)
if defekt.nil?
ndefekt = Defekt.create(
:project_id => project.id,
@@ -41,7 +41,8 @@ def self.sync(force=false, site_url, username, password)
:state => d.status.name,
:severity => severity,
:owner => d.assignee.displayName,
- :reporter => d.reporter.displayName
+ :reporter => d.reporter.displayName,
+ :project_id => project.id
)
else
defekt.title = d.summary
@@ -8,5 +8,4 @@ def set_day
self.day = self.creation.to_date
end
-end
-
+end
@@ -1,5 +1,6 @@
class Project < ActiveRecord::Base
has_many :defekts
+ belongs_to :systems
end
@@ -0,0 +1,4 @@
+class System < ActiveRecord::Base
+ has_many :projects
+end
+
@@ -17,25 +17,21 @@ def self.get_severity(labels)
end
- def self.sync(force=false, token)
-
- if Defekts.check_synced and !force
- return
- end
-
- PivotalTracker::Client.token = token
+ def self.sync(system, system_config, force=false)
+ PivotalTracker::Client.token = system_config['token']
@projects = PivotalTracker::Project.all
@projects.each do |p|
- project = Project.find_by_origin_id(p.id)
+ project = Project.find_by_origin_id_and_system_id(p.id, system.id)
if project.nil?
project = Project.create(
:name => p.name,
- :origin_id => p.id )
+ :origin_id => p.id,
+ :system_id => system.id)
end
@@ -45,7 +41,7 @@ def self.sync(force=false, token)
severity = get_severity(d.labels)
- defekt = Defekt.find_by_origin_id(d.id)
+ defekt = Defekt.find_by_origin_id_and_project_id(d.id, project.id)
if defekt.nil?
@@ -59,7 +55,8 @@ def self.sync(force=false, token)
:state => d.current_state,
:severity => severity,
:owner => d.owned_by,
- :reporter => d.requested_by )
+ :reporter => d.requested_by,
+ :project_id => project.id )
else
View
@@ -6,17 +6,7 @@ module Defekts
get "/" do
defekt_config = settings.defekt_config
- # need to change this to more generic way once class pattern is redefined.
- if !defekt_config['pivotal'].nil?
- defekt_config['pivotal'].each do |site|
- PivotalHelper.sync(false, site['token'])
- end
- end
- if !defekt_config['jira'].nil?
- defekt_config['jira'].each do |site|
- JiraHelper.sync(false, site['site_url'], site['username'], site['password'])
- end
- end
+ Analysis.sync_defkets defekt_config
#p = Project.create( :name => "frameworks", :origin_id => "72352" )
#po = Project.find_by_origin_id("72351")

0 comments on commit 78ba4f3

Please sign in to comment.