fgi 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/fgi +7 -3
- data/lib/fgi/configuration.rb +45 -10
- data/lib/fgi/git_service.rb +91 -4
- data/lib/fgi/git_services/gitlab.rb +2 -1
- data/lib/fgi/http_requests.rb +2 -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: 2c10109eb480ab557f79d477ff770b7b4113d079
|
4
|
+
data.tar.gz: a718badc264ab8b9483e11ec76082db9a04aac99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eab634762636cc11025a56296c9b20e3e8d767935c245db69acefc7313b8ed02646d1660737343d50bc71d75ac128d2cb775127777c6166745281ba78633a44
|
7
|
+
data.tar.gz: ce9f2d259e89d34e3ee9fb822d0b0dfa6516f71cf91b74d3a5f51dbffed28aea0ddf7077125d4cf567f789506586a3a390365b01992fe6ff14f77489b85cd12e
|
data/bin/fgi
CHANGED
@@ -14,17 +14,21 @@ options_parser = OptionParser.new do |fgi|
|
|
14
14
|
fgi.banner = 'Usage: fgi COMMAND [OPTION]'
|
15
15
|
fgi.separator ''
|
16
16
|
fgi.separator 'Commands'
|
17
|
-
fgi.separator ' config : run the
|
17
|
+
fgi.separator ' config : run the FGI configurator.'
|
18
18
|
fgi.separator ' token [TOKEN] : define the new user token.'
|
19
19
|
fgi.separator ' new [ISSUE_NAME] : create the issue with the given name.'
|
20
20
|
fgi.separator ' ... more comming soon ...'
|
21
21
|
fgi.separator ''
|
22
22
|
fgi.separator 'Options'
|
23
23
|
|
24
|
-
fgi.on('-e', '--estimate ESTIMATION', 'How many time do you think you will spend on this issue ?') do |estimate|
|
24
|
+
fgi.on('-e', '--estimate [ESTIMATION]', 'How many time do you think you will spend on this issue ? (example: 1d13h37m05s)') do |estimate|
|
25
25
|
options[:estimate] = estimate
|
26
26
|
end
|
27
27
|
|
28
|
+
fgi.on('-l', '--later', 'Tell FGI that you anly want to create an issue but not to create and switch branch.') do
|
29
|
+
options[:later] = true
|
30
|
+
end
|
31
|
+
|
28
32
|
fgi.on('-h', '--help', 'Display the FGI manual') do
|
29
33
|
puts options_parser
|
30
34
|
end
|
@@ -51,7 +55,7 @@ when 'new'
|
|
51
55
|
exit!
|
52
56
|
end
|
53
57
|
title = get_full_issue_title(argv)
|
54
|
-
Fgi::GitService.create_issue(title)
|
58
|
+
Fgi::GitService.create_issue(title: title, options: options)
|
55
59
|
when 'token'
|
56
60
|
Fgi.configured?
|
57
61
|
Fgi::Tokens.add_token(argv[1])
|
data/lib/fgi/configuration.rb
CHANGED
@@ -28,17 +28,22 @@ module Fgi
|
|
28
28
|
# :routes
|
29
29
|
# :project_id
|
30
30
|
# :project_slug
|
31
|
+
# :default_branch
|
31
32
|
config = {}
|
32
33
|
|
33
34
|
config[:git_service_class] = define_git_service
|
34
35
|
config[:url] = save_git_url
|
35
36
|
|
36
37
|
# Instanciation of the Git service class
|
38
|
+
# TODO - HARD REFECTO NEEDED HERE...
|
37
39
|
git_service = config[:git_service_class].new(config: config)
|
38
40
|
config[:git_service] = git_service.to_sym
|
39
41
|
user_token = save_user_token(git_service)
|
40
42
|
project_name_and_id = define_project_name_and_id(git_service, user_token)
|
41
43
|
config = config.merge(project_name_and_id)
|
44
|
+
git_service = config[:git_service_class].new(config: config)
|
45
|
+
config[:default_branch] = define_default_branch(git_service, user_token)
|
46
|
+
|
42
47
|
|
43
48
|
# -------------------------- #
|
44
49
|
# CREATORS #
|
@@ -110,7 +115,12 @@ module Fgi
|
|
110
115
|
input = STDIN.gets.chomp
|
111
116
|
exit! if input == 'quit'
|
112
117
|
# force scheme if not specified
|
113
|
-
|
118
|
+
# TODO - Find a way to clear this... Find the correct scheme.
|
119
|
+
input = if input.start_with?('gitlab.com')
|
120
|
+
"https://#{input}"
|
121
|
+
elsif !input.start_with?('http://', 'https://')
|
122
|
+
"http://#{input}"
|
123
|
+
end
|
114
124
|
# Call the entered url to know if it exist or not.
|
115
125
|
# If not, would raise an exception
|
116
126
|
get(url: input)
|
@@ -145,6 +155,7 @@ module Fgi
|
|
145
155
|
exit! if input == 'quit'
|
146
156
|
|
147
157
|
url = "#{git_service.routes[:search_projects]}#{input}"
|
158
|
+
|
148
159
|
response = get(url: url, headers: { git_service.token_header => user_token })
|
149
160
|
|
150
161
|
if response[:status] == '200' && !response[:body].empty?
|
@@ -153,7 +164,13 @@ module Fgi
|
|
153
164
|
puts "#{index+1} - #{project['name_with_namespace']}"
|
154
165
|
end
|
155
166
|
|
156
|
-
|
167
|
+
puts "\nPlease insert the number of the current project :"
|
168
|
+
puts '-------------------------------------------------'
|
169
|
+
input = validate_choice(response[:body])
|
170
|
+
{
|
171
|
+
project_slug: response[:body][input - 1]['path_with_namespace'],
|
172
|
+
project_id: response[:body][input - 1]['id']
|
173
|
+
}
|
157
174
|
|
158
175
|
else
|
159
176
|
puts "\nOops, we couldn't find a project called #{input}. Try again or quit (quit) :"
|
@@ -165,21 +182,39 @@ module Fgi
|
|
165
182
|
end
|
166
183
|
end
|
167
184
|
|
185
|
+
def define_default_branch(git_service, user_token)
|
186
|
+
puts "\nPlease define the default project branch :"
|
187
|
+
puts '------------------------------------------'
|
188
|
+
|
189
|
+
url = "#{git_service.routes[:branches]}"
|
190
|
+
response = get(url: url, headers: { git_service.token_header => user_token })
|
191
|
+
|
192
|
+
if response[:status] == '200' && !response[:body].empty?
|
193
|
+
begin
|
194
|
+
response[:body].each_with_index do |branch, index|
|
195
|
+
puts "#{index+1} - #{branch['name']}"
|
196
|
+
end
|
197
|
+
|
198
|
+
puts "\nPlease insert the number of the default project branch :"
|
199
|
+
puts '--------------------------------------------------------'
|
200
|
+
input = validate_choice(response[:body])
|
201
|
+
response[:body][input - 1]['name']
|
202
|
+
|
203
|
+
rescue Interrupt => int
|
204
|
+
exit!
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
168
208
|
|
169
|
-
def
|
170
|
-
puts "\nPlease insert the number of the current project :"
|
171
|
-
puts '---------------------------------------------------'
|
209
|
+
def validate_choice(response_body)
|
172
210
|
input = STDIN.gets.chomp
|
173
211
|
exit! if input == 'quit'
|
174
212
|
input = input.to_i
|
175
213
|
if (1..response_body.count).include?(input)
|
176
|
-
|
177
|
-
project_slug: response_body[input - 1]['path_with_namespace'],
|
178
|
-
project_id: response_body[input - 1]['id']
|
179
|
-
}
|
214
|
+
input
|
180
215
|
else
|
181
216
|
puts "\nSorry, the option is out of range. Try again :"
|
182
|
-
|
217
|
+
validate_choice(response_body)
|
183
218
|
end
|
184
219
|
end
|
185
220
|
|
data/lib/fgi/git_service.rb
CHANGED
@@ -12,7 +12,7 @@ module Fgi
|
|
12
12
|
services
|
13
13
|
end
|
14
14
|
|
15
|
-
def create_issue(title)
|
15
|
+
def create_issue(title: title, options: {})
|
16
16
|
git_service = CONFIG[:git_service_class].new
|
17
17
|
title = get_issue_title if title.nil?
|
18
18
|
description = get_issue_description
|
@@ -21,8 +21,63 @@ module Fgi
|
|
21
21
|
url_with_querystring = "#{git_service.routes[:issues]}?title=#{URI.encode(title)}&description=#{URI.encode(description)}"
|
22
22
|
|
23
23
|
response = post(url: url_with_querystring, headers: headers)
|
24
|
+
response_body = JSON.parse(response[:body])
|
24
25
|
|
25
|
-
post_issue_display(
|
26
|
+
post_issue_display(response_body)
|
27
|
+
|
28
|
+
if CONFIG[:default_branch].nil?
|
29
|
+
puts "\n/!\\ FGI IS NOT UP-TO-DATE /!\\"
|
30
|
+
puts 'We are not able to create and switch you to the new branch.'
|
31
|
+
puts 'Delete .config.fgi.yml and reconfigure fgi by running `fgi config`'
|
32
|
+
else
|
33
|
+
create_new_branch(title) unless response_body['iid'].nil? || options[:later]
|
34
|
+
end
|
35
|
+
|
36
|
+
unless options[:estimate].nil?
|
37
|
+
# Since GitLab version isn't up to date, we should be able to add estimations in issues comments (/estimate)
|
38
|
+
url_with_querystring = "#{git_service.routes[:issues]}/#{response_body['iid']}/time_estimate?duration=#{options[:estimate]}"
|
39
|
+
response = post(url: url_with_querystring, headers: headers)
|
40
|
+
# GitLab sucks sometimes... This API is an example
|
41
|
+
begin
|
42
|
+
response_body = JSON.parse(response[:body])
|
43
|
+
rescue Exception => e
|
44
|
+
response_body = response[:body]
|
45
|
+
end
|
46
|
+
|
47
|
+
post_estimation_display(response_body, options[:estimate])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_new_branch(issue_title)
|
52
|
+
branch_name = snakecase(issue_title)
|
53
|
+
unless %x(git status -s).empty?
|
54
|
+
begin
|
55
|
+
puts "\nThere are unsaved changes on your current branch."
|
56
|
+
puts "Do you want to see them ? (y/n)"
|
57
|
+
puts '-------------------------------'
|
58
|
+
input = STDIN.gets.chomp
|
59
|
+
system('git diff') if %w[y yes].include?(input)
|
60
|
+
|
61
|
+
puts "\nDo you want to COMMIT theses changes ? (y/n)"
|
62
|
+
puts '--------------------------------------------'
|
63
|
+
input = STDIN.gets.chomp
|
64
|
+
if %w[y yes].include?(input)
|
65
|
+
commit_changes
|
66
|
+
else
|
67
|
+
stash_changes
|
68
|
+
end
|
69
|
+
|
70
|
+
rescue Interrupt => int
|
71
|
+
puts %q"Why did you killed me ? :'("
|
72
|
+
exit!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
%x(git checkout #{CONFIG[:default_branch]}) # Be sure to be on the default branch.
|
76
|
+
from = %x(git branch | grep '*').gsub('* ', '').chomp
|
77
|
+
%x(git pull origin HEAD) # Be sure to get the remote changes locally.
|
78
|
+
%x(git checkout -b #{branch_name}) # Create the new branch.
|
79
|
+
to = %x(git branch | grep '*').gsub('* ', '').chomp
|
80
|
+
puts "\nYou are now working on branch #{to} created from #{from} !"
|
26
81
|
end
|
27
82
|
|
28
83
|
private
|
@@ -50,16 +105,48 @@ module Fgi
|
|
50
105
|
end
|
51
106
|
|
52
107
|
def post_issue_display(response)
|
53
|
-
|
108
|
+
unless response['iid'].nil?
|
54
109
|
puts 'Your issue has been successfully created.'
|
55
110
|
puts 'To view it, please follow the link bellow :'
|
56
111
|
puts "\n#{CONFIG[:url]}/#{CONFIG[:project_slug]}/issues/#{response['iid']}"
|
57
|
-
puts "\nThank you for using Fast Gitlab Issues!"
|
58
112
|
else
|
59
113
|
puts %q(Your issue couldn't be created. Check your FGI configuration.)
|
60
114
|
end
|
61
115
|
end
|
62
116
|
|
117
|
+
def post_estimation_display(response, estimation)
|
118
|
+
if response['human_time_estimate'].nil?
|
119
|
+
puts "\nWe weren't able to save your estimation."
|
120
|
+
puts "You'll have to do it manually on #{CONFIG[:git_service].capitalize}."
|
121
|
+
else
|
122
|
+
puts "\nYou have #{estimation} to resolve this issue. Good luck ;)"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def commit_changes
|
127
|
+
puts 'Enter your commit message :'
|
128
|
+
commit_message = STDIN.gets.chomp
|
129
|
+
%x(git add .)
|
130
|
+
%x(git commit -am '#{commit_message}')
|
131
|
+
puts 'Your changes have been commited !'
|
132
|
+
end
|
133
|
+
|
134
|
+
def stash_changes
|
135
|
+
%x(git add .)
|
136
|
+
%x(git stash)
|
137
|
+
puts "\nYour changes have been stashed."
|
138
|
+
puts "We will let you manually `git stash pop` to get your work back if needed.\n"
|
139
|
+
end
|
140
|
+
|
141
|
+
def snakecase(string)
|
142
|
+
string.gsub(/::/, '/').
|
143
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
144
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
145
|
+
tr('-', '_').
|
146
|
+
tr(' ', '_').
|
147
|
+
downcase
|
148
|
+
end
|
149
|
+
|
63
150
|
end
|
64
151
|
end
|
65
152
|
end
|
@@ -9,7 +9,8 @@ module Fgi
|
|
9
9
|
@routes = {
|
10
10
|
projects: "#{config[:url]}/api/#{@version}/projects",
|
11
11
|
search_projects: "#{config[:url]}/api/#{@version}/projects?search=",
|
12
|
-
issues: "#{config[:url]}/api/#{@version}/projects/#{config[:project_id]}/issues"
|
12
|
+
issues: "#{config[:url]}/api/#{@version}/projects/#{config[:project_id]}/issues",
|
13
|
+
branches: "#{config[:url]}/api/#{@version}/projects/#{config[:project_id]}/repository/branches"
|
13
14
|
}
|
14
15
|
end
|
15
16
|
|
data/lib/fgi/http_requests.rb
CHANGED
@@ -27,6 +27,7 @@ module Fgi
|
|
27
27
|
# @param body [Hash] the body to set for the request
|
28
28
|
# @return [String] the received response from the Git service API
|
29
29
|
def http_request(verb:, url:, headers: nil, body: nil)
|
30
|
+
is_https = url.start_with?('https')
|
30
31
|
uri = URI.parse(url)
|
31
32
|
req = case verb
|
32
33
|
when :get
|
@@ -40,7 +41,7 @@ module Fgi
|
|
40
41
|
# Set body if given
|
41
42
|
req.body = body.to_json unless body.nil?
|
42
43
|
|
43
|
-
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
44
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: is_https) do |http|
|
44
45
|
http.request(req)
|
45
46
|
end
|
46
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fgi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Philibin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|