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_estimation(issue_id:, estimation:, git_service:) ⇒ 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
76 77 78 |
# File 'lib/fgi/git_service.rb', line 76 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>'
=> Pushing the current branch to the remote repo
=> Return to the default project branch
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 |
# File 'lib/fgi/git_service.rb', line 50 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 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]}" += " - #{options[:fix_message]}" unless [:fix_message].nil? `git commit -a --allow-empty -m '#{commit_message}'` `git push #{git_remote} HEAD` `git branch -u #{git_remote}/#{name}` # 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 |
# 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 = "#{options[: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] set_issue_estimation( issue_id: response['iid'], estimation: [:estimate], git_service: git_service ) 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_estimation(issue_id:, estimation:, git_service:) ⇒ Object
TODO, Make sure it works for all git services The method to set the estimation time to resolve the issue
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fgi/git_service.rb', line 85 def set_issue_estimation(issue_id:, estimation:, git_service:) return if estimation.nil? # Since GitLab version isn't up to date, we should be able # to add estimations in issues comments (/estimate) url_with_querystring = "#{git_service.routes[:issues]}/#{issue_id}/time_estimate?duration=#{estimation}" 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 response_body = JSON.parse(response[:body]) rescue Exception response_body = response[:body] end post_estimation_display(response_body['human_time_estimate'], estimation) end |