gh-cards 0.2.0 → 0.2.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffcb44c41e909ba458443b3c8ca7e5b4542da1b97e117f7035e8e8aa500f4e78
4
- data.tar.gz: 2177a0f6725b21a7e96d3bae81d20cf9116000e366e1b9ed4871a55d7eb3547f
3
+ metadata.gz: b47409d11ef9ddeb07af9f1f71b33ebffb1f8dd5ccd579ba4100f58ca66db65b
4
+ data.tar.gz: 21e69c6a6282fe57c3520ce17be96c2e2d1ad9a3d8d80758c44d4b469ff5799f
5
5
  SHA512:
6
- metadata.gz: 6592bb2490b22cff266d1c897e61e7ea9acdd5521ede7d398c906480cd6a4ae1cf5ae8f4d36365118dc164be663b69bd5ee1fa2d84c925125e75011f057d41a4
7
- data.tar.gz: 330ce1d2aeb424a0332fda8acf1773273635e64e042d4c248ff1f4fa0ae1bc09470a1418a2713a8dcad869ce9aaa9d04504c9f14817ce38cc584da6316f0c92d
6
+ metadata.gz: 9d002133e26ed5db39afa9bcab1070ee36dccf79c8ed5031c081c45b6b62ac71129b0126843d6ac7e6d3ff455608615a83797afbcce69a335de2f32dfb9cb360
7
+ data.tar.gz: 666d1625fc9f4ab2f30043f70e0c89e3d757f0537c232bd0a99b7993d6e7bbb4fb50e7152bcb1deba3e93d773bbfb7f431cc8db071f6e7fb9e7071cd0bdd905e
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  *.gem
10
+ *.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # 0.2.0
2
2
 
3
+ General code cleanup
4
+
5
+ # 0.2.0
6
+
3
7
  Add an issues milestone to card objects and update default template
4
8
 
5
9
  # 0.1.0
data/README.md CHANGED
@@ -101,7 +101,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
101
101
 
102
102
  ## Contributing
103
103
 
104
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gh-cards. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/devopsmakers/gh-cards. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
105
105
 
106
106
  ## License
107
107
 
@@ -109,4 +109,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
109
109
 
110
110
  ## Code of Conduct
111
111
 
112
- Everyone interacting in the Gh::Cards project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gh-cards/blob/master/CODE_OF_CONDUCT.md).
112
+ Everyone interacting in the Gh::Cards project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/devopsmakers/gh-cards/blob/master/CODE_OF_CONDUCT.md).
data/lib/gh/cards/cli.rb CHANGED
@@ -13,7 +13,7 @@ module Gh
13
13
 
14
14
  desc "generate", "Generate your Github issue cards HTML file"
15
15
  def generate
16
- Gh::Cards.generate options[:template], options[:directory], options[:repo]
16
+ Gh::Cards.generate(options[:template], options[:directory], options[:repo])
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module Gh
2
2
  module Cards
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/lib/gh/cards.rb CHANGED
@@ -10,93 +10,88 @@ module Gh
10
10
  $user_names_cache = {}
11
11
 
12
12
  def self.generate(template, directory, repo)
13
- @template = template
14
- @directory = directory
15
- @repo = repo || _get_this_repo()
13
+ repo = repo || _get_this_repo()
14
+ last_issue = _get_last_issue(directory)
16
15
 
17
- @last_issue = _get_last_issue(@directory)
16
+ client = Octokit::Client.new(:netrc => true)
17
+ client.auto_paginate = true
18
+ cards = _get_cards_from_gh_issues(client, repo, last_issue)
18
19
 
19
- @cards = _get_cards_from_gh_issues(@last_issue)
20
+ if cards.empty?
21
+ exit_msg = "No issues found in #{repo}"
22
+ if last_issue > 0
23
+ exit_msg << "\n\nFile: #{directory}/last shows the last issue generated as #{last_issue}"
24
+ exit_msg << "\nTo reset and generate all cards, delete #{directory}/last and re-run"
25
+ end
26
+ puts exit_msg
27
+ exit 0
28
+ end
20
29
 
21
- _generate_cards_html(@template, @directory, @repo, @cards)
30
+ puts "Found #{cards.length} new #{"issue".pluralize cards.length} in #{repo} to generate cards from"
22
31
 
23
- _set_last_issue(@directory, @cards)
32
+ _generate_cards_html(template, directory, repo, cards)
24
33
 
25
- system("open", "#{@directory}/cards.html")
34
+ _set_last_issue(directory, cards)
35
+
36
+ system("open", "#{directory}/cards.html")
26
37
  puts "Done!"
27
38
  end
28
39
 
29
40
  def self._get_this_repo
30
- @repo_regex = /^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$/
41
+ repo_regex = /^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$/
31
42
  begin
32
- @g = Git.open('.')
43
+ g = Git.open('.')
33
44
  rescue
34
45
  abort("Unable to detect git repo! Make sure you're in a repo or use the --repo option")
35
46
  end
36
- @r = @g.remote('origin').url.match(@repo_regex)
37
- return "#{@r[4]}/#{@r[5]}"
47
+ r = g.remote('origin').url.match(repo_regex)
48
+ return "#{r[4]}/#{r[5]}"
38
49
  end
39
50
 
40
51
  def self._get_last_issue(directory)
41
- @last_file = "#{directory}/last"
52
+ last_file = "#{directory}/last"
42
53
 
43
54
  if ! File.directory?(directory)
44
55
  FileUtils.mkdir_p directory
45
56
  end
46
57
 
47
- if ! File.file?(@last_file)
48
- File.open(@last_file, "w") do |f|
58
+ if ! File.file?(last_file)
59
+ File.open(last_file, "w") do |f|
49
60
  f.write(0)
50
61
  end
51
62
  end
52
63
 
53
- @last_issue_number = File.open(@last_file, "r"){ |file| file.read }
54
- return @last_issue_number.to_i
55
-
64
+ last_issue_number = File.open(last_file, "r"){ |file| file.read }
65
+ return last_issue_number.to_i
56
66
  end
57
67
 
58
68
  def self._set_last_issue(directory, cards)
59
- @last_file = "#{directory}/last"
60
- File.open(@last_file, "w") do |f|
61
- f.write(@cards[0][:number])
69
+ last_file = "#{directory}/last"
70
+ File.open(last_file, "w") do |f|
71
+ f.write(cards[0][:number])
62
72
  end
63
73
  end
64
74
 
65
- def self._get_cards_from_gh_issues(last_issue)
66
- @client = Octokit::Client.new(:netrc => true)
67
- @client.auto_paginate = true
68
-
69
- @issues = @client.list_issues @repo
70
- @issues.reject!{ |issue| issue[:number] <= last_issue or issue[:pull_request]}
75
+ def self._get_cards_from_gh_issues(client, repo, last_issue)
76
+ issues = client.list_issues repo
77
+ issues.reject!{ |issue| issue[:number] <= last_issue or issue[:pull_request]}
71
78
 
72
- if @issues.empty?
73
- @exit_msg = "No issues found in #{@repo}"
74
- if last_issue > 0
75
- @exit_msg << "\n\nFile: #{@directory}/last shows the last issue generated as #{last_issue}"
76
- @exit_msg << "\nTo reset and generate all cards, delete #{@directory}/last and re-run"
77
- end
78
- puts @exit_msg
79
- exit 0
80
- end
81
-
82
- puts "Found #{@issues.length} new #{"issue".pluralize @issues.length} in #{@repo} to generate cards from"
83
-
84
- @cards = @issues.map do |issue|
79
+ cards = issues.map do |issue|
85
80
  {
86
81
  :title => issue[:title],
87
82
  :number => issue[:number],
88
83
  :labels => issue[:labels].map{|label| {:name => label[:name], :color => label[:color]}},
89
84
  :milestone => issue[:milestone] ? issue[:milestone][:title] : nil,
90
- :created_by => _get_gh_user_name(issue[:user][:login]),
85
+ :created_by => _get_gh_user_name(client, issue[:user][:login]),
91
86
  :created_at => issue[:created_at]
92
87
  }
93
88
  end
94
- return @cards
89
+ return cards
95
90
  end
96
91
 
97
- def self._get_gh_user_name(user_login)
92
+ def self._get_gh_user_name(client, user_login)
98
93
  if $user_names_cache[user_login.to_sym].nil?
99
- $user_names_cache[user_login.to_sym] = @client.user(user_login)[:name] || user_login
94
+ $user_names_cache[user_login.to_sym] = client.user(user_login)[:name] || user_login
100
95
  end
101
96
  return $user_names_cache[user_login.to_sym]
102
97
  end
@@ -104,20 +99,17 @@ module Gh
104
99
  def self._generate_cards_html(template, directory, repo, cards)
105
100
 
106
101
  if File.file?("#{__dir__}/../../templates/#{template}.html.erb")
107
- @template_file = "#{__dir__}/../../templates/#{template}.html.erb"
102
+ template_file = "#{__dir__}/../../templates/#{template}.html.erb"
108
103
  elsif File.file?("#{__dir__}/../../templates/#{template}")
109
- @template_file = "#{__dir__}/../../templates/#{template}"
104
+ template_file = "#{__dir__}/../../templates/#{template}"
110
105
  elsif File.file?(template)
111
- @template_file = template
106
+ template_file = template
112
107
  else
113
108
  abort("Unable to find template: #{template}")
114
109
  end
115
110
 
116
- @cards = cards
117
- @repo = repo
118
-
119
111
  puts "Generating cards using template: #{template}"
120
- erb = ERB.new(File.read(@template_file))
112
+ erb = ERB.new(File.read(template_file))
121
113
  File.write("#{directory}/cards.html", erb.result(binding))
122
114
  end
123
115
  end
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <title>Cards for <%= @repo %></title>
4
+ <title>Cards for <%= repo %></title>
5
5
  <meta charset="utf-8">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1">
7
7
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
@@ -20,11 +20,11 @@
20
20
  <div class="row">
21
21
  <div class="col-12">
22
22
  <div class="card-deck">
23
- <% @cards.each_slice(3) do |slice| %>
23
+ <% cards.each_slice(3) do |slice| %>
24
24
  <% slice.each do |card| %>
25
25
  <div class="card">
26
26
  <div class="card-header">
27
- <%= @repo.split('/')[-1] %>
27
+ <%= repo.split('/')[-1] %>
28
28
  </div>
29
29
  <div class="card-body">
30
30
  <h4 class="card-title"><span class="font-weight-bold">#<%= card[:number] %></span> <%= card[:title] %></h4>
@@ -35,8 +35,8 @@
35
35
  <% if card[:labels].length > 0 %>
36
36
  <h6 class="text-secondary">Labels:</h6>
37
37
  <div class="small text-secondary test-lowercase">
38
- <% for @label in card[:labels] %>
39
- <%= @label[:name] %><br />
38
+ <% for label in card[:labels] %>
39
+ <%= label[:name] %><br />
40
40
  <% end %>
41
41
  </div>
42
42
  <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh-cards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Birkett
@@ -133,6 +133,7 @@ files:
133
133
  - ".gh-cards/cards.html"
134
134
  - ".gh-cards/last"
135
135
  - ".gitignore"
136
+ - ".ruby-version"
136
137
  - ".travis.yml"
137
138
  - CHANGELOG.md
138
139
  - CODE_OF_CONDUCT.md