belt 0.3.6 → 0.3.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: abed8bb1f75407be5e61c3725a880c52096ecbd62285910afcc640bff6be277d
4
- data.tar.gz: cdb9b586a8ce7cdc9e6f41bc39cc77b80c5155e2bb8a19d5390e65bf5a86b70f
3
+ metadata.gz: 0be7ca644efba0ca7b1e95b076bbae96873ced55d3251e5de235208169bbcce9
4
+ data.tar.gz: d5f0b277442b1b139fb48c306b4f2c0ca13ce30d6b35637a67749b549f6a7182
5
5
  SHA512:
6
- metadata.gz: b34e9c0a0edfc2c8df99876af80e2f6bbf7848a5e63c842c4d7f39262165089c8b6a69182981e629b6f936859dbf062c5ab5d0d65ed0221f156e1aead3d26b44
7
- data.tar.gz: 53c37765c40fac45c9770bdee1ae337f3a9f928656ece072b7c907da84b535e2c460ff0bfd824d106935e02792c3234cc60470738151556b2d247afa7fb5f731
6
+ metadata.gz: cac4e33287828876e5f248dcf3536f2e4709b2637481453e9d5015711b8a1de4bfc854edfc429060c7929a17f3ec46b17dc15127474ce9bd0312f064c23d77ee
7
+ data.tar.gz: eca9b584458ff63559fe3e4fad915be300628ec0659ae4e3d7d7cac66bba8d8d2e2eb9dd9010174f3d6bce6d7e688356e1325070f7aec0150e518348ab8be50d
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.3.7
4
+
5
+ ### Bug Fix
6
+
7
+ - **App name detection in worktrees**: `detect_app_name` now checks
8
+ `infrastructure/*/variables.tf` for `variable "app_name" { default = "..." }`
9
+ before falling back to the directory name. Fixes incorrect Lambda function
10
+ lookups (e.g. `belt logs`) when running from a git worktree whose directory
11
+ name doesn't match the actual app name.
4
12
 
5
13
  ## 0.3.6
6
14
 
@@ -17,7 +17,7 @@ module Belt
17
17
  end
18
18
 
19
19
  # Detects the application name.
20
- # Prefers terraform.tfvars app_name, then falls back to directory name.
20
+ # Priority: terraform.tfvars app_name > variables.tf default > directory name.
21
21
  def detect_app_name
22
22
  # Check any environment tfvars for the app_name
23
23
  Dir.glob('infrastructure/*/terraform.tfvars').each do |f|
@@ -26,6 +26,10 @@ module Belt
26
26
  return match[1] if match
27
27
  end
28
28
 
29
+ # Check variables.tf for a default app_name value
30
+ name = detect_app_name_from_variables_tf
31
+ return name if name
32
+
29
33
  # Fall back to directory name
30
34
  File.basename(Dir.pwd)
31
35
  end
@@ -67,6 +71,27 @@ module Belt
67
71
  def find_schema_file_path
68
72
  find_contracts_file_path
69
73
  end
74
+
75
+ private
76
+
77
+ # Parses `variable "app_name" { default = "..." }` from any environment's variables.tf.
78
+ # This handles the common pattern where app_name is a Terraform variable with a default
79
+ # rather than being set directly in terraform.tfvars.
80
+ def detect_app_name_from_variables_tf
81
+ Dir.glob('infrastructure/*/variables.tf').each do |f|
82
+ content = File.read(f)
83
+ # Match the app_name variable block and extract its default value
84
+ next unless content.match?(/variable\s+"app_name"/)
85
+
86
+ # Extract default from within the variable block
87
+ block_match = content.match(/variable\s+"app_name"\s*\{([^}]*)\}/m)
88
+ next unless block_match
89
+
90
+ default_match = block_match[1].match(/default\s*=\s*"([^"]+)"/)
91
+ return default_match[1] if default_match
92
+ end
93
+ nil
94
+ end
70
95
  end
71
96
  end
72
97
  end
@@ -321,6 +321,19 @@ module Belt
321
321
  return match[1] if match
322
322
  end
323
323
 
324
+ # Try variables.tf for a default app_name value
325
+ vars_file = File.join(@infra_dir, @env, 'variables.tf')
326
+ if File.exist?(vars_file)
327
+ content = File.read(vars_file)
328
+ if content.match?(/variable\s+"app_name"/)
329
+ block_match = content.match(/variable\s+"app_name"\s*\{([^}]*)\}/m)
330
+ if block_match
331
+ default_match = block_match[1].match(/default\s*=\s*"([^"]+)"/)
332
+ return default_match[1] if default_match
333
+ end
334
+ end
335
+ end
336
+
324
337
  # Fall back to directory name
325
338
  File.basename(@project_root)
326
339
  end
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.3.6'
4
+ VERSION = '0.3.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla