brainiac-basecamp 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8adcfd4dedeee9ee8fee1e9439e80f7f3917d81ece1c5420a3777619df8d7ab5
|
|
4
|
+
data.tar.gz: d88eb5a5e18d8bea39522ccfa6c8fbac13b2b50f87a28a29c6c1b8958e4f3eea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 311711ad321fe576e24aeb51d82d9dffc4b9d2b6199b8f6b6242b7405583f224d1686d4b91cc395d3e16985dd73834324cbe539fe216f2eb22962a4f34d05d2d
|
|
7
|
+
data.tar.gz: 7ccb5d585757a9b87b5dfa88512e44528048c153d4d5e159c4e62baa9c78f904dec5333899abdbaeec46b0a8da0ac6bfbd1cd39ca2530030f1d6e05e3a1d096c
|
|
@@ -156,10 +156,75 @@ module Brainiac
|
|
|
156
156
|
# If project is set, look up directly
|
|
157
157
|
return epic_branches[project_key] if project_key && epic_branches[project_key]
|
|
158
158
|
|
|
159
|
-
# Fallback: if there's only one epic branch
|
|
160
|
-
|
|
159
|
+
# Fallback: if there's only one epic branch AND the task has no specific project set,
|
|
160
|
+
# use it (assumed single-project epic).
|
|
161
|
+
# Do NOT fallback if the task has a specific project that isn't in epic_branches —
|
|
162
|
+
# that means the branch wasn't created for this repo and we should return nil
|
|
163
|
+
# (letting the default branch be used) rather than returning a branch from a different repo.
|
|
164
|
+
return epic_branches.values.first if epic_branches.size == 1 && !project_key
|
|
165
|
+
|
|
166
|
+
# Multi-project epic but no matching branch for this task's project — return nil
|
|
167
|
+
nil
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Lazily ensure an epic branch exists for a card's project.
|
|
171
|
+
# Called when epic_branch_for_card returns nil but the card IS in an active epic.
|
|
172
|
+
# Creates the branch in the task's repo and registers it in epic state.
|
|
173
|
+
#
|
|
174
|
+
# @param card_number [Integer, String] Fizzy card number
|
|
175
|
+
# @return [String, nil] Epic branch name or nil
|
|
176
|
+
def ensure_epic_branch_for_card(card_number)
|
|
177
|
+
epic = Orchestrator.find_epic_for_card(card_number.to_i)
|
|
178
|
+
return nil unless epic
|
|
179
|
+
return nil unless epic["review_gate"] == "epic_branch"
|
|
180
|
+
|
|
181
|
+
task = epic["tasks"]&.find { |t| t["fizzy_card"] == card_number.to_i }
|
|
182
|
+
return nil unless task
|
|
183
|
+
|
|
184
|
+
project_key = task["project"]
|
|
185
|
+
return nil unless project_key
|
|
161
186
|
|
|
162
|
-
#
|
|
187
|
+
# Already have a branch for this project
|
|
188
|
+
epic_branches = epic["epic_branches"] || {}
|
|
189
|
+
return epic_branches[project_key] if epic_branches[project_key]
|
|
190
|
+
|
|
191
|
+
# Resolve repo path for this project
|
|
192
|
+
projects_file = File.join(BRAINIAC_DIR, "projects.json")
|
|
193
|
+
return nil unless File.exist?(projects_file)
|
|
194
|
+
|
|
195
|
+
all_projects = JSON.parse(File.read(projects_file))
|
|
196
|
+
repo_path = all_projects.dig(project_key, "repo_path")
|
|
197
|
+
return nil unless repo_path
|
|
198
|
+
|
|
199
|
+
# Create the branch
|
|
200
|
+
slug = branch_slug(epic["title"])
|
|
201
|
+
branch_name = "epic/#{slug}"
|
|
202
|
+
default_branch = detect_default_branch(repo_path)
|
|
203
|
+
|
|
204
|
+
run_git("fetch", "origin", chdir: repo_path)
|
|
205
|
+
|
|
206
|
+
# Check if branch already exists remotely
|
|
207
|
+
remote_exists = system("git", "ls-remote", "--exit-code", "--heads", "origin", branch_name,
|
|
208
|
+
chdir: repo_path, out: File::NULL, err: File::NULL)
|
|
209
|
+
|
|
210
|
+
if remote_exists
|
|
211
|
+
run_git("fetch", "origin", "#{branch_name}:#{branch_name}", chdir: repo_path)
|
|
212
|
+
LOG.info "[Basecamp:EpicBranch] Lazy-created: reusing existing '#{branch_name}' in #{project_key}" if defined?(LOG)
|
|
213
|
+
else
|
|
214
|
+
run_git("branch", branch_name, "origin/#{default_branch}", chdir: repo_path)
|
|
215
|
+
run_git("push", "-u", "origin", branch_name, chdir: repo_path)
|
|
216
|
+
LOG.info "[Basecamp:EpicBranch] Lazy-created: new '#{branch_name}' in #{project_key}" if defined?(LOG)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Register in epic state
|
|
220
|
+
epic["epic_branches"] ||= {}
|
|
221
|
+
epic["epic_branches"][project_key] = branch_name
|
|
222
|
+
epic["updated_at"] = Time.now.iso8601
|
|
223
|
+
Orchestrator.send(:save_epic, epic)
|
|
224
|
+
|
|
225
|
+
branch_name
|
|
226
|
+
rescue StandardError => e
|
|
227
|
+
LOG.error "[Basecamp:EpicBranch] Lazy branch creation failed for #{project_key}: #{e.message}" if defined?(LOG)
|
|
163
228
|
nil
|
|
164
229
|
end
|
|
165
230
|
|
|
@@ -482,12 +482,17 @@ module Brainiac
|
|
|
482
482
|
end
|
|
483
483
|
|
|
484
484
|
# Return the epic branch as the worktree base for cards in an active epic.
|
|
485
|
+
# If the epic branch doesn't exist for this task's project yet, create it lazily.
|
|
485
486
|
def register_resolve_base_branch
|
|
486
487
|
Brainiac.on(:resolve_base_branch) do |ctx|
|
|
487
488
|
card_number = ctx[:card_number]
|
|
488
489
|
next unless card_number
|
|
489
490
|
|
|
490
491
|
branch = EpicBranch.epic_branch_for_card(card_number)
|
|
492
|
+
|
|
493
|
+
# Lazy creation: if no branch exists for this task's project, create one now
|
|
494
|
+
branch ||= EpicBranch.ensure_epic_branch_for_card(card_number)
|
|
495
|
+
|
|
491
496
|
next unless branch
|
|
492
497
|
|
|
493
498
|
"origin/#{branch}"
|
|
@@ -495,12 +500,15 @@ module Brainiac
|
|
|
495
500
|
end
|
|
496
501
|
|
|
497
502
|
# Return the epic branch as the PR target for cards in an active epic.
|
|
503
|
+
# Same lazy-creation logic as resolve_base_branch.
|
|
498
504
|
def register_resolve_pr_target
|
|
499
505
|
Brainiac.on(:resolve_pr_target) do |ctx|
|
|
500
506
|
card_number = ctx[:card_number]
|
|
501
507
|
next unless card_number
|
|
502
508
|
|
|
503
|
-
EpicBranch.epic_branch_for_card(card_number)
|
|
509
|
+
branch = EpicBranch.epic_branch_for_card(card_number)
|
|
510
|
+
branch ||= EpicBranch.ensure_epic_branch_for_card(card_number)
|
|
511
|
+
branch
|
|
504
512
|
end
|
|
505
513
|
end
|
|
506
514
|
|