-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.rb
53 lines (41 loc) · 1.3 KB
/
setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'dotenv'
require 'pry'
require_relative 'helpers/input_helper'
require_relative 'helpers/gitlab_service'
Dotenv.load
module Setup
extend InputHelper
GITLAB_CONFIG = %w[
GITLAB_URL
GITLAB_TOKEN
GITLAB_DEV_IDS
]
def setup_credentials
if ENV['GITLAB_URL'].nil?
url = get_input("Please enter the Gitlab URL (for example https://gitlab.com/api/v4):")
write_to_env_file('GITLAB_URL', url)
end
if ENV['GITLAB_TOKEN'].nil?
token = get_input("Please enter the Gitlab TOKEN (generate it on https://gitlab.trainline.tools/-/profile/personal_access_tokens)")
write_to_env_file('GITLAB_TOKEN', token)
end
end
def setup_users
while get_letter_input("Do you want to find devs? (y/n)") == 'y'
user = get_input("Type his name:")
puts GitlabService.fetch_user(user).to_h
end
if get_letter_input("Do you want to setup the devs? (y/n)") == 'y'
users_list = get_input_list("Please type the Gitlab usernames (separated by ','):")
users = GitlabService.fetch_users(users_list)
write_to_env_file('GITLAB_DEV_IDS', users.to_s)
end
end
def run
setup_credentials
return puts "Please run setup again" if ENV['GITLAB_TOKEN'].nil?
setup_users
end
module_function :run, :setup_credentials, :setup_users
end
Setup.run