mkghrepo 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f817c7c60a8d2f73adcfaa2b815c63e3d66c1cb
4
- data.tar.gz: 7315c2b0d060eb991d98fd7d7b269f40f8969053
3
+ metadata.gz: 2733c4f97e164ebb080cbf7133ad9d0769434949
4
+ data.tar.gz: 11f8fbc4e9982c072596758caa133f5f72f21a18
5
5
  SHA512:
6
- metadata.gz: 8778966fc365421acaa458c012a72feb65f97487d09e1a267a12128f2d287d7642cd29813fb86823740a884719671a6bbb84e083434889a72129b27cc226724b
7
- data.tar.gz: 4d5a59d79735a120288a17c126f13146bd4e3e7f7ff537b40abca661d68f3da1ce9af44261c7145cd845f3a1f243256359e98155e573d76fd36e7cc58d0410a5
6
+ metadata.gz: 2bc240ed5465854185af36c4ba15c8b8361794a1c8369320d764abb7f1ba993e9cc30b524770709f5d41747fced0c3dc879bc5bf9f8b58c6dd301324099bb393
7
+ data.tar.gz: ddd476f1691a578497c1d2b574c58245d16aa61c044aa88799cc2cb06e9e6a1f936cac79c2a1b964af389d54929aa3bb0ad0819207c990e88476936ac93c3119
@@ -40,8 +40,11 @@ module Mkghrepo
40
40
  default: false
41
41
  o.bool '-t',
42
42
  '--create-team',
43
- 'creates a team called "<foo>-write", default is false',
43
+ 'creates a team called "<repo>", default is false',
44
44
  default: false
45
+ o.string '-ts',
46
+ '--team-suffix',
47
+ 'adds a suffix to the team name, "<repo>-<team-suffix>"'
45
48
  o.string '--token',
46
49
  'sets github token, defaults from GITHUB_TOKEN',
47
50
  default: ENV['GITHUB_TOKEN']
@@ -88,7 +91,7 @@ module Mkghrepo
88
91
  File.open(file, 'r') do |f|
89
92
  f.each_line do |a|
90
93
  # Treat each line as a separate repo
91
- process_lines(a, client, opts[:private], opts[:create_team])
94
+ process_lines(a, client, opts)
92
95
  end
93
96
  end
94
97
  end
@@ -100,7 +103,7 @@ module Mkghrepo
100
103
  begin
101
104
  STDIN.read.split("\n").each do |a|
102
105
  # Treat each line as a separate repo
103
- process_lines(a, client, opts[:private], opts[:create_team])
106
+ process_lines(a, client, opts)
104
107
  end
105
108
  rescue Interrupt
106
109
  # Trap a CTRL+C event and exit gracefully
@@ -109,7 +112,7 @@ module Mkghrepo
109
112
  end
110
113
  end
111
114
 
112
- def process_lines(line, client, private, create_team)
115
+ def process_lines(line, client, opts)
113
116
  # Split the line using space as delimiter, format is:
114
117
  # <org>/<repo> <user1> <user2> ... <userN>
115
118
  # or
@@ -117,20 +120,20 @@ module Mkghrepo
117
120
  @logger.debug("processing #{line.strip}")
118
121
  matches = line.split(' ')
119
122
  repo = matches[0]
120
- create_repo(client, repo, private)
123
+ create_repo(client, repo, opts)
121
124
 
122
125
  # If no users are specified or create_team was not enabled
123
- return if matches.length < 2 || create_team == false
126
+ return if matches.length < 2 || opts[:create_team] == false
124
127
  # create team and whatever
125
128
  if repo.include? '/'
126
- process_team(client, repo, matches[1..matches.count])
129
+ process_team(client, repo, matches[1..matches.count], opts)
127
130
  else
128
131
  @logger.warn("Not creating Team for #{repo}, only orgs support teams")
129
132
  end
130
133
  end
131
134
 
132
- def process_team(client, repo, users)
133
- team = create_team(client, repo)
135
+ def process_team(client, repo, users, opts)
136
+ team = create_team(client, repo, opts)
134
137
  users.each do |user|
135
138
  add_user_to_team(client, user, team.id) if team.respond_to? :id
136
139
  end
@@ -152,17 +155,21 @@ module Mkghrepo
152
155
  end
153
156
  end
154
157
 
155
- def create_repo(client, repo, private)
158
+ def create_repo(client, repo, opts)
156
159
  @logger.debug("Creating repo named: #{repo}")
157
- client.create_repo(repo, private)
160
+ client.create_repo(repo, opts[:private])
158
161
  rescue Octokit::Error => e
159
162
  parse_error(repo, e)
160
163
  else
161
164
  @logger.info("Succesfully created repository: #{repo}")
162
165
  end
163
166
 
164
- def create_team(client, repo)
165
- team_name = repo.rpartition('/').last + '-write'
167
+ def create_team(client, repo, opts)
168
+ if opts[:team_suffix]
169
+ team_name = repo.rpartition('/').last + '-' + opts[:team_suffix]
170
+ else
171
+ team_name = repo.rpartition('/').last
172
+ end
166
173
  @logger.debug("Creating team named: #{team_name}")
167
174
  team = client.create_team(repo, team_name, 'push')
168
175
  rescue Octokit::Error => e
@@ -1,6 +1,8 @@
1
1
  # encoding: UTF-8
2
2
  require 'octokit'
3
3
 
4
+ PREVIEW_API_HEADER = 'application/vnd.github.ironman-preview+json'
5
+
4
6
  module Mkghrepo
5
7
  # Repo provides an interface to github repos
6
8
  class Repo
@@ -32,11 +34,15 @@ module Mkghrepo
32
34
  @client.create_team(organization,
33
35
  name: team_name,
34
36
  repo_names: [repo],
35
- permission: permissions)
37
+ permission: permissions,
38
+ privacy: 'closed',
39
+ accept: PREVIEW_API_HEADER)
36
40
  end
37
41
 
38
42
  def add_user_to_team(user, team_id)
39
- @client.add_team_member(team_id, user)
43
+ @client.add_team_membership(team_id, user,
44
+ role: 'maintainer',
45
+ accept: PREVIEW_API_HEADER)
40
46
  end
41
47
  end
42
48
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  # Set version for the Gem
3
3
  module Mkghrepo
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkghrepo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rapposelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit