fgi 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/fgi +7 -3
  3. data/lib/fgi.rb +1 -1
  4. data/lib/fgi/git_service.rb +47 -17
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d59a2d5cf5f06e8ac7234bd5e997f2979dee1c23
4
- data.tar.gz: 87c72213d77138f9f9e2f962763d08c2c75cf310
3
+ metadata.gz: 91922d15f334ba84772f933b85794b8684e0e26a
4
+ data.tar.gz: ad27509e51ffc44569ca6baa93023770b9988621
5
5
  SHA512:
6
- metadata.gz: 80a6daec4ed632e0ab6a8c73cfeabad5592c3fa7c67cbde92e42557d76c49a32a96632bce0b79ea362483d8f11a7d034fecd64321b7eef41b3485ac8e783888b
7
- data.tar.gz: f443b71afe99c46d12b2bd9f305d7aed2c1f806142f3013473df725fe4540f580344354d328dcfcf0063dcfac2d366d126c5b0bdacd8aeb97c5c0a7090a3448d
6
+ metadata.gz: af1d05fc79eb0889510fd949c6206ef0d48de344fb904b0e13e37fa5f372dfeb3a018326fb4987ffaa32c76998907630064f17bce1de8c96149250c3e7f488e9
7
+ data.tar.gz: 6d3fd9699f8b44ddbbff1e450f82f6ca5bd13a067b5e0082fa312b6e8a4b042f1229b656199172d8d87d8df0577ab621159ef98b719c5f4daa5c98e3e084e7fa
data/bin/fgi CHANGED
@@ -19,7 +19,7 @@ options_parser = OptionParser.new do |fgi|
19
19
  # NEW
20
20
  fgi.separator "\nfgi new [ISSUE_NAME] [OPTIONS] : create the issue with the given name.\n\n"
21
21
  fgi.on('-e', '--estimate [ESTIMATION]', 'How many time do you think you will spend on this issue ? (example: 1d13h37m05s)') do |estimate|
22
- options[:estimate] = estimate
22
+ options[:duration] = estimate
23
23
  end
24
24
  fgi.on('-l', '--later', 'Tell FGI that you only want to create an issue but not to create and switch branch.') do
25
25
  options[:later] = true
@@ -35,6 +35,9 @@ options_parser = OptionParser.new do |fgi|
35
35
  fgi.on('-m', '--fix-message [MESSAGE]', %q(Add a custom message with the basic 'Fix #ID')) do |message|
36
36
  options[:fix_message] = message
37
37
  end
38
+ fgi.on('-s', '--spent [SPENT_TIME]', 'How many time have you spent on this issue ? (example: 1d13h37m05s)') do |spent|
39
+ options[:duration] = spent
40
+ end
38
41
  # CURRENT
39
42
  fgi.separator "\nfgi current [OPTIONS] : display the current branch and issue."
40
43
  fgi.separator "\n -e, --estimate [ESTIMATION] Add/rewrite the estimation time on the current issue. See 'fgi new' options."
@@ -77,8 +80,9 @@ when 'fix'
77
80
  when 'current'
78
81
  current_branch = Fgi::GitService.current_branch
79
82
  puts "Current branch : #{current_branch}"
80
- if (defined? Fgi::ISSUES) && !options[:estimate].nil?
81
- Fgi::GitService.set_issue_estimation(issue_id: Fgi::ISSUES[current_branch][:id], estimation: options[:estimate], git_service: Fgi::CONFIG[:git_service_class].new)
83
+ if (defined? Fgi::ISSUES) && !options[:duration].nil?
84
+ res = Fgi::GitService.set_issue_time_trackers(issue_id: Fgi::ISSUES[current_branch][:id], duration: options[:duration], git_service: Fgi::CONFIG[:git_service_class].new, tracker: :estimate)
85
+ post_estimation_display(res['human_time_estimate'], options[:duration])
82
86
  exit!
83
87
  elsif Fgi::ISSUES
84
88
  puts "Current issue : #{Fgi::ISSUES[current_branch][:title]}" || 'This branch do not match any FGI issue.'
data/lib/fgi.rb CHANGED
@@ -14,7 +14,7 @@ module Fgi
14
14
  require_relative 'fgi/configuration'
15
15
  require_relative 'fgi/git_service'
16
16
 
17
- VERSION = '1.1.5'.freeze
17
+ VERSION = '1.1.6'.freeze
18
18
 
19
19
  # Add FGI user's current issues to the gitignore
20
20
  if `cat .gitignore | grep '.current_issues.fgi.yml'`.empty?
@@ -34,11 +34,15 @@ module Fgi
34
34
  branch_name = "#{options[:prefix]}/#{branch_name}" unless options[:prefix].nil?
35
35
  save_issue(branch: branch_name, id: response['iid'], title: response['title'].tr("'", ' ').tr('_', ' '))
36
36
  create_branch(name: branch_name, from_current: options[:from_current]) unless options[:later]
