Class: CTodo::Redmine

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ctodo/redmine.rb

Overview

needs Redmine 1.1 at least

Instance Method Summary collapse

Constructor Details

#initialize(conf, prefix = 'red') ⇒ Redmine

Returns a new instance of Redmine.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ctodo/redmine.rb', line 7

def initialize(conf, prefix = 'red')
	red_uri = conf[:"#{prefix}_uri"]
	red_key = conf[:"#{prefix}_key"]
	@enabled = (!red_uri.nil? and !red_key.nil?)
	if @enabled
		self.class.base_uri(red_uri)
		rand_pwd = (0...8).map {65.+(rand(25)).chr}.join
		self.class.basic_auth(red_key, rand_pwd)
		dir = [:git_repo_dir, :hg_repo_dir, :cur_dir].map {|k| conf[k]}.select {|v| not v.nil?}.first
		@repo = File.basename(dir)
		# HACK: 1000 should really be enough
		@limit = (conf[:all] ? 1000 : 25)
	end
end

Instance Method Details

#find_id_for_identifier(projects, ident) ⇒ Object



54
55
56
57
58
59
# File 'lib/ctodo/redmine.rb', line 54

def find_id_for_identifier(projects, ident)
	projects.each do |p|
		return p['id'] if ident == p['identifier']
	end
	nil
end

#get_issues(issues) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ctodo/redmine.rb', line 22

def get_issues(issues)
	return if not @enabled
	
	# all projects
	r = self.class.get "/projects.json"
	return if r.code != 200
	
	# get id for matching project identifier (not name!)
	p_id = find_id_for_identifier(r['projects'], @repo)
	return if p_id == nil
	
	r = self.class.get "/issues.json", :query => {:project_id => p_id, :offset => 0, :limit => @limit}
	
	r['issues'].each do |i|
		loc = "#{self.class.base_uri}/issues/#{i['id']}"
		if i['assigned_to'].nil?
			assig = nil
		else
			assig = i['assigned_to']['name']
			# BUG: missing login attribute in API, http://www.redmine.org/projects/redmine/wiki/Rest_Users
			#u_id = i['assigned_to']['id']
			#r2 = self.class.get "/users/#{u_id}.xml"
			#assig = r2['user']['login']
		end
		tags = []
		tags << Tag.new(i['tracker']['name'], "ffffff") if not i['tracker'].nil?
		tags << Tag.new(i['category']['name'], ColorUtils.rgb4string(i['category']['name'])) if not i['category'].nil?
		tags << Tag.new(i['fixed_version']['name'], "000000") if not i['fixed_version'].nil?
		issues << Issue.new(i['subject'], loc, assig, tags)
	end
end