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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGIyNDMyMDNmZTRiZTZkZjRlYTBkNGNhYjc2YzE5YzE3N2RmZTdhZA==
4
+ OWY0MjEzZmY5MWZjZmE3OTA4N2YxNGNhYjFiYjY5YWY1N2Y5YTQ1ZQ==
5
5
  data.tar.gz: !binary |-
6
- MzJjM2M1ZjczYjc4OWFlNDZkOTJmNzQ0NmYwNjhkYWQzNTQ3YWYzMw==
6
+ ZjI3ODE3YWE4ZjJlZWIwYzQ1YTVkNWM1YzBiNjRiNmJmNGU2NDAyYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzM0YTI2MjA1ODE5YzIyZTdkZDNhNmQzYTQ3ZDhiYWFmYjYzNWI5ZjJmN2Vi
10
- ZTY3NWY3OWNhMGQ4MTNiYzI1MzM3ZGEwZWFlY2NlNmI0ZWNkNTMwOGNkN2Uw
11
- MjgwMjVjMmMwNjRlYWUyZTAxYjc4N2I3ZmFhOWQ3N2U3YjA1OWI=
9
+ NTU3ODcxMTg0ZWY2M2RkOTg5ZDZjODUyZDdlYzFmZjM4NTI3YzczZWQ3YWVm
10
+ MWVlMWJiYTM0MWY0MTgwNjFmYjNjZTJhZmRkZDk5ZWE2ODYzZWYzZGMyMzk4
11
+ MjQzNGFlMzMzZTA1YzZmMDIwZDQ5NjNjMDE4ZTI1NzY4ZjFmZmU=
12
12
  data.tar.gz: !binary |-
13
- NmZjMmM4NjlmMWQ2ODViMmM4MGYzZGQ4NTg2N2U5OWRlOTFiZjRiMWJhOGVk
14
- OGJiZTJmZWQxNTI0YzMwZWMwODJmNjNmN2IyMWU2YjdkYTJiNmY3NmRjMGU3
15
- N2I0MDlmMzZkNWM3OTBlYTk4Y2Q3YmU0YTBkMmM2ZWYyNmUzMzQ=
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
- Githubissues::Port::Import.new connection, owner, repo, 'import.xlsx', fields: ['labels']
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 :path, :fields
7
+ attr_reader :connection, :owner, :repo, :path
8
8
  def initialize connection, owner, repo, path, options = {}
9
9
  @path = path
10
- fields = (options.has_key? :fields) ? options[:fields] : %w(number title body labels assignee state milestone created_at closed_at comments comments_url events_url html_url labels_url)
11
- issues = connection.issues.list user: owner, repo: repo, filter: 'all', auto_pagination: true
12
- Axlsx::Package.new do |p|
13
- p.workbook.add_worksheet(:name => @repo) do |s|
14
- s.add_row fields
15
- issues.each do |i|
16
- row = Array.new
17
- fields.each do |f|
18
- row.push case f.downcase
19
- when 'assignee'
20
- i.assignee.login unless i.assignee.nil?
21
- when 'labels'
22
- i.labels.map(&:name).join(', ') unless i.labels.nil?
23
- else
24
- i.send f
25
- end
26
- end unless issues.nil?
27
- s.add_row row
28
- end
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
- fields = (options.has_key? :fields) ? options[:fields] : %w(labels)
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
- @messages = []
14
- sheet.rows.each_with_index do |r, i|
15
- case i
16
- when 0
17
- @header = r.invert
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
- number = r["A#{i+1}"]
20
- updates = {}
21
- break if number.nil?
28
+ parse_row row, row_number
29
+ end
30
+ end
31
+ end
22
32
 
23
- fields.each do |f|
24
- if @header.has_key? f
25
- value = r[@header[f].gsub '1', (i+1).to_s]
26
- value = value.split(',').map(&:strip) if f.downcase.eql?'labels' and (!value.nil?)
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
- issue = connection.issues.edit owner, repo, number, updates
32
- @messages.push "Issue ##{number} updated: #{updates.inspect}"
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
- @messages
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
@@ -1,5 +1,5 @@
1
1
  module Githubissues
2
2
  module Port
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2"
4
4
  end
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githubissues-port
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramtin Vaziri