pivotal2github 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/pivotal2github +193 -0
- data/lib/pivotal2github.rb +5 -0
- data/lib/pivotal2github/version.rb +3 -0
- data/pivotal2github.gemspec +29 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d74958a39a57860fbcb025a7131029783fa5a0b9
|
4
|
+
data.tar.gz: 9b614bc823518c3ce2e25d2520de394155c3b586
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94066a57a4b9d7bef962a1e816a5490d3e05c4e171f373662ea0f13eb81a4df23e8af609d6b6295ce16148219c88f855773cc9cface51f0ad078a5f9436a9abe
|
7
|
+
data.tar.gz: 00274eb16a7b41bc0f4e8ce3b1b083bc025771d596c901d0fe9658fcf97ed33aa0366d72ca7a95c0ee7ac25c6d2c72bbce1b20f78d337621c6b5faf92e6ae455
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Julien Letessier
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Julien Letessier
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Pivotal2github
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Install it yourself as:
|
7
|
+
|
8
|
+
$ gem install pivotal2github
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
```
|
13
|
+
Usage: pivotal2github [options]
|
14
|
+
-p, --pivotal-token TOKEN API token for Pivotal Tracker
|
15
|
+
-g, --github-token TOKEN API token for Github
|
16
|
+
-r, --repository REPO Target Github repository
|
17
|
+
-P, --project PROJECT_ID Source Pivotal project ID
|
18
|
+
-h, --help Prints this help
|
19
|
+
```
|
20
|
+
|
21
|
+
- Only imports non-accepted stories.
|
22
|
+
- Adds some metadata to the issues (particularly, link to original PT story).
|
23
|
+
- Doesn't import assignments (but mentions them in the issue).
|
24
|
+
- Any attachements in comments or stories themselves are not imported.
|
25
|
+
- Imports state and estimates as tags, to be "translated" into e.g. Zenhub
|
26
|
+
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mezis/pivotal2github.
|
31
|
+
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
36
|
+
|
data/Rakefile
ADDED
data/bin/pivotal2github
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'tracker_api'
|
5
|
+
require 'octokit'
|
6
|
+
require 'logger'
|
7
|
+
require 'redis'
|
8
|
+
require 'net/http/persistent'
|
9
|
+
require 'optparse'
|
10
|
+
require 'ostruct'
|
11
|
+
require 'pry'
|
12
|
+
|
13
|
+
LOGGER = Logger.new(STDERR)
|
14
|
+
LOGGER.level = Logger::INFO
|
15
|
+
|
16
|
+
# PEOPLE = {}
|
17
|
+
PAGE_SIZE = 20
|
18
|
+
|
19
|
+
|
20
|
+
OPTIONS = OpenStruct.new
|
21
|
+
parser = OptionParser.new do |o|
|
22
|
+
o.on('-p TOKEN', '--pivotal-token TOKEN', 'API token for Pivotal Tracker') do |v|
|
23
|
+
OPTIONS.pt_token = v
|
24
|
+
end
|
25
|
+
|
26
|
+
o.on('-g TOKEN', '--github-token TOKEN', 'API token for Github') do |v|
|
27
|
+
OPTIONS.gh_token = v
|
28
|
+
end
|
29
|
+
|
30
|
+
o.on('-r REPO', '--repository REPO', 'Target Github repository') do |v|
|
31
|
+
OPTIONS.repo = v
|
32
|
+
end
|
33
|
+
|
34
|
+
o.on('-P PROJECT_ID', '--project PROJECT_ID', 'Source Pivotal project ID') do |v|
|
35
|
+
OPTIONS.project_id = v
|
36
|
+
end
|
37
|
+
|
38
|
+
o.on("-h", "--help", "Prints this help") do
|
39
|
+
puts o
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
parser.parse! ARGV
|
44
|
+
|
45
|
+
|
46
|
+
STACK = Faraday::RackBuilder.new do |builder|
|
47
|
+
# builder.response :logger
|
48
|
+
builder.use Octokit::Response::RaiseError
|
49
|
+
builder.adapter :net_http_persistent
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
module Helpers
|
54
|
+
def render_person(person)
|
55
|
+
return "None" if person.nil?
|
56
|
+
"[#{person.name}](#{person.email})"
|
57
|
+
end
|
58
|
+
|
59
|
+
def render_people(people)
|
60
|
+
return "None" if people.nil? || people.empty?
|
61
|
+
people.map { |p| render_person(p) }.join(', ')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
class PersonCache
|
67
|
+
def self.get(project, id)
|
68
|
+
all(project)[id]
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def self.all(project)
|
74
|
+
@_all ||= Hash.new.tap do |h|
|
75
|
+
project.memberships.map(&:person).each do |p|
|
76
|
+
h[p.id] = p
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
class Story
|
84
|
+
def initialize(project, story)
|
85
|
+
@project = project
|
86
|
+
@story = story
|
87
|
+
end
|
88
|
+
|
89
|
+
def push(client, repo)
|
90
|
+
# return if old?
|
91
|
+
LOGGER.info "pushing story #{@story.id}"
|
92
|
+
|
93
|
+
issue = client.create_issue(repo, @story.name, body, labels: labels)
|
94
|
+
|
95
|
+
if closed?
|
96
|
+
LOGGER.info "closing issue for story #{@story.id}"
|
97
|
+
client.close_issue(repo, issue.number)
|
98
|
+
end
|
99
|
+
|
100
|
+
comments.each do |c|
|
101
|
+
LOGGER.info "pushing comment for story #{@story.id}"
|
102
|
+
c.push(client, repo, issue.number)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
include Helpers
|
108
|
+
|
109
|
+
def comments
|
110
|
+
@story.comments.map { |c| Comment.new(@project ,c) }
|
111
|
+
end
|
112
|
+
|
113
|
+
def requester
|
114
|
+
PersonCache.get(@project, @story.requested_by_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
def owners
|
118
|
+
@story.owner_ids.map { |id| PersonCache.get(@project, id) }
|
119
|
+
end
|
120
|
+
|
121
|
+
def closed?
|
122
|
+
@story.current_state == 'accepted'
|
123
|
+
end
|
124
|
+
|
125
|
+
def labels
|
126
|
+
[ @story.labels.map(&:name),
|
127
|
+
"state:#{@story.current_state}",
|
128
|
+
"type:#{@story.story_type}",
|
129
|
+
@story.estimate && "estimate:#{@story.estimate.to_i}",
|
130
|
+
].flatten.compact
|
131
|
+
end
|
132
|
+
|
133
|
+
def meta_s
|
134
|
+
[ "Original Story: [#{@story.id}](#{@story.url})",
|
135
|
+
"Requester: #{render_person requester}",
|
136
|
+
"Created on: #{@story.created_at.strftime '%F'}",
|
137
|
+
"Owners: #{render_people owners}",
|
138
|
+
@story.accepted_at && "Accepted on: #{@story.accepted_at.strftime '%F'}",
|
139
|
+
].compact.map { |s| "- #{s}" }
|
140
|
+
end
|
141
|
+
|
142
|
+
def body
|
143
|
+
"#{@story.description}\n\n------\n\n#{meta_s.join "\n"}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
class Comment
|
149
|
+
def initialize(project, comment)
|
150
|
+
@project = project
|
151
|
+
@comment = comment
|
152
|
+
end
|
153
|
+
|
154
|
+
def push(client, repo, issue_number)
|
155
|
+
client.add_comment(repo, issue_number, body)
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
include Helpers
|
160
|
+
|
161
|
+
def body
|
162
|
+
"#{@comment.text}\n\n#{footer}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def footer
|
166
|
+
[ '—',
|
167
|
+
@comment.person_id && render_person(PersonCache.get(@project, @comment.person_id)),
|
168
|
+
"on #{@comment.created_at.strftime '%F'}"
|
169
|
+
].compact.join(' ')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def pt_client
|
175
|
+
Thread.current[:pt_client] ||= TrackerApi::Client.new(token: OPTIONS.pt_token, logger: LOGGER, adapter: :net_http_persistent)
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
def gh_client
|
180
|
+
Thread.current[:gh_client] ||= Octokit::Client.new(access_token: OPTIONS.gh_token, middleware: STACK)
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
project = pt_client.project(OPTIONS.project_id)
|
185
|
+
|
186
|
+
offset = 0
|
187
|
+
while true
|
188
|
+
stories = project.stories(limit: PAGE_SIZE, offset: offset, auto_paginate: false, filter: '-state:accepted')
|
189
|
+
break if stories.empty?
|
190
|
+
stories.map { |s| Story.new(project, s) }.each { |s| s.push(gh_client, OPTIONS.repo) }
|
191
|
+
offset += PAGE_SIZE
|
192
|
+
end
|
193
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pivotal2github/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pivotal2github'
|
8
|
+
spec.version = Pivotal2github::VERSION
|
9
|
+
spec.authors = ['Julien Letessier']
|
10
|
+
spec.email = ['julien.letessier@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Import Pivotal Tracker stories into Github Issues}
|
13
|
+
spec.homepage = 'https://github.com/mezis/pivotal2github'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'bin'
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'tracker_api'
|
27
|
+
spec.add_runtime_dependency 'octokit'
|
28
|
+
spec.add_runtime_dependency 'net-http-persistent'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pivotal2github
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julien Letessier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tracker_api
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: octokit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: net-http-persistent
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- julien.letessier@gmail.com
|
114
|
+
executables:
|
115
|
+
- pivotal2github
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/pivotal2github
|
128
|
+
- lib/pivotal2github.rb
|
129
|
+
- lib/pivotal2github/version.rb
|
130
|
+
- pivotal2github.gemspec
|
131
|
+
homepage: https://github.com/mezis/pivotal2github
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.5
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Import Pivotal Tracker stories into Github Issues
|
155
|
+
test_files: []
|
156
|
+
has_rdoc:
|