hamster-pivotal 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/bin/hamster-pivotal +32 -0
- data/lib/pivotal.rb +4 -0
- data/lib/pivotal/connection.rb +30 -0
- data/lib/pivotal/entry.rb +61 -0
- metadata +62 -0
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
README.md
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/hamster-pivotal
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
3
|
+
require 'pivotal'
|
4
|
+
|
5
|
+
required_env_vars = [ 'PIVOTAL_EMAIL',
|
6
|
+
'PIVOTAL_PASSWORD',
|
7
|
+
'PIVOTAL_PERSON_ID',
|
8
|
+
'PIVOTAL_PROJECT_ID' ]
|
9
|
+
|
10
|
+
usage = <<-eos
|
11
|
+
Import your Hamster time entries into pivotal tracker.
|
12
|
+
|
13
|
+
hamster-pivotal dry-run export.tsv
|
14
|
+
|
15
|
+
Make sure your stories are read properly.
|
16
|
+
|
17
|
+
hamster-pivotal submit export.tsv
|
18
|
+
|
19
|
+
Import time entries from export.tsv to PivotalTracker
|
20
|
+
eos
|
21
|
+
|
22
|
+
abort usage if ARGV.length < 2
|
23
|
+
|
24
|
+
env_variables = "Please make sure the following environment variables are configured properly: #{required_env_vars.join(', ')}."
|
25
|
+
abort env_variables if required_env_vars.any?{|x| ENV[x].nil?}
|
26
|
+
|
27
|
+
case ARGV[0]
|
28
|
+
when 'dry-run'
|
29
|
+
Pivotal::Entry.dry_run(ARGV[1])
|
30
|
+
when 'submit'
|
31
|
+
Pivotal::Entry.upload_to_pivotal(ARGV[1])
|
32
|
+
end
|
data/lib/pivotal.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Pivotal
|
4
|
+
class Connection
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
HOST = 'https://www.pivotaltracker.com'
|
8
|
+
EMAIL = ENV['PIVOTAL_EMAIL']
|
9
|
+
PASSWORD = ENV['PIVOTAL_PASSWORD']
|
10
|
+
PERSON_ID = ENV['PIVOTAL_PERSON_ID']
|
11
|
+
PROJECT_ID = ENV['PIVOTAL_PROJECT_ID']
|
12
|
+
COOKIE_FILE = 'pivotal_session.txt'
|
13
|
+
|
14
|
+
attr_accessor :email, :password, :logged_in
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@logged_in = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def login
|
21
|
+
`curl -c #{COOKIE_FILE} -d 'credentials[username]=#{EMAIL}&credentials[password]=#{PASSWORD}' #{HOST}/signin` unless @logged_in
|
22
|
+
@logged_in = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def post_form(data, path)
|
26
|
+
login unless @logged_in
|
27
|
+
`curl -b #{COOKIE_FILE} -c #{COOKIE_FILE} -d '#{data}' #{HOST}/#{path}`
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pivotal
|
4
|
+
class Entry
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def upload_to_pivotal(file)
|
8
|
+
entries_from_hamster_tsv_export(file).map(&:post)
|
9
|
+
end
|
10
|
+
|
11
|
+
def dry_run(file)
|
12
|
+
entries_from_hamster_tsv_export(file).map(&:pretty_print)
|
13
|
+
end
|
14
|
+
|
15
|
+
def entries_from_hamster_tsv_export(file)
|
16
|
+
entries = []
|
17
|
+
File.read(file).lines.each do |line|
|
18
|
+
next if line =~ /^activity/
|
19
|
+
entries << Entry.from_hamster_tsv_line(line)
|
20
|
+
end
|
21
|
+
entries
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_hamster_tsv_line(line)
|
25
|
+
parts = line.split("\t")
|
26
|
+
entry = new
|
27
|
+
entry.start = DateTime.parse(parts[1])
|
28
|
+
entry.end = DateTime.parse(parts[2])
|
29
|
+
entry.description = parts[5]
|
30
|
+
entry
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_accessor :start, :end, :description
|
35
|
+
|
36
|
+
def invoice_time
|
37
|
+
(((@end.to_time.to_i - @start.to_time.to_i) / 60) / 60.0).round(2)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Round to increments of half hours
|
41
|
+
def pivotal_time(fraction=0.5)
|
42
|
+
multiplier = 1.0 / fraction
|
43
|
+
val = (multiplier*invoice_time).round / multiplier
|
44
|
+
val = 0.5 if val == 0
|
45
|
+
val
|
46
|
+
end
|
47
|
+
|
48
|
+
# Make pivotal happy with the specified date format
|
49
|
+
def pivotal_date
|
50
|
+
@start.strftime("%m/%d/%Y")
|
51
|
+
end
|
52
|
+
|
53
|
+
def post
|
54
|
+
Connection.instance.post_form("shift[person_id]=#{Connection::PERSON_ID}&shift[project_id]=#{Connection::PROJECT_ID}&shift[date]=#{self.pivotal_date}&shift[hours]=#{self.pivotal_time}&shift[description]=#{self.description}&commit=Save", "/time_shifts")
|
55
|
+
end
|
56
|
+
|
57
|
+
def pretty_print
|
58
|
+
puts "#{self.pivotal_date} ::: #{self.description} ::: #{self.pivotal_time}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hamster-pivotal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Huckabee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-02 00:00:00 -07:00
|
14
|
+
default_executable: hamster-pivotal
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: hamster-pivotal allows you to automate the process of importing your Hamster time entries into Pivotal Tracker
|
18
|
+
email: joshhuckabee@gmail.com
|
19
|
+
executables:
|
20
|
+
- hamster-pivotal
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- README
|
27
|
+
- UNLICENSE
|
28
|
+
- VERSION
|
29
|
+
- bin/hamster-pivotal
|
30
|
+
- lib/pivotal/connection.rb
|
31
|
+
- lib/pivotal/entry.rb
|
32
|
+
- lib/pivotal.rb
|
33
|
+
has_rdoc: false
|
34
|
+
homepage: http://github.com/jhuckabee/hamster-pivotal
|
35
|
+
licenses:
|
36
|
+
- Public Domain
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.7
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.6.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Import your Hamster time entries into Pivotal Tracker
|
61
|
+
test_files: []
|
62
|
+
|