37
- set_issue_estimation(
38
- issue_id: response['iid'],
39
- estimation: options[:estimate],
40
- git_service: git_service
41
- )
37
+ unless options[:duration].nil?
38
+ res = set_issue_time_trackers(
39
+ issue_id: response['iid'],
40
+ duration: options[:duration],
41
+ git_service: git_service,
42
+ tracker: :estimate
43
+ )
44
+ post_estimation_display(res['human_time_estimate'], options[:duration])
45
+ end
42
46
  end
43
47
  end
44
48
 
@@ -52,6 +56,7 @@ module Fgi
52
56
  puts "We could not find any issues to fix on your current branch (#{current_branch})."
53
57
  exit!
54
58
  end
59
+ set_spent_time(options: options, issue_id: ISSUES[current_branch][:id])
55
60
  git_remote = ask_for_remote
56
61
  `git add .`
57
62
  puts "Are you sure to want to close the issue #{ISSUES[current_branch][:title]} ?"
@@ -62,7 +67,7 @@ module Fgi
62
67
  commit_message += " - #{options[:fix_message]}" unless options[:fix_message].nil?
63
68
  `git commit -a --allow-empty -m '#{commit_message}'`
64
69
  `git push #{git_remote} HEAD`
65
- `git branch -u #{git_remote}/#{name}` # Define the upstream branch
70
+ `git branch -u #{git_remote}/#{ISSUES[current_branch]}` # Define the upstream branch
66
71
  `git checkout #{CONFIG[:default_branch]}` # Be sure to be on the default branch.
67
72
  remove_issue(current_branch)
68
73
  puts "Congrat's ! You're now back to work on the default branch (#{CONFIG[:default_branch]})"
@@ -73,29 +78,34 @@ module Fgi
73
78
  end
74
79
  end
75
80
 
76
- def current_branch
77
- `git branch | grep '*'`.gsub('* ', '').chomp
78
- end
79
-
80
81
  # TODO, Make sure it works for all git services
81
82
  # The method to set the estimation time to resolve the issue
82
83
  # @param issue_id [Integer] the issue id to set its estimation time
83
84
  # @param estimation [String] the estimation time given by the user
84
85
  # @param git_service [Class] the git service class to use for this project
85
- def set_issue_estimation(issue_id:, estimation:, git_service:)
86
- return if estimation.nil?
86
+ # @param tracker [Symbol] the tracker to set. Can be :estimate or :spent
87
+ def set_issue_time_trackers(issue_id:, duration:, git_service:, tracker:)
88
+ return if duration.nil? || !%i[estimate spent].include?(tracker)
87
89
  # Since GitLab version isn't up to date, we should be able
88
- # to add estimations in issues comments (/estimate)
89
- url_with_querystring = "#{git_service.routes[:issues]}/#{issue_id}/time_estimate?duration=#{estimation}"
90
+ # to add estimations and spent time in issues comments (/estimate, /spent)
91
+ api = if tracker == :spent
92
+ 'add_spent_time'
93
+ else
94
+ 'time_estimate'
95
+ end
96
+ url_with_querystring = "#{git_service.routes[:issues]}/#{issue_id}/#{api}?duration=#{duration}"
90
97
  headers = { git_service.token_header => TOKEN, 'Content-Type' => 'application/json' }
91
98
  response = post(url: url_with_querystring, headers: headers)
92
99
  # GitLab sucks sometimes... This API is an example
93
100
  begin
94
- response_body = JSON.parse(response[:body])
101
+ JSON.parse(response[:body])
95
102
  rescue Exception
96
- response_body = response[:body]
103
+ response[:body]
97
104
  end
98
- post_estimation_display(response_body['human_time_estimate'], estimation)
105
+ end
106
+
107
+ def current_branch
108
+ `git branch | grep '*'`.gsub('* ', '').chomp
99
109
  end
100
110
 
101
111
  private
@@ -127,6 +137,17 @@ module Fgi
127
137
  end
128
138
  end
129
139
 
140
+ def set_spent_time(options:, issue_id:)
141
+ return if options[:duration].nil?
142
+ res = set_issue_time_trackers(
143
+ issue_id: issue_id,
144
+ duration: options[:duration],
145
+ git_service: CONFIG[:git_service_class].new,
146
+ tracker: :spent
147
+ )
148
+ post_spent_display(res['human_time_estimate'], options[:duration])
149
+ end
150
+
130
151
  # Save the current user's FGI created issue in the gitignored file 'current_issue.fgi.yml'
131
152
  # @param id [Integer] the current issue id
132
153
  # @param title [String] the current issue name
@@ -238,6 +259,15 @@ module Fgi
238
259
  end
239
260
  end
240
261
 
262
+ def post_spent_display(response_spent, spent_time)
263
+ if response_spent.nil?
264
+ puts "\nWe weren't able to save your spent time."
265
+ puts "You'll have to do it manually on #{CONFIG[:git_service].capitalize}."
266
+ else
267
+ puts "\nYou have spent #{spent_time} on this issue."
268
+ end
269
+ end
270
+
241
271
  # The method used to commit the user's local changes
242
272
  def commit_changes
243
273
  puts 'Enter your commit message :'
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.1.5
4
+ version: 1.1.6
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-10-09 00:00:00.000000000 Z
12
+ date: 2017-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler