brainiac-github 0.2.7 → 0.2.9
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: ac4e54b24a8bb52bf92a37bfe86acb8d6e16f76c646811dfdb586be8921e4ad3
|
|
4
|
+
data.tar.gz: 0c31ee9574f36510100bb08094b884aa3eb81917b89c149ae8fb814fbc6aa7de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 26615c5fd5c52574cd4a9739fa8d2179eb834ed91d805f7f02e7881cee59f3cc2952fce2751b7441ef97fe013e9db1809a026bb987ef7e5108c47b9e738d0185
|
|
7
|
+
data.tar.gz: c43852a07188be9a2ae9f8158eb15b91a3c4083dfdc0abab4a0514b1a3b7a755520f4bbde5e8be59919c1a71fc0aa1883c8334c673a7783334f8cd14766eeb19
|
|
@@ -61,15 +61,19 @@ module Brainiac
|
|
|
61
61
|
post("/repos/#{repo}/issues/comments/#{comment_id}/reactions", { content: reaction }, agent_key: agent_key)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
# POST a reaction on a PR
|
|
64
|
+
# POST a reaction on a PR (or issue) itself.
|
|
65
|
+
#
|
|
66
|
+
# GitHub's reactions API has NO endpoint for PR reviews — only for
|
|
67
|
+
# issue comments, PR review comments, issues, and PRs. Since a PR is
|
|
68
|
+
# an issue under the hood, PR reactions go through the issues path.
|
|
65
69
|
#
|
|
66
70
|
# @param repo [String] "owner/repo"
|
|
67
|
-
# @param
|
|
68
|
-
# @param reaction [String]
|
|
71
|
+
# @param pr_number [Integer]
|
|
72
|
+
# @param reaction [String] e.g. "eyes", "+1", "rocket"
|
|
69
73
|
# @param agent_key [String, nil] agent key for per-agent app identity
|
|
70
74
|
# @return [Hash] parsed response
|
|
71
|
-
def
|
|
72
|
-
post("/repos/#{repo}/
|
|
75
|
+
def create_pr_reaction(repo, pr_number, reaction, agent_key: nil)
|
|
76
|
+
post("/repos/#{repo}/issues/#{pr_number}/reactions", { content: reaction }, agent_key: agent_key)
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
# GET request to GitHub API.
|
|
@@ -285,18 +285,22 @@ module Brainiac
|
|
|
285
285
|
# If the work item's assigned agent is NOT local to this machine,
|
|
286
286
|
# skip dispatch entirely — the other machine owns this PR's agent.
|
|
287
287
|
if result && !mentioned
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
288
|
+
override_result = resolve_comment_agent_override(result, agent_name, pr_number)
|
|
289
|
+
return override_result if override_result.is_a?(Array)
|
|
290
|
+
|
|
291
|
+
agent_name = override_result if override_result
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Fallback for human-opened PRs with no assigned agent: if there's no work item,
|
|
295
|
+
# or the work item has no agent field, both machines would dispatch because each
|
|
296
|
+
# has its own local project default agent. Use branch_exists_locally? as a
|
|
297
|
+
# tiebreaker — only the machine that has the branch as a local worktree/branch
|
|
298
|
+
# should handle the comment. Explicit mentions bypass this check.
|
|
299
|
+
unless mentioned || work_item_has_agent?(result)
|
|
300
|
+
repo_path = project_config["repo_path"]
|
|
301
|
+
unless branch_exists_locally?(repo_path, branch)
|
|
302
|
+
LOG.info "[GitHub] PR ##{pr_number} branch '#{branch}' not found locally — skipping comment dispatch"
|
|
303
|
+
return [200, { status: "ignored", reason: "branch not on this machine" }.to_json]
|
|
300
304
|
end
|
|
301
305
|
end
|
|
302
306
|
|
|
@@ -404,6 +408,38 @@ module Brainiac
|
|
|
404
408
|
local_agent_names.include?(agent_from_bot)
|
|
405
409
|
end
|
|
406
410
|
|
|
411
|
+
# Check if a work item result has an assigned agent.
|
|
412
|
+
# Returns true if the result exists and has a non-empty agent field.
|
|
413
|
+
def work_item_has_agent?(result)
|
|
414
|
+
return false unless result
|
|
415
|
+
|
|
416
|
+
agent = result[1]["agent"]
|
|
417
|
+
agent && !agent.empty?
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# Resolve agent override from a work item for PR comment dispatch.
|
|
421
|
+
# Returns:
|
|
422
|
+
# - A Rack response array if dispatch should be skipped (remote agent owns it)
|
|
423
|
+
# - An agent name string if the work item agent should override the default
|
|
424
|
+
# - nil if no override needed
|
|
425
|
+
def resolve_comment_agent_override(result, current_agent, pr_number)
|
|
426
|
+
_, card_info = result
|
|
427
|
+
work_item_agent = card_info["agent"]
|
|
428
|
+
return nil unless work_item_agent
|
|
429
|
+
|
|
430
|
+
unless local_agent_names.include?(work_item_agent)
|
|
431
|
+
LOG.info "[GitHub] PR ##{pr_number} assigned to remote agent #{work_item_agent} — skipping dispatch"
|
|
432
|
+
return [200, { status: "ignored", reason: "work item owned by remote agent" }.to_json]
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
if work_item_agent.downcase != current_agent.downcase
|
|
436
|
+
LOG.info "[GitHub] Work item agent override: #{work_item_agent} (project default: #{current_agent})"
|
|
437
|
+
return work_item_agent
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
nil
|
|
441
|
+
end
|
|
442
|
+
|
|
407
443
|
# Check if a branch exists as a local worktree or local branch.
|
|
408
444
|
# Used to determine if this machine should handle a PR when there's no work item.
|
|
409
445
|
#
|
|
@@ -694,10 +730,12 @@ module Brainiac
|
|
|
694
730
|
agent_name = resolve_work_item_agent(card_info, project_config)
|
|
695
731
|
|
|
696
732
|
Thread.new do
|
|
733
|
+
# GitHub has no reactions endpoint for PR reviews, so react on the
|
|
734
|
+
# PR itself (PRs are issues under the hood) to signal "on it".
|
|
697
735
|
if AppClient.configured?(agent_name)
|
|
698
|
-
AppClient.
|
|
736
|
+
AppClient.create_pr_reaction(repo_name, pr_number, "eyes", agent_key: agent_name)
|
|
699
737
|
else
|
|
700
|
-
run_cmd("gh", "api", "-X", "POST", "/repos/#{repo_name}/
|
|
738
|
+
run_cmd("gh", "api", "-X", "POST", "/repos/#{repo_name}/issues/#{pr_number}/reactions",
|
|
701
739
|
"-f", "content=eyes", "-H", "Accept: application/vnd.github+json", chdir: repo_path)
|
|
702
740
|
end
|
|
703
741
|
|
|
@@ -14,6 +14,19 @@ module Brainiac
|
|
|
14
14
|
- ``` ```language ``` for code blocks
|
|
15
15
|
- `- item` for lists
|
|
16
16
|
|
|
17
|
+
### @Mentions (STRICT — read carefully)
|
|
18
|
+
On GitHub, an `@name` only works if it maps to a real GitHub account.
|
|
19
|
+
The other agents (Galen, GLaDOS, Threepio, etc.) are NOT GitHub users —
|
|
20
|
+
`@threepio` just pings some unrelated stranger who happens to own that
|
|
21
|
+
username. That's noisy and rude.
|
|
22
|
+
|
|
23
|
+
Rules for GitHub comments:
|
|
24
|
+
- The ONLY people you may @mention are **@ardavis** (Andy) and **@fladamd** (Adam).
|
|
25
|
+
- NEVER @mention any other agent or person. Refer to other agents by
|
|
26
|
+
plain name instead — write `Threepio` or `GLaDOS`, not `@threepio`.
|
|
27
|
+
- If you're unsure whether a name is a real GitHub account, don't @mention it.
|
|
28
|
+
Drop the `@` and use the plain name.
|
|
29
|
+
|
|
17
30
|
### Scope
|
|
18
31
|
You are responding to activity on a GitHub PR. Focus on the code changes and review feedback.
|
|
19
32
|
When posting comments, post on the PR unless specifically asked to update the card.
|