Class: PullRequestTemplates::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/pull_request_templates/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Set exit_on_failure to ensure Thor exits with non-zero status on errors

Returns:

  • (Boolean)


8
# File 'lib/pull_request_templates/cli.rb', line 8

def self.exit_on_failure? = true

Instance Method Details

#pr_urlObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pull_request_templates/cli.rb', line 11

def pr_url
  # Find all available templates
  templates = get_available_templates

  if templates.empty?
    raise Thor::Error, "No templates found"
  end

  # Check if we're on the default branch
  current_branch = `git rev-parse --abbrev-ref HEAD`.strip

  if current_branch == "main"
    raise Thor::Error, "Cannot generate PR URL while on default branch"
  end

  # Check if there are any changes to detect
  changes = get_changes

  if changes.empty?
    raise Thor::Error, "No changes detected"
  end

  # Select appropriate template
  template = select_template(templates, changes)

  # Generate the pull request URL
  url = generate_pr_url(current_branch, template)
  say url
end