Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ gem 'backports'
gem 'octokit'
gem 'rubyzip'
gem 'json_pure'
gem 'args_parser'

2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.3.3)
args_parser (0.2.0)
backports (3.1.1)
faraday (0.8.7)
multipart-post (~> 1.1)
Expand All @@ -25,6 +26,7 @@ PLATFORMS
ruby

DEPENDENCIES
args_parser
backports
json_pure
octokit
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
Export issues from a Github repository to the [Bitbucket
Issue Data Format](https://confluence.atlassian.com/display/BITBUCKET/Export+or+Import+Issue+Data)
Export issues from a Github repository to the
[Bitbucket Issue Data Format](https://confluence.atlassian.com/display/BITBUCKET/Export+or+Import+Issue+Data)

## CLI Options
```
options:
-repository Repository username/reponame
-username (-u) Github login
-password (-p) Github password
-filename (-o) Output file name (default is ./export.zip) : default - export.zip
-prskip Skip exporting pull requests
-help (-h) Show help
```

## Usage

```
bundle install
bundle exec ruby cli.rb githubuser/repo username password exportfilename.zip
bundle exec ruby cli.rb -repository user/repo -username user -password *** -filename out.zip
```
29 changes: 17 additions & 12 deletions cli.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
require './lib/github-to-bitbucket-issues'
require 'args_parser'

if ARGV.size <= 2
options = {
:repository => ARGV[0],
:filename => ARGV[1] || "export.zip"
}
else
options = {
:repository => ARGV[0],
:username => ARGV[1],
:password => ARGV[2],
:filename => ARGV[3] || "export.zip"
}
options = ArgsParser.parse ARGV do
arg :repository, 'Repository username/reponame'
arg :username, 'Github login', :alias => :u
arg :password, 'Github password', :alias => :p
arg :filename, 'Output file name (default is ./export.zip)', :alias => :o, :default => 'export.zip'
arg :prskip, 'Skip exporting pull requests'
arg :help, 'Show help', :alias => :h

validate :repository, "Invalid repository path" do |r|
r =~ /^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+$/
end
end

if options.has_option? :help or !options.has_param?(:repository, :username, :password)
STDERR.puts options.help
exit 1
end

GTBI::Export.new(options).generate
Expand Down
19 changes: 11 additions & 8 deletions lib/github-to-bitbucket-issues/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(options)
})
@repository = options[:repository]
@filename = options[:filename]
@skip_pull_requests = options.has_option? :prskip
@issues = []
@comments = []
@milestones = []
Expand Down Expand Up @@ -58,9 +59,11 @@ def to_json
private

def download_issues
%w(open closed).each do |state|
@issues += download_all_of("issue", {:state => state})
end
@issues = download_all_of(
"issue",
{:state => "all"},
{:skip_pull_requests => @skip_pull_requests}
)
end

def download_comments
Expand All @@ -71,11 +74,11 @@ def download_milestones
@milestones = download_all_of("milestone")
end

def download_all_of(type, options = {})
items = downloader(type).new(@github_client, @repository, options).fetch
items.map do |item|
formatter(type).new(item).formatted
end
def download_all_of(type, download_options = {}, accept_options = {})
items = downloader(type).new(@github_client, @repository, download_options).fetch
formatter = formatter(type).new
items = items.select { |item| formatter.accept(item, accept_options) }
items.map { |item| formatter.format(item) }
end

def downloader(type)
Expand Down
8 changes: 6 additions & 2 deletions lib/github-to-bitbucket-issues/formatters/base.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module GTBI
module Formatters
class Base
def initialize(raw)
@raw = raw
def format(item)
{}
end

def accept(item, options)
true
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/github-to-bitbucket-issues/formatters/comment.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module GTBI
module Formatters
class Comment < Base
def formatted
def format(item)
{
:content => @raw.body,
:created_on => @raw.created_at,
:id => @raw.id,
:issue => get_issue(@raw),
:updated_on => @raw.updated_at,
:user => @raw.user.login
:content => item.body,
:created_on => item.created_at,
:id => item.id,
:issue => get_issue(item),
:updated_on => item.updated_at,
:user => item.user.login
}
end

Expand Down
38 changes: 21 additions & 17 deletions lib/github-to-bitbucket-issues/formatters/issue.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
module GTBI
module Formatters
class Issue < Base
def formatted
def format(item)
{
:assignee => get_assignee(@raw),
:assignee => get_assignee(item),
:component => nil,
:content => @raw.body || " ",
:content_updated_on => @raw.updated_at,
:created_on => @raw.updated_at,
:edited_on => @raw.updated_at,
:id => @raw.number,
:kind => get_kind(@raw),
:milestone => get_milestone(@raw),
:priority => get_priority(@raw),
:reporter => @raw.user.login,
:status => get_status(@raw),
:title => @raw.title,
:updated_on => @raw.updated_at,
:content => item.body || " ",
:content_updated_on => item.updated_at,
:created_on => item.updated_at,
:edited_on => item.updated_at,
:id => item.number,
:kind => get_kind(item),
:milestone => get_milestone(item),
:priority => get_priority(item),
:reporter => item.user.login,
:status => get_status(item),
:title => item.title,
:updated_on => item.updated_at,
:version => nil,
:watchers => []
}
end

def accept(issue, options)
!options[:skip_pull_requests] || issue.pull_request.nil? || issue.pull_request.patch_url.nil?
end

private

def get_assignee(issue)
Expand Down Expand Up @@ -64,10 +68,10 @@ def get_priority(issue)

def get_milestone(issue)
if issue.milestone
milestone = issue.milestone.title
issue.milestone.title
else
nil
end

milestone
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/github-to-bitbucket-issues/formatters/milestone.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module GTBI
module Formatters
class Milestone < Base
def formatted
def format(item)
{
:name => @raw.title
:name => item.title
}
end
end
Expand Down