Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/wralph/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def respond_to_missing?(method_name, include_private = false)

def default_hash
{
'repo' => {
'branch_name' => "issue-\#{identifier}"
},
'objective_repository' => {
'source' => 'github_issues'
},
Expand Down
6 changes: 6 additions & 0 deletions lib/wralph/fixtures/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# WRALPH Configuration
# Configure which adapters to use for different components

# Repository settings
repo:
# Branch name template for generated branches
# Uses #{identifier} as a placeholder for the issue number
branch_name: "issue-#{identifier}"

# Where the objectives, PRDs, or other issue write-ups are stored.
objective_repository:
# You can specify a "custom" source, just provide a class that implements
Expand Down
8 changes: 8 additions & 0 deletions lib/wralph/interfaces/repo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require_relative 'shell'
require_relative '../config'
require_relative '../utils'

module Wralph
module Interfaces
Expand Down Expand Up @@ -78,6 +80,12 @@ def self.get_pr_from_branch_name(branch_name)
pr_number = stdout.strip
pr_number.empty? || pr_number == 'null' ? nil : pr_number
end

def self.branch_name(identifier)
config = Config.load
template = config.repo&.branch_name || "issue-\#{identifier}"
Utils.prompt_sub(template, identifier: identifier)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/wralph/run/act_on_ci_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Wralph
module Run
module ActOnCIResults
def self.run(issue_number)
branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)

# Check current branch to return to later
stdout, = Interfaces::Shell.run_command('git branch --show-current')
Expand Down
2 changes: 1 addition & 1 deletion lib/wralph/run/execute_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.run(issue_number)
plan_file = Interfaces::Repo.plan_file(issue_number)
plan_exists = File.exist?(plan_file)

branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)
stdout, = Interfaces::Shell.run_command('git branch --show-current')
current_branch = stdout.strip

Expand Down
2 changes: 1 addition & 1 deletion lib/wralph/run/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Feedback
def self.run(issue_number)
Init.ensure_initialized!

branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)
plan_file = Interfaces::Repo.plan_file(issue_number)

stdout, = Interfaces::Shell.run_command('git branch --show-current')
Expand Down
2 changes: 1 addition & 1 deletion lib/wralph/run/iterate_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module IterateCI
MAX_RETRIES = 10

def self.run(issue_number, pr_number = nil)
branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)
pr_number ||= Interfaces::Repo.get_pr_from_branch_name(branch_name)

stdout, = Interfaces::Shell.run_command('git branch --show-current')
Expand Down
2 changes: 1 addition & 1 deletion lib/wralph/run/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.run(issue_number)
Init.ensure_initialized!

plan_file = Interfaces::Repo.plan_file(issue_number)
branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)

# Ensure plans directory exists
FileUtils.mkdir_p(Interfaces::Repo.plans_dir)
Expand Down
2 changes: 1 addition & 1 deletion lib/wralph/run/remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Remove
def self.run(issue_number)
Init.ensure_initialized!

branch_name = "issue-#{issue_number}".freeze
branch_name = Interfaces::Repo.branch_name(issue_number)

# Delete local branch
_, _, success = Interfaces::Shell.run_command("git branch -D #{branch_name}")
Expand Down
57 changes: 57 additions & 0 deletions spec/lib/wralph/interfaces/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,61 @@
expect(Wralph::Interfaces::Repo.secrets_file).to eq(expected_path)
end
end

describe '.branch_name' do
before do
Wralph::Config.reset
end

it 'uses default template when no config exists' do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p(File.join(tmpdir, '.git'))

Dir.chdir(tmpdir) do
result = Wralph::Interfaces::Repo.branch_name('123')
expect(result).to eq('issue-123')
end
end
end

it 'uses custom template from config' do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p(File.join(tmpdir, '.git'))
wralph_dir = File.join(tmpdir, '.wralph')
FileUtils.mkdir_p(wralph_dir)

config_data = {
'repo' => {
'branch_name' => "feature/ticket-\#{identifier}"
}
}
File.write(File.join(wralph_dir, 'config.yaml'), config_data.to_yaml)

Dir.chdir(tmpdir) do
result = Wralph::Interfaces::Repo.branch_name('456')
expect(result).to eq('feature/ticket-456')
end
end
end

it 'handles template with multiple variables' do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p(File.join(tmpdir, '.git'))
wralph_dir = File.join(tmpdir, '.wralph')
FileUtils.mkdir_p(wralph_dir)

config_data = {
'repo' => {
'branch_name' => "bugfix-\#{identifier}"
}
}
File.write(File.join(wralph_dir, 'config.yaml'), config_data.to_yaml)

Dir.chdir(tmpdir) do
result = Wralph::Interfaces::Repo.branch_name('789')
expect(result).to eq('bugfix-789')
end
end
end
end
end
3 changes: 3 additions & 0 deletions spec/lib/wralph/run/execute_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
allow(Wralph::Interfaces::Shell).to receive(:run_command)
.with('git branch --show-current')
.and_return(['master', '', true])

# Mock Repo.branch_name to return the expected branch name
allow(Wralph::Interfaces::Repo).to receive(:branch_name).with(issue_number).and_return(branch_name)
end

context 'when plan file does not exist' do
Expand Down