Class: GitHelper::LocalCode
- Inherits:
-
Object
- Object
- GitHelper::LocalCode
- Defined in:
- lib/git_helper/local_code.rb
Instance Method Summary collapse
- #branch ⇒ Object
- #default_branch(project_name, external_client, client_type) ⇒ Object
- #generate_title(local_branch) ⇒ Object
- #name ⇒ Object
- #new_branch(branch_name) ⇒ Object
- #read_template(file_name) ⇒ Object
- #template_options(template_identifiers) ⇒ Object
Instance Method Details
#branch ⇒ Object
15 16 17 18 |
# File 'lib/git_helper/local_code.rb', line 15 def branch # Get the current branch by looking in the list of branches for the * `git branch`.scan(/\*\s([\S]*)/).first.first end |
#default_branch(project_name, external_client, client_type) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git_helper/local_code.rb', line 20 def default_branch(project_name, external_client, client_type) if client_type == :octokit # GitHub repository external_client.repository(project_name).default_branch elsif client_type == :gitlab # GitLab project page_number = 1 counter = 1 branches = [] while counter > 0 break if default_branch = branches.select { |branch| branch.default }.first page_branches = external_client.branches(project_name, page: page_number, per_page: 100) branches = page_branches counter = page_branches.count page_number += 1 end default_branch.name end end |
#generate_title(local_branch) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/git_helper/local_code.rb', line 56 def generate_title(local_branch) branch_arr = local_branch.split(local_branch.include?('_') ? '_' : '-') return if branch_arr.empty? if branch_arr.length == 1 branch_arr.first.capitalize elsif branch_arr[0].scan(/([\w]+)/).any? && branch_arr[1].scan(/([\d]+)/).any? # branch includes jira_123 at beginning issue = "#{branch_arr[0].upcase}-#{branch_arr[1]}" description = branch_arr[2..-1].join(' ') "#{issue} #{description.capitalize}" elsif branch_arr[0].scan(/([\w]+-[\d]+)/).any? # branch includes string jira-123 at beginning issue = branch_arr[0].upcase description = branch_arr[1..-1].join(' ') "#{issue} #{description.capitalize}" else # plain words branch_arr[0..-1].join(' ').capitalize end end |
#name ⇒ Object
10 11 12 13 |
# File 'lib/git_helper/local_code.rb', line 10 def name # Get the repo/project name by looking in the remote URLs for the full name `git remote -v`.scan(/\S[\s]*[\S]+.com[\S]{1}([\S]*).git/).first.first end |
#new_branch(branch_name) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/git_helper/local_code.rb', line 3 def new_branch(branch_name) system("git pull") system("git branch --no-track #{branch_name}") system("git checkout #{branch_name}") system("git push --set-upstream origin #{branch_name}") end |
#read_template(file_name) ⇒ Object
52 53 54 |
# File 'lib/git_helper/local_code.rb', line 52 def read_template(file_name) File.open(file_name).read end |
#template_options(template_identifiers) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/git_helper/local_code.rb', line 40 def (template_identifiers) nested_templates = Dir.glob( File.join("**/#{template_identifiers[:nested_directory_name]}", "*.md"), File::FNM_DOTMATCH | File::FNM_CASEFOLD ) non_nested_templates = Dir.glob( File.join("**", "#{template_identifiers[:non_nested_file_name]}.md"), File::FNM_DOTMATCH | File::FNM_CASEFOLD ) nested_templates.concat(non_nested_templates).uniq end |