Class: Fgi::GitService
- Inherits:
-
Object
- Object
- Fgi::GitService
- Extended by:
- HttpRequests
- Defined in:
- lib/fgi/git_service.rb
Class Method Summary collapse
- .current_branch ⇒ Object
-
.fix_issue(options) ⇒ Object
All the process initiated by the issue fix => Commiting with a ‘Fix #<id>’ message => Pushing the current branch to the remote repo => Return to the default project branch.
-
.new_issue(title:, options: {}) ⇒ Object
All the process initiated by the issue creation => Create issue => Create a new branch from the default one => Set the issue estimation time.
-
.services ⇒ Array<String>
An array containing all the git services available.
-
.set_issue_time_trackers(issue_id:, duration:, git_service:, tracker:) ⇒ Object
TODO, Make sure it works for all git services The method to set the estimation time to resolve the issue.
Methods included from HttpRequests
Class Method Details
.current_branch ⇒ Object
107 108 109 |
# File 'lib/fgi/git_service.rb', line 107 def current_branch `git branch | grep '*'`.gsub('* ', '').chomp end |
.fix_issue(options) ⇒ Object
All the process initiated by the issue fix
=> Commiting with a 'Fix #<id>' message
=> Pushing the current branch to the remote repo
=> Return to the default project branch
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 |
# File 'lib/fgi/git_service.rb', line 54 def fix_issue() if ISSUES[current_branch].nil? puts "We could not find any issues to fix on your current branch (#{current_branch})." exit! end set_spent_time(options: , issue_id: ISSUES[current_branch][:id]) git_remote = ask_for_remote `git add .` puts "Are you sure to want to close the issue #{ISSUES[current_branch][:title]} ?" begin input = STDIN.gets.chomp if %w[y yes].include?(input) = "Fix ##{ISSUES[current_branch][:id]}" += " - #{[:fix_message]}" unless [:fix_message].nil? `git commit -a --allow-empty -m '#{}'` `git push #{git_remote} HEAD` `git branch -u #{git_remote}/#{ISSUES[current_branch]}` # Define the upstream branch `git checkout #{CONFIG[:default_branch]}` # Be sure to be on the default branch. remove_issue(current_branch) puts "Congrat's ! You're now back to work on the default branch (#{CONFIG[:default_branch]})" end rescue Interrupt puts %q"Why did you killed me ? :'(" exit! end end |
.new_issue(title:, options: {}) ⇒ Object
All the process initiated by the issue creation
=> Create issue
=> Create a new branch from the default one
=> Set the issue estimation time
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 |
# File 'lib/fgi/git_service.rb', line 23 def new_issue(title:, options: {}) git_service = CONFIG[:git_service_class].new title = get_issue_title if title.nil? response = create_issue(title: title, git_service: git_service) if CONFIG[:default_branch].nil? puts "\n/!\\ FGI IS NOT UP-TO-DATE /!\\" puts 'We are not able to create and switch you to the new branch.' puts 'Delete .config.fgi.yml and reconfigure fgi by running `fgi config`' elsif !response['iid'].nil? branch_name = snakify(title) branch_name = "#{[:prefix]}/#{branch_name}" unless [:prefix].nil? save_issue(branch: branch_name, id: response['iid'], title: response['title'].tr("'", ' ').tr('_', ' ')) create_branch(name: branch_name, from_current: [:from_current]) unless [:later] unless [:duration].nil? res = set_issue_time_trackers( issue_id: response['iid'], duration: [:duration], git_service: git_service, tracker: :estimate ) post_estimation_display(res['human_time_estimate'], [:duration]) end end end |
.services ⇒ Array<String>
Returns an array containing all the git services available.
9 10 11 12 13 14 15 |
# File 'lib/fgi/git_service.rb', line 9 def services services = [] Dir.entries("#{File.dirname(__FILE__)}/git_services").each do |service| services << service.gsub(/.rb/, '').to_sym unless %w[. ..].include?(service) end services end |
.set_issue_time_trackers(issue_id:, duration:, git_service:, tracker:) ⇒ Object
TODO, Make sure it works for all git services The method to set the estimation time to resolve the issue
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fgi/git_service.rb', line 87 def set_issue_time_trackers(issue_id:, duration:, git_service:, tracker:) return if duration.nil? || !%i[estimate spent].include?(tracker) # Since GitLab version isn't up to date, we should be able # to add estimations and spent time in issues comments (/estimate, /spent) api = if tracker == :spent 'add_spent_time' else 'time_estimate' end url_with_querystring = "#{git_service.routes[:issues]}/#{issue_id}/#{api}?duration=#{duration}" headers = { git_service.token_header => TOKEN, 'Content-Type' => 'application/json' } response = post(url: url_with_querystring, headers: headers) # GitLab sucks sometimes... This API is an example begin JSON.parse(response[:body]) rescue Exception response[:body] end end |