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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df22ea85b48c5fd4960ad4e8bb28c3e59f551839c2cbc900dc065edc74039ed3
4
- data.tar.gz: d8708dd8352a97e01bac35eb65ddb13ab7aea6249876987d4e73fd89328f97ee
3
+ metadata.gz: fa974a43197bb85272bc7a2b53c44b2dc763203d6f5ef7c1286059b50aa2cd97
4
+ data.tar.gz: 15a725f96507c8cf78dc37e73e1e91505b03ba1c5ee21b7f4c5a8c583f353503
5
5
  SHA512:
6
- metadata.gz: 241be88652dfaf39203b734d212d6b91e641017a3344cd4c8cabdad2332e1262f8e848e12680ca0612d43c9e44db6c124c9d1e6e76aecc5c625a4f30b8cff499
7
- data.tar.gz: 5096d8be04c2c469770b93e5c998502cd545cb78553f64ec40e621d84f8d03c0d5e3ec9263c77237db1bc92cdb7396cb2ddff4b626be6230ca279b3f91676a14
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
- return [200, { status: "ignored", reason: "no matching card" }.to_json] unless result
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: pr.dig("base", "ref")
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, { status: "processed", action: "pr_sync", card: card_number, ephemeral_redeployed: ephemeral_redeployed }.to_json]
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
- # belt_app? lives on BeltEnvironment (via BeltHelpers), not on this Handler module.
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
@@ -3,7 +3,7 @@
3
3
  module Brainiac
4
4
  module Plugins
5
5
  module Github
6
- VERSION = "0.3.0"
6
+ VERSION = "0.3.1"
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Davis