-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit.rb
106 lines (94 loc) · 2.61 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'rubygems'
require 'active_resource'
require 'appscript'
include Appscript
require 'api'
def pull_projects
@redmine_projects = Project.find(:all)
@things_projects = Things.projects.get()
@things_projects_collected = @things_projects.collect {|project| project.name.get()}
@redmine_projects.each do |project|
if @things_projects_collected.index(project.name).nil?
Things.make(:new => :project, :with_properties => {:name => project.name})
end
end
end
def add_things_id_to_issue(id,tid)
issue = Issue.find(id)
issue.custom_field_values = {"1", tid}
if issue.save
puts issue.id
else
puts issue.errors.full_messages
end
end
def pull_issues
@redmine_issues = Issue.find(:all)
@redmine_issues.each do |rs|
begin
tag = Things.tags['issue-id-'+rs.id].to_dos.get
puts "Updating #{rs.subject}"
to_dos = Things.tags['issue-id-'+rs.id].get.to_dos.get
to_do = to_dos[0]
to_do.name.set(rs.subject)
unless rs.description.nil?
notes = rs.description+" #{Issue.site}#{rs.id}"
to_do.notes.set(notes)
end
to_do.project.set(Things.projects[rs.project.name])
to_do.tag_names.set("issue-id-"+rs.id)
rescue
puts "Doesn't exist"
puts "Creating #{rs.subject}"
to_do = Things.make(:new => :to_do, :with_properties =>{
:name => rs.subject
}
)
unless rs.description.nil?
notes = rs.description+" #{Issue.site}#{rs.id}"
to_do.notes.set(notes)
end
to_do.tag_names.set("issue-id-"+rs.id)
to_do.project.set(Things.projects[rs.project.name])
add_things_id_to_issue(rs.id, to_do.object_id)
end
puts rs.status.name
puts rs.id
puts "=-------------------------"
if rs.status.name == "closed"
puts "#{rs.id} should be closed"
to_do.status.set("completed")
end
end
end
def push_issues
puts "Pushing Issues"
to_dos = Things.to_dos.get
to_dos.each do |to_do|
path = to_do.inspect.split('.')
if path[2] == "projects"
else
tags = to_do.tag_names.get
puts tags.gsub("issue-id-","")
issue = Issue.find(tags.gsub("issue-id-",""))
status = to_do.status.get
status = status.to_s
if status == "completed"
puts "should make it complete"
if issue.status.name != "Closed"
issue.status_id = 5
if issue.save
puts issue.id
else
puts issue.errors.full_messages
end
else
puts "It's already closed. Nothing left to do."
end
end
end
end
end
pull_projects
pull_issues
push_issues