-
Notifications
You must be signed in to change notification settings - Fork 6
/
gh2ptissues.rb
100 lines (73 loc) · 2.79 KB
/
gh2ptissues.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
#!/usr/bin/env ruby
# Description: Migrates GitHub Issues to Pivotal Tracker.
GITHUB_ORG = 'APX'
GITHUB_USER = 'shyam-habarakada'
GITHUB_REPO = 'APX/benchpress-server'
GITHUB_LOGIN = 'shyam-habarakada'
PIVOTAL_PROJECT_ID = 836893
PIVOTAL_PROJECT_USE_SSL = true
GITHUB_PASSWORD = ENV['GITHUB_PASSWORD']
PIVOTAL_TOKEN = ENV['PIVOTAL_TOKEN'].to_s unless ENV['PIVOTAL_TOKEN'].nil?
require 'rubygems'
require 'octokit'
require 'pivotal-tracker'
require 'json'
# uncomment to debug
# require 'net-http-spy'
# puts ENV['GITHUB_PASSWORD']
# puts ENV['PIVOTAL_TOKEN']
dry_run = true
begin
PivotalTracker::Client.token = PIVOTAL_TOKEN
PivotalTracker::Client.use_ssl = PIVOTAL_PROJECT_USE_SSL
pivotal_project = nil
pivotal_project = PivotalTracker::Project.find(PIVOTAL_PROJECT_ID)
github = Octokit::Client.new(:login => GITHUB_LOGIN, :password => GITHUB_PASSWORD)
issues_filter = 'bug' # update filter as appropriate
story_type = 'bug' # 'bug', 'feature', 'chore', 'release'. Omitting makes it a feature.
story_current_state = 'unscheduled' # 'unscheduled', 'started', 'accepted', 'delivered', 'finished', 'unscheduled'.
# 'unstarted' puts it in 'Current' if Commit Mode is on; 'Backlog' if Auto Mode is on.
# Omitting puts it in the Icebox.
total_issues = 0
page_issues = 1
issues = github.list_issues(GITHUB_REPO, { :page => page_issues, :labels => issues_filter } )
while issues.count > 0
issues.each do |issue|
total_issues += 1
comments = github.issue_comments(GITHUB_REPO, issue.number)
labels = 'github-import'
issue.labels.each do |l|
labels += ",#{l.name}"
end
puts "issue: #{issue.number} #{issue.title}, with #{comments.count} comments"
unless dry_run
story = pivotal_project.stories.create(
:name => issue.title,
:description => issue.body,
:created_at => issue.created_at,
:labels => labels,
:story_type => story_type,
:current_state => story_current_state
)
story.notes.create(
text: "Migrated from #{issue.html_url}",
)
comments.each do |comment|
story.notes.create(
text: comment.body.gsub(/\r\n\r\n/, "\n\n"),
author: comment.user.login,
noted_at: comment.created_at
)
end
github.add_comment(GITHUB_REPO, issue.number, "Migrated to pivotal tracker #{story.url}")
github.close_issue(GITHUB_REPO, issue.number)
end
end
page_issues += 1
issues = github.list_issues(GITHUB_REPO, { :page => page_issues, :labels => issues_filter } )
end
puts "\n== processed #{total_issues} issues"
rescue StandardError => se
puts se.message
exit 1
end