githubissues-port 0.1.4 → 0.2
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 +8 -8
- data/README.rdoc +3 -1
- data/export.xlsx +0 -0
- data/lib/githubissues-port/export.rb +38 -21
- data/lib/githubissues-port/import.rb +55 -20
- data/lib/githubissues-port/version.rb +1 -1
- data/spec/fixtures/sample.xlsx +0 -0
- data/spec/test_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWY0MjEzZmY5MWZjZmE3OTA4N2YxNGNhYjFiYjY5YWY1N2Y5YTQ1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjI3ODE3YWE4ZjJlZWIwYzQ1YTVkNWM1YzBiNjRiNmJmNGU2NDAyYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTU3ODcxMTg0ZWY2M2RkOTg5ZDZjODUyZDdlYzFmZjM4NTI3YzczZWQ3YWVm
|
10
|
+
MWVlMWJiYTM0MWY0MTgwNjFmYjNjZTJhZmRkZDk5ZWE2ODYzZWYzZGMyMzk4
|
11
|
+
MjQzNGFlMzMzZTA1YzZmMDIwZDQ5NjNjMDE4ZTI1NzY4ZjFmZmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTEwMzI5Y2Q4MzBhNGFlZTE0MjFhYzQ0ODUyZDNmYjU0NmJlNGRhNjg3ZGJk
|
14
|
+
MjkwZGFkMThlNjBjZDc3YjNlYzM2YzJhODMyZmVjYTBkN2E5MmNiNGI1Yzdh
|
15
|
+
M2Q0ZGMyM2ZmMTQxZDI5OTVjMGViNTFjZTE1MzdhMDdlM2IxOTY=
|
data/README.rdoc
CHANGED
@@ -28,8 +28,10 @@ githubissues-port can simply import or export issues from an Excel file.:
|
|
28
28
|
|
29
29
|
connection = Github.new basic_auth: "#{your_github_username}:#{your_github_password}"
|
30
30
|
|
31
|
-
|
31
|
+
# The import mudule will import issues from Excel, creates an issue if the number blank, otherwise, updating an existing issue by looking up the issue number.
|
32
|
+
Githubissues::Port::Import.new connection, owner, repo, 'import.xlsx', fields: ['title', 'labels']
|
32
33
|
|
34
|
+
# The export module will export issues to Excel.
|
33
35
|
Githubissues::Port::Export.new connection, owner, repo, 'export.xlsx', fields: ['number', 'title', 'body', 'labels']
|
34
36
|
|
35
37
|
== Contributing
|
data/export.xlsx
CHANGED
Binary file
|
@@ -4,30 +4,47 @@ require 'axlsx'
|
|
4
4
|
module Githubissues
|
5
5
|
module Port
|
6
6
|
class Githubissues::Port::Export
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :connection, :owner, :repo, :path
|
8
8
|
def initialize connection, owner, repo, path, options = {}
|
9
9
|
@path = path
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
10
|
+
@connection = connection
|
11
|
+
@owner = owner
|
12
|
+
@repo = repo
|
13
|
+
@default_fields = %w(number title body labels assignee state milestone created_at closed_at comments comments_url events_url html_url labels_url)
|
14
|
+
@fields = (options.has_key? :fields) ? options[:fields] : @default_fields
|
15
|
+
generate_excel
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_excel
|
19
|
+
Axlsx::Package.new do |excel|
|
20
|
+
generate_sheet excel, 'open'
|
21
|
+
generate_sheet excel, 'closed'
|
22
|
+
excel.serialize path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_sheet excel, state
|
27
|
+
excel.workbook.add_worksheet(:name => state) do |sheet|
|
28
|
+
sheet.add_row @fields
|
29
|
+
issues = @connection.issues.list user: @owner,
|
30
|
+
repo: @repo,
|
31
|
+
filter: 'all',
|
32
|
+
auto_pagination: true,
|
33
|
+
state: state
|
34
|
+
issues.each{|issue| sheet.add_row generate_row(issue)}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_row issue
|
39
|
+
@fields.collect do |field|
|
40
|
+
case field.downcase
|
41
|
+
when 'assignee'
|
42
|
+
issue.assignee.login unless issue.assignee.nil?
|
43
|
+
when 'labels'
|
44
|
+
issue.labels.map(&:name).join(', ') unless issue.labels.nil?
|
45
|
+
else
|
46
|
+
issue.send field
|
29
47
|
end
|
30
|
-
p.serialize path
|
31
48
|
end
|
32
49
|
end
|
33
50
|
end
|
@@ -4,35 +4,70 @@ require 'creek'
|
|
4
4
|
module Githubissues
|
5
5
|
module Port
|
6
6
|
class Githubissues::Port::Import
|
7
|
-
attr_reader :path, :messages
|
7
|
+
attr_reader :connection, :owner, :repo, :path, :messages, :header
|
8
8
|
def initialize connection, owner, repo, path, options = {}
|
9
9
|
@path = path
|
10
|
-
|
10
|
+
@connection = connection
|
11
|
+
@owner = owner
|
12
|
+
@repo = repo
|
13
|
+
@fields = (options.has_key? :fields) ? options[:fields] : %w(labels)
|
14
|
+
@messages = []
|
15
|
+
parse_excel
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_excel
|
11
19
|
creek = Creek::Book.new path, :check_file_extension => false
|
12
20
|
sheet= creek.sheets[0]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
sheet.rows.each_with_index do |row, row_index|
|
22
|
+
break if row.first.nil? and row[1].nil?
|
23
|
+
row_number = row_index + 1
|
24
|
+
case row_number
|
25
|
+
when 1
|
26
|
+
parse_header row, row_number
|
18
27
|
else
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
parse_row row, row_number
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
22
32
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
updates[f.downcase] = value
|
28
|
-
end
|
29
|
-
end
|
33
|
+
def parse_header row, row_number
|
34
|
+
@header = row.invert
|
35
|
+
@header.each{|k, v| @header[k] = v.gsub('1', '')}
|
36
|
+
end
|
30
37
|
|
31
|
-
|
32
|
-
|
38
|
+
def extract_updates row, row_number
|
39
|
+
updates = {}
|
40
|
+
@fields.each do |field|
|
41
|
+
if @header.has_key? field
|
42
|
+
value = row["#{@header[field]}#{row_number}"]
|
43
|
+
value = value.split(',').map(&:strip) if field.downcase.eql?'labels' and (!value.nil?)
|
44
|
+
updates[field.downcase] = value
|
33
45
|
end
|
34
46
|
end
|
35
|
-
|
47
|
+
puts updates.inspect
|
48
|
+
updates
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_existing_issue number, updates
|
52
|
+
issue = @connection.issues.edit @owner, @repo, number, updates
|
53
|
+
@messages.push "Issue ##{issue.number} updated: #{updates.inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_new_issue number, updates
|
57
|
+
@connection.user = @owner
|
58
|
+
@connection.repo = @repo
|
59
|
+
issue = @connection.issues.create updates
|
60
|
+
@messages.push "Issue ##{issue.number} created: #{updates.inspect}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_row row, row_number
|
64
|
+
number = row["A#{row_number}"]
|
65
|
+
updates = extract_updates row, row_number
|
66
|
+
unless number.nil?
|
67
|
+
update_existing_issue number, updates
|
68
|
+
else
|
69
|
+
create_new_issue number, updates
|
70
|
+
end
|
36
71
|
end
|
37
72
|
end
|
38
73
|
end
|
data/spec/fixtures/sample.xlsx
CHANGED
Binary file
|
data/spec/test_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe 'githubissues-port exporting and importing to xlsx' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'import should be successfull.' do
|
17
|
-
import = Githubissues::Port::Import.new @connection, 'pythonicrubyist', 'test_issues', 'spec/fixtures/sample.xlsx', fields: ['labels']
|
17
|
+
import = Githubissues::Port::Import.new @connection, 'pythonicrubyist', 'test_issues', 'spec/fixtures/sample.xlsx', fields: ['title', 'labels']
|
18
18
|
puts import.messages.inspect
|
19
19
|
import.should_not be_nil
|
20
20
|
end
|