brainiac-github 0.3.0 → 0.3.1
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 +4 -4
- data/lib/brainiac/plugins/github/handler.rb +69 -5
- data/lib/brainiac/plugins/github/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa974a43197bb85272bc7a2b53c44b2dc763203d6f5ef7c1286059b50aa2cd97
|
|
4
|
+
data.tar.gz: 15a725f96507c8cf78dc37e73e1e91505b03ba1c5ee21b7f4c5a8c583f353503
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9f0b4c4c6c453a6c146a9ca5e3fa8aea3657a2aa79345a44e0803121cda492f1ff598256d05de2d4e649058fdfe128249499533c8dc9410c5880194795b1d56
|
|
7
|
+
data.tar.gz: 2a1c93fb97fe48873c4dbffb654d4b4c305929404c70336704c509a06ff0408a33bbb674dcd66bb98356caf6e1ec223b81022445c5b3901da5775342c95df777
|
|
@@ -32,6 +32,12 @@ module Brainiac
|
|
|
32
32
|
|
|
33
33
|
unless base == default_branch
|
|
34
34
|
LOG.info "PR merged into #{base}, not #{default_branch} — ignoring"
|
|
35
|
+
|
|
36
|
+
# Trigger #2: a child PR merging *into* an epic branch redeploys the
|
|
37
|
+
# epic's ephemeral env (if one is tracked for that branch).
|
|
38
|
+
epic_redeployed = maybe_redeploy_epic_ephemeral_env(base_branch: base)
|
|
39
|
+
return [200, { status: "processed", action: "epic_redeploy", base: base }.to_json] if epic_redeployed
|
|
40
|
+
|
|
35
41
|
return [200, { status: "ignored", reason: "not merged into #{default_branch}" }.to_json]
|
|
36
42
|
end
|
|
37
43
|
|
|
@@ -95,9 +101,18 @@ module Brainiac
|
|
|
95
101
|
def handle_pr_synchronized(payload)
|
|
96
102
|
pr = payload["pull_request"]
|
|
97
103
|
branch = pr.dig("head", "ref")
|
|
104
|
+
base_branch = pr.dig("base", "ref")
|
|
105
|
+
|
|
106
|
+
# Trigger #1: a push to an epic PR's head branch redeploys the epic env.
|
|
107
|
+
# Epic envs have no card, so resolve this before the card lookup bails.
|
|
108
|
+
epic_redeployed = maybe_redeploy_epic_ephemeral_env(branch: branch)
|
|
98
109
|
|
|
99
110
|
result = find_work_item_by_branch(branch)
|
|
100
|
-
|
|
111
|
+
unless result
|
|
112
|
+
return [200, { status: "processed", action: "epic_sync", branch: branch, epic_redeployed: true }.to_json] if epic_redeployed
|
|
113
|
+
|
|
114
|
+
return [200, { status: "ignored", reason: "no matching card" }.to_json]
|
|
115
|
+
end
|
|
101
116
|
|
|
102
117
|
_internal_id, card_info = result
|
|
103
118
|
card_number = extract_card_number(card_info)
|
|
@@ -111,15 +126,17 @@ module Brainiac
|
|
|
111
126
|
# Try to redeploy to ephemeral Belt environment if one exists
|
|
112
127
|
ephemeral_redeployed = maybe_redeploy_ephemeral_belt_env(
|
|
113
128
|
card_info: card_info, card_number: card_number, worktree: worktree,
|
|
114
|
-
base_branch:
|
|
129
|
+
base_branch: base_branch
|
|
115
130
|
)
|
|
116
131
|
|
|
117
132
|
# Also emit the hook for other plugins (e.g., brainiac-fizzy persistent env redeploy)
|
|
118
133
|
results = Brainiac.emit(:pr_synchronized, card_number: card_number, card_info: card_info,
|
|
119
134
|
worktree: worktree, pull_request: pr, branch: branch)
|
|
120
135
|
|
|
121
|
-
if ephemeral_redeployed || results.any?
|
|
122
|
-
[200,
|
|
136
|
+
if ephemeral_redeployed || epic_redeployed || results.any?
|
|
137
|
+
[200,
|
|
138
|
+
{ status: "processed", action: "pr_sync", card: card_number, ephemeral_redeployed: ephemeral_redeployed,
|
|
139
|
+
epic_redeployed: epic_redeployed }.to_json]
|
|
123
140
|
else
|
|
124
141
|
[200, { status: "ignored", reason: "no deployment plugin" }.to_json]
|
|
125
142
|
end
|
|
@@ -931,7 +948,54 @@ module Brainiac
|
|
|
931
948
|
false
|
|
932
949
|
end
|
|
933
950
|
|
|
934
|
-
#
|
|
951
|
+
# Redeploy an epic's ephemeral Belt environment.
|
|
952
|
+
#
|
|
953
|
+
# Epic envs aren't keyed by card number — they're tracked in
|
|
954
|
+
# ephemeral_envs.json with `epic_branch` / `epic_pr` fields. This
|
|
955
|
+
# resolves the env by matching the head branch (PR sync / push) or the
|
|
956
|
+
# PR url (child merge into the epic branch), then redeploys its worktree.
|
|
957
|
+
#
|
|
958
|
+
# @param branch [String, nil] Head branch of the synced PR
|
|
959
|
+
# @param base_branch [String, nil] Base branch (for merge-triggered redeploys)
|
|
960
|
+
# @return [Boolean] true if a redeploy was attempted
|
|
961
|
+
def maybe_redeploy_epic_ephemeral_env(branch: nil, base_branch: nil)
|
|
962
|
+
return false unless defined?(BeltConfig) && defined?(BeltEnvironment)
|
|
963
|
+
|
|
964
|
+
# Trigger #1: a push/synchronize on the epic PR branch itself.
|
|
965
|
+
# Trigger #2: a child PR merging *into* the epic branch (base match).
|
|
966
|
+
match = BeltConfig.epic_env_for_branch(branch) ||
|
|
967
|
+
BeltConfig.epic_env_for_branch(base_branch)
|
|
968
|
+
return false unless match
|
|
969
|
+
|
|
970
|
+
env_name, entry = match
|
|
971
|
+
worktree = entry["worktree"]
|
|
972
|
+
|
|
973
|
+
unless worktree && File.directory?(worktree)
|
|
974
|
+
LOG.warn "[EphemeralEnv] Epic env '#{env_name}' worktree missing: #{worktree.inspect} — skipping redeploy"
|
|
975
|
+
return false
|
|
976
|
+
end
|
|
977
|
+
return false unless belt_app_worktree?(worktree)
|
|
978
|
+
|
|
979
|
+
unless ephemeral_env_present?(worktree: worktree, env_name: env_name)
|
|
980
|
+
LOG.debug "[EphemeralEnv] Epic env '#{env_name}' not configured in worktree — skipping redeploy"
|
|
981
|
+
return false
|
|
982
|
+
end
|
|
983
|
+
|
|
984
|
+
# Pull latest into the epic worktree so the deploy reflects the new commits.
|
|
985
|
+
system("git", "pull", "--ff-only", chdir: worktree)
|
|
986
|
+
|
|
987
|
+
LOG.info "[EphemeralEnv] Redeploying epic environment '#{env_name}' (branch: #{branch || base_branch})"
|
|
988
|
+
|
|
989
|
+
# No reliable per-push base for an epic worktree, so let the diff base
|
|
990
|
+
# fall back to origin/HEAD → origin/main → origin/master.
|
|
991
|
+
frontend_only = BeltEnvironment.frontend_only_changes?(worktree: worktree)
|
|
992
|
+
BeltEnvironment.deploy(worktree: worktree, env_name: env_name, frontend_only: frontend_only)
|
|
993
|
+
true
|
|
994
|
+
rescue StandardError => e
|
|
995
|
+
LOG.error "[EphemeralEnv] Error redeploying epic env: #{e.message}"
|
|
996
|
+
false
|
|
997
|
+
end
|
|
998
|
+
|
|
935
999
|
def belt_app_worktree?(worktree)
|
|
936
1000
|
BeltEnvironment.respond_to?(:belt_app?) && BeltEnvironment.belt_app?(worktree)
|
|
937
1001
|
end
|