40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/stagecoach/config.rb', line 40
def setup
CommandLine.line_break
puts "Stagecoach Initial Setup"
CommandLine.line_break
puts "You are running stagecoach from #{FileUtils.pwd.green}. Is this the root directory of your repository?"
puts "Stagecoach may not work properly anywhere else! So proceed with caution"
CommandLine.line_break
print "[C]ontinue or [Q]uit: "
case STDIN.gets.chomp
when /c/i
Config.check_if_outdated
Config.new unless File.exist?(CONFIG_FILE)
when /q/i
puts "Exiting..."
exit
end
loop do
if Git.global_config(:github, :user) == ""
print "Please enter your github username: "
case STDIN.gets.chomp
when ""
print "Github user can't be blank, please try again:"
redo
else
Git.set_global_config(:github, :user, $_.chomp) end
end
if Git.global_config(:github, :token) == ""
print "Please enter your Github api token (you can find this at http://github.com/account/admin): "
case STDIN.gets.chomp
when ""
print "Github API key can't be blank, please try again: "
redo
else
Git.set_global_config(:github, :token, $_.chomp)
end
end
break
end
source_dir = (File.dirname(__FILE__) + '/../githooks/')
install_dir = FileUtils.pwd + '/.git/hooks/'
git_hook = 'commit-msg'
CommandLine.line_break
puts "Would you like to install the stagecoach #{"commit-msg githook".green}?"
puts "This automatically references stagecoach-created github issues from each commit you make"
puts "Note that this will only affect branches created in stagecoach. For more information run stagecoach -h"
CommandLine.line_break
print "[I]nstall or [S]kip this step: "
loop do
case STDIN.gets.chomp
when /i/i
if File.exist?(install_dir + git_hook)
case FileUtils.compare_file(source_dir + git_hook, install_dir + git_hook)
when true
puts 'The stagecoach githook is already installed in this repo. Skipping this step...'
break
when false
puts "You have a commit-msg githook already. Are you sure you want to install? This will #{'overwrite'.red} your current commit-msg githook."
print "[O]K or anything else to skip installation: "
case STDIN.gets.chomp
when /o/i
Config.githook_install(source_dir, install_dir, git_hook)
break
else
break
end
end
else
puts "Installing..."
Config.githook_install(source_dir, install_dir, git_hook)
break
end
when /s/i
puts 'Skipping Installation.'
break
end
end
config = Config.yaml_to_hash
unless config["redmine_site"] && config["redmine_api_key"] && config["redmine_user_id"]
CommandLine.line_break
print "Enter your redmine/planio repository, eg. https://digitaleseiten.plan.io: "
redmine_site = STDIN.gets.chomp
print "Enter your API key for that repo: "
redmine_api_key = STDIN.gets.chomp
RedmineApi::Client.instance_eval do
self.site = config["redmine_site"] || redmine_site
self.user = config["redmine_api_key"] || redmine_api_key
end
all_users = Redmine.users
puts "ID | User Name"
all_users.each {|u| puts printf("%-5d",u.attributes["id"]).to_s + " | " + u.attributes["firstname"] + " " + u.attributes["lastname"]} rescue puts "This one"
puts "Which id is yours?"
user_id = STDIN.gets.chomp
Config.save({"redmine_site" => redmine_site, "redmine_api_key" => redmine_api_key, "redmine_user_id" => user_id.to_i })
CommandLine.line_break
puts "Settings saved OK:"
puts "Repository: " + redmine_site if redmine_site
puts "API Key: " + redmine_api_key if redmine_api_key
puts "User ID: " + user_id if user_id
CommandLine.line_break
end
puts "Complete! Exiting..."
exit
end
|