github_members 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/exe/github-members +5 -0
- data/lib/github_members/cli.rb +38 -12
- data/lib/github_members/client.rb +10 -0
- data/lib/github_members/markdown_writer.rb +5 -5
- data/lib/github_members/options.rb +8 -8
- data/lib/github_members/organization.rb +3 -0
- data/lib/github_members/version.rb +1 -1
- data/lib/github_members.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3252336e573db141cb2b04483678c6265eef27c14935fac81f5fc11764c3d68
|
4
|
+
data.tar.gz: e7fd29914612158a441f083af6a0a382287b1bf07c56fee013de1d5226a70136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82fb677c50b06554eceb70fa95c798e26f8236aa47ed4af5cc3a82a382d357139f0073852676b456fd48494fb19a8eed42d853789253d6a5da5588884bb544b0
|
7
|
+
data.tar.gz: 00b2bd9ad58d25d21a9f4a4cb197d5efa6816cb5a1388418c632fd4996b4271c0cb00d54e54ca4aa0dde2516dc5ed0f16ca9bf1b82de675f352961357ab8a978
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/github_members.svg)](https://badge.fury.io/rb/github_members)
|
2
|
+
|
1
3
|
# GitHub Members
|
2
4
|
|
3
5
|
Manage GitHub members who belong to an organization.
|
@@ -43,6 +45,8 @@ Examples:
|
|
43
45
|
|
44
46
|
<!-- HELP:END -->
|
45
47
|
|
48
|
+
You can use also the `github-members` command instead of `github_members`.
|
49
|
+
|
46
50
|
### Prepare GitHub access token
|
47
51
|
|
48
52
|
By default, only public members of a specified organization is fetched.
|
@@ -70,3 +74,8 @@ When running `github_members`, a table of a specified organization members is in
|
|
70
74
|
|
71
75
|
<!-- GITHUB_MEMBERS:END -->
|
72
76
|
```
|
77
|
+
|
78
|
+
## Releasing
|
79
|
+
|
80
|
+
1. Update [`GithubMembers::VERSION`](lib/github_members/version.rb) and commit the updated file.
|
81
|
+
2. Run workflow on [Actions](https://github.com/ybiquitous/github_members/actions/workflows/release.yml).
|
data/exe/github-members
ADDED
data/lib/github_members/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module GithubMembers
|
2
2
|
class CLI
|
3
|
+
class RequiredMemberAttributes < Error; end
|
4
|
+
|
3
5
|
EXIT_SUCCESS = 0
|
4
6
|
EXIT_FAILURE = 1
|
5
7
|
|
@@ -32,9 +34,18 @@ module GithubMembers
|
|
32
34
|
return EXIT_FAILURE
|
33
35
|
end
|
34
36
|
|
35
|
-
|
37
|
+
org = Organization.new(client.fetch_organization(options.github_org))
|
38
|
+
|
39
|
+
yaml_file = options.yaml_file
|
40
|
+
members =
|
41
|
+
begin
|
42
|
+
read_members(yaml_file)
|
43
|
+
rescue RequiredMemberAttributes => e
|
44
|
+
warn e.message
|
45
|
+
return EXIT_FAILURE
|
46
|
+
end
|
36
47
|
|
37
|
-
|
48
|
+
client.fetch_members(org.name).each do |new_member|
|
38
49
|
github = new_member.fetch(:github)
|
39
50
|
fullname = new_member.fetch(:fullname)
|
40
51
|
avatar = new_member.fetch(:avatar)
|
@@ -57,29 +68,44 @@ module GithubMembers
|
|
57
68
|
|
58
69
|
members.delete_if { |_, m| !m.updated }
|
59
70
|
|
60
|
-
write_members(members.values)
|
71
|
+
write_members(members.values, yaml_file)
|
72
|
+
puts "Updated: #{yaml_file}"
|
61
73
|
|
62
|
-
|
74
|
+
markdown_file = options.markdown_file
|
75
|
+
MarkdownWriter.new.write(org: org, members: members.values, file: markdown_file)
|
76
|
+
puts "Updated: #{markdown_file}"
|
63
77
|
|
64
78
|
EXIT_SUCCESS
|
65
79
|
end
|
66
80
|
|
67
|
-
private
|
81
|
+
private
|
82
|
+
|
83
|
+
def client
|
84
|
+
@client ||= Client.new(options)
|
85
|
+
end
|
86
|
+
|
87
|
+
def member_class
|
68
88
|
@member_class ||= Member.new.define_class(*options.fields)
|
69
89
|
end
|
70
90
|
|
71
|
-
|
72
|
-
file = options.yaml_file
|
91
|
+
def read_members(file)
|
73
92
|
return {} unless file.exist?
|
74
93
|
|
75
|
-
YAML.safe_load(File.read(file)).each_with_object({}) do |
|
76
|
-
|
77
|
-
|
94
|
+
YAML.safe_load(File.read(file)).each_with_object({}) do |member_attrs, hash|
|
95
|
+
member = member_class.new(updated: false)
|
96
|
+
|
97
|
+
required_attrs = member_attrs.keys.map(&:to_sym) - member.members
|
98
|
+
unless required_attrs.empty?
|
99
|
+
raise RequiredMemberAttributes, "Needed to specify the option: --fields #{required_attrs.join(",")}"
|
100
|
+
end
|
101
|
+
|
102
|
+
member_attrs.each { |key, value| member[key] = value }
|
103
|
+
hash[member.github] = member
|
78
104
|
end
|
79
105
|
end
|
80
106
|
|
81
|
-
|
82
|
-
|
107
|
+
def write_members(members, file)
|
108
|
+
file.write(members.map(&:to_h).to_yaml)
|
83
109
|
end
|
84
110
|
end
|
85
111
|
end
|
@@ -5,7 +5,7 @@ module GithubMembers
|
|
5
5
|
TAG_BEGIN = "<!-- GITHUB_MEMBERS:BEGIN -->"
|
6
6
|
TAG_END = "<!-- GITHUB_MEMBERS:END -->"
|
7
7
|
|
8
|
-
def write(members:, file:)
|
8
|
+
def write(org:, members:, file:)
|
9
9
|
unless file.exist?
|
10
10
|
file.write(<<~MARKDOWN)
|
11
11
|
# Members
|
@@ -16,14 +16,14 @@ module GithubMembers
|
|
16
16
|
end
|
17
17
|
|
18
18
|
table = render_table(members)
|
19
|
-
write_file(table, members.size, file)
|
19
|
+
write_file(table, members.size, org, file)
|
20
20
|
end
|
21
21
|
|
22
22
|
private def render_table(members)
|
23
23
|
return "" if members.empty?
|
24
24
|
|
25
25
|
fields = members.first.additional_fields
|
26
|
-
labels = ["", "GitHub", "Fullname"]
|
26
|
+
labels = [" ", "GitHub", "Fullname"]
|
27
27
|
align = ["c", "l", "l"]
|
28
28
|
|
29
29
|
fields.each do |field|
|
@@ -48,7 +48,7 @@ module GithubMembers
|
|
48
48
|
MarkdownTables.make_table(labels, data, is_rows: true, align: align)
|
49
49
|
end
|
50
50
|
|
51
|
-
private def write_file(table, member_count, file)
|
51
|
+
private def write_file(table, member_count, org, file)
|
52
52
|
content = file.read
|
53
53
|
|
54
54
|
unless content.include?(TAG_BEGIN)
|
@@ -61,7 +61,7 @@ module GithubMembers
|
|
61
61
|
|
62
62
|
content.sub!(/#{TAG_BEGIN}.+#{TAG_END}/mo, <<~MARKDOWN.strip)
|
63
63
|
#{TAG_BEGIN}
|
64
|
-
**#{member_count}** member#{member_count == 1 ? "" : "s"}
|
64
|
+
**#{member_count}** member#{member_count == 1 ? "" : "s"} of [#{org.name}](#{org.url})
|
65
65
|
|
66
66
|
#{table}
|
67
67
|
#{TAG_END}
|
@@ -17,7 +17,7 @@ module GithubMembers
|
|
17
17
|
self.github_token = ENV["GITHUB_TOKEN"].to_s
|
18
18
|
|
19
19
|
args = parser.parse!(argv)
|
20
|
-
self.help = parser.help + help_examples
|
20
|
+
self.help = parser.help + help_examples(parser.program_name)
|
21
21
|
self.github_org = args.first
|
22
22
|
self.markdown_file = Pathname(markdown_file || Defaults::MARKDOWN_FILE)
|
23
23
|
self.yaml_file = Pathname(yaml_file || Defaults::YAML_FILE)
|
@@ -27,7 +27,7 @@ module GithubMembers
|
|
27
27
|
|
28
28
|
private def parser
|
29
29
|
@parser ||= OptionParser.new do |opts|
|
30
|
-
opts.banner = "Usage:
|
30
|
+
opts.banner = "Usage: #{opts.program_name} [options] <org>"
|
31
31
|
|
32
32
|
opts.on("-g", "--github-token GITHUB_TOKEN",
|
33
33
|
"A GitHub access token. The `GITHUB_TOKEN` environment variable",
|
@@ -57,22 +57,22 @@ module GithubMembers
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
private def help_examples
|
60
|
+
private def help_examples(program_name)
|
61
61
|
<<~HELP
|
62
62
|
|
63
63
|
Examples:
|
64
64
|
# By default
|
65
|
-
|
65
|
+
#{program_name} <org>
|
66
66
|
|
67
67
|
# Set a token
|
68
|
-
GITHUB_TOKEN=***
|
69
|
-
|
68
|
+
GITHUB_TOKEN=*** #{program_name} <org>
|
69
|
+
#{program_name} <org> -g ***
|
70
70
|
|
71
71
|
# Specify files
|
72
|
-
|
72
|
+
#{program_name} <org> -m README.md -y company_members.yml
|
73
73
|
|
74
74
|
# Add fields
|
75
|
-
|
75
|
+
#{program_name} <org> -f slack,note
|
76
76
|
HELP
|
77
77
|
end
|
78
78
|
end
|
data/lib/github_members.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative "github_members/defaults"
|
|
9
9
|
require_relative "github_members/markdown_writer"
|
10
10
|
require_relative "github_members/member"
|
11
11
|
require_relative "github_members/options"
|
12
|
+
require_relative "github_members/organization"
|
12
13
|
require_relative "github_members/version"
|
13
14
|
|
14
15
|
require_relative "github_members/cli"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_members
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masafumi Koba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: markdown-tables
|
@@ -43,12 +43,14 @@ email:
|
|
43
43
|
- ybiquitous@gmail.com
|
44
44
|
executables:
|
45
45
|
- github_members
|
46
|
+
- github-members
|
46
47
|
extensions: []
|
47
48
|
extra_rdoc_files: []
|
48
49
|
files:
|
49
50
|
- CHANGELOG.md
|
50
51
|
- LICENSE
|
51
52
|
- README.md
|
53
|
+
- exe/github-members
|
52
54
|
- exe/github_members
|
53
55
|
- lib/github_members.rb
|
54
56
|
- lib/github_members/cli.rb
|
@@ -58,6 +60,7 @@ files:
|
|
58
60
|
- lib/github_members/markdown_writer.rb
|
59
61
|
- lib/github_members/member.rb
|
60
62
|
- lib/github_members/options.rb
|
63
|
+
- lib/github_members/organization.rb
|
61
64
|
- lib/github_members/version.rb
|
62
65
|
homepage: https://github.com/ybiquitous/github_members
|
63
66
|
licenses:
|