zd_hire 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/zd_hire +95 -28
- data/lib/zd_hire/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad1103a8e3681f621dbed4bd2926afa07b48168c
|
4
|
+
data.tar.gz: 441fdd191d67aa469918582a9f8e384788e9e8b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ee99e6f0e9c3ce52e14173ba129891e7212a3a0e29fab83752b7fc929796ed58555d4f9c08f9541e00e224a52bcd9c1f682e980826f805ed841c8527114e28c
|
7
|
+
data.tar.gz: 4563d3978b7cdb5bbfbe448b63710e5801f55d11299b9d5cff74827f43543ca2f7ee00d0349f3e12a6523ef52c17983a1473bf30419cab1a793dbe2d11ad75e0
|
data/bin/zd_hire
CHANGED
@@ -19,6 +19,12 @@ QUESTIONS = {
|
|
19
19
|
PRIVATE_SECTION_SEPARATOR = '## PRIVATE'
|
20
20
|
EVALUATION_SEPARATOR = '## EVALUATION'
|
21
21
|
DEFAULT_ISSUE_LABEL = 'default_issue'
|
22
|
+
POSITION_LEVEL_LABELS = %w{
|
23
|
+
software_engineer
|
24
|
+
senior_software_engineer
|
25
|
+
staff_engineer
|
26
|
+
senior_staff_engineer
|
27
|
+
}
|
22
28
|
|
23
29
|
def token_validator
|
24
30
|
->(token) {
|
@@ -87,9 +93,16 @@ command :init do |c|
|
|
87
93
|
end
|
88
94
|
|
89
95
|
command :clone do |c|
|
96
|
+
c.syntax = 'zd_hire clone REPOSITORY NAME'
|
97
|
+
c.description = 'Sets up repository for candidate'
|
98
|
+
c.option '--custom', TrueClass, 'Whether should run in custom mode'
|
99
|
+
c.option '--verbose', TrueClass, 'Whether should run in verbose mode'
|
90
100
|
c.action do |args, options|
|
101
|
+
$custom = options.custom
|
102
|
+
$verbose = options.verbose
|
103
|
+
|
91
104
|
if config.valid?
|
92
|
-
target = ask(QUESTIONS[:target_repo]) do |q|
|
105
|
+
target = args.first || ask(QUESTIONS[:target_repo]) do |q|
|
93
106
|
q.validate = target_validator
|
94
107
|
q.responses.merge!(not_valid: "Target and origin repositories can't be the same")
|
95
108
|
end
|
@@ -97,15 +110,16 @@ command :clone do |c|
|
|
97
110
|
else
|
98
111
|
say 'Run `zd_hire init` to configure github keys'
|
99
112
|
end
|
100
|
-
|
113
|
+
agree_if_custom('Would you like to create a Github Project?(y/n) ', true) do
|
101
114
|
create_project(target)
|
102
115
|
end
|
103
116
|
end
|
104
117
|
end
|
105
118
|
|
106
119
|
def create_pr(new_repo)
|
120
|
+
say "Copying Pull Request..."
|
107
121
|
origin_pull_requests.each {|pr| say "[#{pr.number}] #{pr.head.ref}: #{pr.title}" }
|
108
|
-
pr_number = ask('Which Pull Request? ')
|
122
|
+
pr_number = ask('Which Pull Request? [The branch must also be available locally] ')
|
109
123
|
selected = origin_pull_requests.detect {|pr| pr.number.to_i == pr_number.to_i }
|
110
124
|
exit unless selected
|
111
125
|
branch = selected.head.ref
|
@@ -116,13 +130,23 @@ def create_pr(new_repo)
|
|
116
130
|
"git push origin #{branch}"
|
117
131
|
].join(' && ')
|
118
132
|
|
119
|
-
|
133
|
+
say "Pulling from local branch..."
|
134
|
+
execute(command, wait_response: true)
|
120
135
|
sleep 1
|
136
|
+
say "Creating PR in target repository..."
|
121
137
|
github.create_pull_request(new_repo.full_name, 'master', branch, selected.title, selected.body)
|
122
138
|
end
|
123
139
|
|
124
140
|
def origin_default_issue
|
125
|
-
@df ||= origin_repo_issues.detect{|issue| issue
|
141
|
+
@df ||= origin_repo_issues.detect{ |issue| has_label?(issue, DEFAULT_ISSUE_LABEL) }
|
142
|
+
end
|
143
|
+
|
144
|
+
def issues_by_label(label)
|
145
|
+
origin_repo_issues.select { |issue| has_label?(issue, label) }
|
146
|
+
end
|
147
|
+
|
148
|
+
def has_label?(issue, label)
|
149
|
+
issue.labels.any? { |l| l.name == label }
|
126
150
|
end
|
127
151
|
|
128
152
|
def evaluation_items(issue)
|
@@ -154,15 +178,33 @@ def origin_pull_requests
|
|
154
178
|
@prs ||= github.pull_requests(config.origin_repo)
|
155
179
|
end
|
156
180
|
|
157
|
-
def
|
181
|
+
def copy_issues(target)
|
182
|
+
selected_issues = $custom ? pick_issues : issues_for_position
|
183
|
+
say "Copying issues..."
|
184
|
+
selected_issues.each { |issue| copy_issue(target, issue) }
|
185
|
+
|
186
|
+
report_issues(selected_issues) if $custom
|
187
|
+
end
|
188
|
+
|
189
|
+
def pick_issues
|
158
190
|
issues = presentable_issues
|
159
191
|
issues.each { |i| say "#{i.number}: #{i.title}" }
|
160
192
|
issue_ids = ask('Type Issue IDs separated by spaces: ', Array).map(&:to_i)
|
161
|
-
|
193
|
+
issues.select do |issue|
|
162
194
|
issue_ids.include?(issue.number.to_i)
|
163
195
|
end
|
164
|
-
|
165
|
-
|
196
|
+
end
|
197
|
+
|
198
|
+
def issues_for_position
|
199
|
+
position = choose("Which Position? \n") do |menu|
|
200
|
+
menu.choices(*POSITION_LEVEL_LABELS)
|
201
|
+
end
|
202
|
+
issues_by_label(position)
|
203
|
+
end
|
204
|
+
|
205
|
+
def report_issues(issues)
|
206
|
+
say "Reporting issues..."
|
207
|
+
issues.each { |issue| puts evaluation_item_report(issue) }
|
166
208
|
end
|
167
209
|
|
168
210
|
def copy_issue(target, issue)
|
@@ -176,21 +218,23 @@ def copy_issue(target, issue)
|
|
176
218
|
end
|
177
219
|
|
178
220
|
def clone_repository(origin, target)
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
221
|
+
say "Cloning repository..."
|
222
|
+
command = [
|
223
|
+
"git clone git@github.com:#{origin}.git -b master --single-branch #{target}",
|
224
|
+
].join(' && ')
|
225
|
+
|
226
|
+
execute(command)
|
184
227
|
end
|
185
228
|
|
186
229
|
def setup_remote(target_dir, remote_repo)
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
230
|
+
say "Setting up remote..."
|
231
|
+
command = [
|
232
|
+
"cd #{target_dir}",
|
233
|
+
"git remote set-url origin #{remote_repo.ssh_url}",
|
234
|
+
'git push -u origin master'
|
235
|
+
].join(' && ')
|
236
|
+
|
237
|
+
execute(command)
|
194
238
|
end
|
195
239
|
|
196
240
|
def create_project(target)
|
@@ -199,27 +243,28 @@ def create_project(target)
|
|
199
243
|
menu.choices(*([user] + github.organizations.map(&:login)))
|
200
244
|
menu.default = user
|
201
245
|
end
|
202
|
-
project_name =
|
246
|
+
project_name = ask_if_custom('Project name? ', target)
|
203
247
|
attrs = repo_attributes
|
204
248
|
attrs[:organization] = organization unless user == organization
|
205
|
-
attrs[:private] = agree('Private repository?(y/n) ', true)
|
249
|
+
attrs[:private] = agree('Private repository [Requires paid Github Account]?(y/n) ', true)
|
206
250
|
|
207
251
|
begin
|
252
|
+
say "Creating Github project..."
|
208
253
|
new_repo = github.create_repository(project_name, attrs)
|
209
254
|
|
210
|
-
|
255
|
+
agree_if_custom("Would you like setup the local repo?(y/n) ", true) do
|
211
256
|
setup_remote(target, new_repo)
|
212
257
|
end
|
213
258
|
|
214
|
-
|
215
|
-
|
259
|
+
agree_if_custom("Would you like to select issues to copy(y/n) ", true) do
|
260
|
+
copy_issues(new_repo.full_name)
|
216
261
|
end
|
217
262
|
|
218
|
-
|
263
|
+
agree_if_custom("Would you like to copy a Pull Request(y/n) ", true) do
|
219
264
|
create_pr(new_repo)
|
220
265
|
end
|
221
266
|
|
222
|
-
|
267
|
+
agree_if_custom('Would you like to open the project in your browser?(y/n) ', true) do
|
223
268
|
system "open #{new_repo.html_url}"
|
224
269
|
end
|
225
270
|
rescue => e
|
@@ -227,6 +272,28 @@ def create_project(target)
|
|
227
272
|
end
|
228
273
|
end
|
229
274
|
|
275
|
+
def execute(command, wait_response: false)
|
276
|
+
say(command) if $verbose
|
277
|
+
wait_response ? `#{command}` : system(command)
|
278
|
+
end
|
279
|
+
|
280
|
+
def ask_if_custom(question, default)
|
281
|
+
if $custom
|
282
|
+
ask(question) {|q| q.default = default }
|
283
|
+
else
|
284
|
+
default
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def agree_if_custom(*args, &block)
|
289
|
+
raise LocalJumpError unless block_given?
|
290
|
+
if $custom
|
291
|
+
yield if agree(*args)
|
292
|
+
else
|
293
|
+
yield
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
230
297
|
def repo_attributes
|
231
298
|
{
|
232
299
|
has_issues: true,
|
data/lib/zd_hire/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zd_hire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Angelim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|