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 +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -2
- data/lib/gh/cards/cli.rb +1 -1
- data/lib/gh/cards/version.rb +1 -1
- data/lib/gh/cards.rb +43 -51
- data/templates/default.html.erb +5 -5
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b47409d11ef9ddeb07af9f1f71b33ebffb1f8dd5ccd579ba4100f58ca66db65b
|
4
|
+
data.tar.gz: 21e69c6a6282fe57c3520ce17be96c2e2d1ad9a3d8d80758c44d4b469ff5799f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d002133e26ed5db39afa9bcab1070ee36dccf79c8ed5031c081c45b6b62ac71129b0126843d6ac7e6d3ff455608615a83797afbcce69a335de2f32dfb9cb360
|
7
|
+
data.tar.gz: 666d1625fc9f4ab2f30043f70e0c89e3d757f0537c232bd0a99b7993d6e7bbb4fb50e7152bcb1deba3e93d773bbfb7f431cc8db071f6e7fb9e7071cd0bdd905e
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/CHANGELOG.md
CHANGED
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/
|
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/
|
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
|
16
|
+
Gh::Cards.generate(options[:template], options[:directory], options[:repo])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/gh/cards/version.rb
CHANGED
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
|
-
|
14
|
-
|
15
|
-
@repo = repo || _get_this_repo()
|
13
|
+
repo = repo || _get_this_repo()
|
14
|
+
last_issue = _get_last_issue(directory)
|
16
15
|
|
17
|
-
|
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
|
-
|
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
|
-
|
30
|
+
puts "Found #{cards.length} new #{"issue".pluralize cards.length} in #{repo} to generate cards from"
|
22
31
|
|
23
|
-
|
32
|
+
_generate_cards_html(template, directory, repo, cards)
|
24
33
|
|
25
|
-
|
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
|
-
|
41
|
+
repo_regex = /^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$/
|
31
42
|
begin
|
32
|
-
|
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
|
-
|
37
|
-
return "#{
|
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
|
-
|
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?(
|
48
|
-
File.open(
|
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
|
-
|
54
|
-
return
|
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
|
-
|
60
|
-
File.open(
|
61
|
-
f.write(
|
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
|
-
|
67
|
-
|
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
|
-
|
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
|
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] =
|
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
|
-
|
102
|
+
template_file = "#{__dir__}/../../templates/#{template}.html.erb"
|
108
103
|
elsif File.file?("#{__dir__}/../../templates/#{template}")
|
109
|
-
|
104
|
+
template_file = "#{__dir__}/../../templates/#{template}"
|
110
105
|
elsif File.file?(template)
|
111
|
-
|
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(
|
112
|
+
erb = ERB.new(File.read(template_file))
|
121
113
|
File.write("#{directory}/cards.html", erb.result(binding))
|
122
114
|
end
|
123
115
|
end
|
data/templates/default.html.erb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html lang="en">
|
3
3
|
<head>
|
4
|
-
<title>Cards for <%=
|
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
|
-
<%
|
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
|
-
<%=
|
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
|
39
|
-
<%=
|
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.
|
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
|