brainiac-github 0.2.5 → 0.2.7

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: 4646b834b308b619a34c5b94da48aeb88b80caa3fb5efd107ac40a5dc56da2a0
4
- data.tar.gz: af0c3f9c0b47e366928760c64168a74eb3651f87c193156cbced75336626bac0
3
+ metadata.gz: 61c06c4b2537e0c675234514c9381b0797f96669401f108a5215f5f42a70b142
4
+ data.tar.gz: a7e2bfd0b3bd4ec8258131e31bd251a9d816a5cedd84742c8141449d161445ae
5
5
  SHA512:
6
- metadata.gz: 945f7fad37cd33a37d755b6517faa8638c4a351d74f11edb60bf8299d04933837f38b34e1fa39afaea34af2b2d57c89f5b88d641fb6e6001436622928143d445
7
- data.tar.gz: 5c2e27ab69d9af292ddbd3c7ac299629f1b97c005b85275bdaaa31d24b010903a75b4973d6d91cf99ab5ea580c53c67c77e341724f46c633a2628d2a78ad6c67
6
+ metadata.gz: e01941e3c2e97832df1683b438cd1632cee50f9d9afaa91538c53bf55e4e438992f7567b17066e555fab22603ce3c56a8831af9332c8d57bb0117354951ff7c3
7
+ data.tar.gz: 9b51d89a994a1a9b4d072375f9a39011ddba50adbce000c11e598ce820900e2d052c577614f730c20a589036e821508d32ed58ecb31940b48095686efaa7ca25
@@ -182,6 +182,26 @@ module Brainiac
182
182
  return [200, { status: "processed", card: card_number, pr: pr_number, reviewer: reviewer, action: "hook_only" }.to_json]
183
183
  end
184
184
 
185
+ # If the work item's assigned agent is NOT local to this machine,
186
+ # skip dispatch — the other machine owns this PR's agent.
187
+ # This check is intentionally AFTER the hook emit so gate tracking
188
+ # works on both machines, but only one machine dispatches the agent.
189
+ if result
190
+ work_item_agent = card_info["agent"]
191
+ if work_item_agent && !local_agent_names.include?(work_item_agent)
192
+ LOG.info "[GitHub] PR ##{pr_number} assigned to remote agent #{work_item_agent} — skipping review dispatch"
193
+ return [200, { status: "ignored", reason: "work item owned by remote agent" }.to_json]
194
+ end
195
+ else
196
+ # No work item found — check if the PR's branch exists as a local worktree.
197
+ # This handles PRs opened manually (not through a card) where the worktree
198
+ # exists on only one machine. The machine that has the worktree should handle it.
199
+ unless branch_exists_locally?(repo_path, branch)
200
+ LOG.info "[GitHub] PR ##{pr_number} branch '#{branch}' not found locally — skipping review dispatch"
201
+ return [200, { status: "ignored", reason: "branch not on this machine" }.to_json]
202
+ end
203
+ end
204
+
185
205
  card_key = "pr-review-#{repo_name.tr("/", "-")}-#{pr_number}"
186
206
 
187
207
  return [200, { status: "ignored", reason: "session already active" }.to_json] if session_active?(card_key)
@@ -261,12 +281,22 @@ module Brainiac
261
281
  # route to whoever is actually working it (e.g. GLaDOS opened the PR,
262
282
  # so GLaDOS should handle follow-up comments — not the project's default agent).
263
283
  # Explicit mentions still take priority (already resolved above).
284
+ #
285
+ # If the work item's assigned agent is NOT local to this machine,
286
+ # skip dispatch entirely — the other machine owns this PR's agent.
264
287
  if result && !mentioned
265
288
  _, card_info = result
266
289
  work_item_agent = card_info["agent"]
267
- if work_item_agent && work_item_agent.downcase != agent_name.downcase && local_agent_names.include?(work_item_agent)
268
- LOG.info "[GitHub] Work item agent override: #{work_item_agent} (project default: #{agent_name})"
269
- agent_name = work_item_agent
290
+ if work_item_agent
291
+ if local_agent_names.include?(work_item_agent)
292
+ if work_item_agent.downcase != agent_name.downcase
293
+ LOG.info "[GitHub] Work item agent override: #{work_item_agent} (project default: #{agent_name})"
294
+ agent_name = work_item_agent
295
+ end
296
+ else
297
+ LOG.info "[GitHub] PR ##{pr_number} assigned to remote agent #{work_item_agent} — skipping dispatch"
298
+ return [200, { status: "ignored", reason: "work item owned by remote agent" }.to_json]
299
+ end
270
300
  end
271
301
  end
272
302
 
@@ -374,6 +404,32 @@ module Brainiac
374
404
  local_agent_names.include?(agent_from_bot)
375
405
  end
376
406
 
407
+ # Check if a branch exists as a local worktree or local branch.
408
+ # Used to determine if this machine should handle a PR when there's no work item.
409
+ #
410
+ # @param repo_path [String] Path to the main repo
411
+ # @param branch [String] Branch name to check
412
+ # @return [Boolean] True if the branch exists locally
413
+ def branch_exists_locally?(repo_path, branch)
414
+ return false unless repo_path && File.directory?(repo_path)
415
+
416
+ # Check if branch exists in any local worktree
417
+ output, status = Open3.capture2("git", "worktree", "list", "--porcelain", chdir: repo_path)
418
+ return false unless status.success?
419
+
420
+ output.each_line do |line|
421
+ if line.start_with?("branch refs/heads/")
422
+ wt_branch = line.sub("branch refs/heads/", "").strip
423
+ return true if wt_branch == branch
424
+ end
425
+ end
426
+
427
+ # Also check if it's a local branch (not in a separate worktree)
428
+ _, status = Open3.capture2("git", "rev-parse", "--verify", "refs/heads/#{branch}",
429
+ chdir: repo_path, err: File::NULL)
430
+ status.success?
431
+ end
432
+
377
433
  # Extract a Brainiac agent display name from a GitHub bot login.
378
434
  # Bot logins follow the pattern "<name>-brainiac[bot]" or "<name>-brainiac".
379
435
  # Returns the matched agent display name, or nil if not a known agent bot.
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Github
6
- VERSION = "0.2.5"
6
+ VERSION = "0.2.7"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainiac-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis