timetrap-redmine 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +2 -4
- data/lib/timetrap-redmine.rb +0 -98
- data/lib/timetrap_redmine/api.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5f6cee22e1012dcc1cf95d22f304fbe8bf9e706
|
4
|
+
data.tar.gz: 33ee86493d9738b420c9ca017d1a466068d6bb03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31111a325d2089ccc08f56e71f09f0f7da398fed4926f1a73f776db59b354d2558d9f0281ea9be6257df1c71a45375776e8ffa86aff45b5d909a285b55c228e7
|
7
|
+
data.tar.gz: 8a547a5e3cde4972b5c781ae6283871b037f7054d4270d413542b5400f83ab579700e4778cca1cffaedf2eaa45b35ee650033d9a2c54ac48b64b36d6b9f09cf1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timetrap-redmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Peschar
|
@@ -15,9 +15,7 @@ email: albert@peschar.net
|
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
|
-
files:
|
19
|
-
- lib/timetrap-redmine.rb
|
20
|
-
- lib/timetrap_redmine/api.rb
|
18
|
+
files: []
|
21
19
|
homepage: http://github.com/apeschar/timetrap-redmine
|
22
20
|
licenses:
|
23
21
|
- MIT
|
data/lib/timetrap-redmine.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require_relative './timetrap_redmine/api'
|
2
|
-
|
3
|
-
class Timetrap::Formatters::Redmine
|
4
|
-
attr_reader :entries
|
5
|
-
|
6
|
-
def initialize(entries)
|
7
|
-
TimetrapRedmine::API::Resource.site = Timetrap::Config['redmine']['url']
|
8
|
-
TimetrapRedmine::API::Resource.user = Timetrap::Config['redmine']['user']
|
9
|
-
TimetrapRedmine::API::Resource.password = Timetrap::Config['redmine']['password']
|
10
|
-
|
11
|
-
@entries = entries
|
12
|
-
@issues = {}
|
13
|
-
end
|
14
|
-
|
15
|
-
def output
|
16
|
-
status = Hash.new(0)
|
17
|
-
entries.each {|e| status[process(e)] += 1}
|
18
|
-
|
19
|
-
STDERR.puts "" if status.length
|
20
|
-
|
21
|
-
STDERR.puts "error unchanged created updated"
|
22
|
-
STDERR.puts "%5d %9d %7d %7d" % [status[:error], status[:unchanged], status[:created], status[:updated]]
|
23
|
-
|
24
|
-
exit
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def process(entry)
|
30
|
-
return unless match = /^([0-9]+)(?:\s+(.+?))?\s*$/.match(entry.note)
|
31
|
-
|
32
|
-
issue_id = match[1]
|
33
|
-
comments = match[2] || ''
|
34
|
-
|
35
|
-
prefix = "[tt #{entry.id}]"
|
36
|
-
|
37
|
-
info = entry.end ? '' : ' (incomplete)'
|
38
|
-
|
39
|
-
time_entry = {
|
40
|
-
:issue_id => issue_id,
|
41
|
-
:comments => "#{prefix}#{info} #{comments}",
|
42
|
-
:spent_on => entry.start.strftime("%Y-%m-%d"),
|
43
|
-
:hours => entry.duration / 3600.0,
|
44
|
-
}
|
45
|
-
|
46
|
-
redmine_entry = find_entry(prefix)
|
47
|
-
|
48
|
-
begin
|
49
|
-
issue = find_issue(issue_id)
|
50
|
-
rescue ActiveResource::ResourceNotFound
|
51
|
-
STDERR.puts "Error: no such issue: #{issue_id}"
|
52
|
-
return :error
|
53
|
-
rescue ActiveResource::ForbiddenAccess
|
54
|
-
STDERR.puts "Error: inaccessible issue: #{issue_id}"
|
55
|
-
return :error
|
56
|
-
end
|
57
|
-
|
58
|
-
if redmine_entry &&
|
59
|
-
redmine_entry.issue.id == time_entry[:issue_id] &&
|
60
|
-
redmine_entry.comments == time_entry[:comments] &&
|
61
|
-
redmine_entry.spent_on == time_entry[:spent_on] &&
|
62
|
-
((redmine_entry.hours || '0.0').to_f - time_entry[:hours]).abs < 0.01
|
63
|
-
operation = :unchanged
|
64
|
-
elsif redmine_entry
|
65
|
-
operation = :updated
|
66
|
-
else
|
67
|
-
operation = :created
|
68
|
-
end
|
69
|
-
|
70
|
-
line = "% 3s %s % 5.2f " % [
|
71
|
-
{:unchanged => '', :updated => 'upd', :created => 'add'}[operation],
|
72
|
-
time_entry[:spent_on],
|
73
|
-
time_entry[:hours]
|
74
|
-
]
|
75
|
-
line += "##{issue.id}: #{issue.subject}"[0, 80 - line.length]
|
76
|
-
STDERR.puts(line)
|
77
|
-
|
78
|
-
unless operation == :unchanged
|
79
|
-
redmine_entry = TimetrapRedmine::API::TimeEntry.new unless redmine_entry
|
80
|
-
redmine_entry.update_attributes(time_entry)
|
81
|
-
end
|
82
|
-
|
83
|
-
return operation
|
84
|
-
end
|
85
|
-
|
86
|
-
def find_entry(prefix)
|
87
|
-
TimetrapRedmine::API::TimeEntry.find(:all, :params => {
|
88
|
-
:f => ['comments', 'user_id'],
|
89
|
-
:op => {:comments => '~', 'user_id' => '='},
|
90
|
-
:v => {:comments => [prefix], 'user_id' => ['me']},
|
91
|
-
:sort => 'id',
|
92
|
-
}).find {|e| e.comments.start_with?(prefix)}
|
93
|
-
end
|
94
|
-
|
95
|
-
def find_issue(issue_id)
|
96
|
-
return @issues[issue_id] ||= TimetrapRedmine::API::Issue.find(issue_id)
|
97
|
-
end
|
98
|
-
end
|
data/lib/timetrap_redmine/api.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_resource'
|
3
|
-
|
4
|
-
module TimetrapRedmine
|
5
|
-
module API
|
6
|
-
class Resource < ActiveResource::Base
|
7
|
-
self.format = ActiveResource::Formats::XmlFormat
|
8
|
-
end
|
9
|
-
|
10
|
-
class Issue < Resource
|
11
|
-
end
|
12
|
-
|
13
|
-
class TimeEntry < Resource
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|