Module: Brainiac::Plugins::Basecamp::Config
- Defined in:
- lib/brainiac/plugins/basecamp/config.rb
Overview
Configuration loader for brainiac-basecamp.
Config file: ~/.brainiac/basecamp.json
Constant Summary collapse
- BRAINIAC_DIR =
ENV.fetch("BRAINIAC_DIR", File.join(Dir.home, ".brainiac"))
- CONFIG_FILE =
File.join(BRAINIAC_DIR, "basecamp.json")
- DEFAULT_CONFIG =
Default config structure.
{ "bot_accounts" => {}, "project_mappings" => {}, "epic_prefix" => "Epic:", "fizzy_account_id" => nil, "review_gate" => "on_complete", "review_gates" => [], "deploy" => { "enabled" => false, "trigger" => "manual", "default_env" => nil, "project_envs" => {}, "command" => "belt deploy {env} --auto" }, "notifications" => { "epic_started" => true, "task_dispatched" => true, "task_completed" => true, "epic_completed" => true } }.freeze
Class Method Summary collapse
-
.basecamp_project_for(brainiac_project) ⇒ String?
Get the Basecamp project ID for a Brainiac project key.
-
.bot_account_for_person(person_id) ⇒ Hash?
Get bot account config for a given Basecamp person ID.
-
.brainiac_project_for(basecamp_project_id) ⇒ String?
Get the Brainiac project key for a Basecamp project/bucket ID.
-
.current ⇒ Hash
Load and cache config.
-
.deploy ⇒ Hash
Deploy configuration.
-
.epic_prefix ⇒ String
The prefix used to identify epic todolists (e.g. "Epic: My Feature").
-
.fizzy_account_id ⇒ String?
The Fizzy account ID (for building card URLs like app.fizzy.do/
/cards/N). -
.load! ⇒ Object
Force reload config from disk.
-
.review_gate ⇒ String
Review gate mode: "on_complete" (advance immediately) or "on_pr_merge" (wait for merge).
Class Method Details
.basecamp_project_for(brainiac_project) ⇒ String?
Get the Basecamp project ID for a Brainiac project key.
77 78 79 80 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 77 def basecamp_project_for(brainiac_project) mapping = current["project_mappings"][brainiac_project] mapping&.dig("basecamp_project_id") end |
.bot_account_for_person(person_id) ⇒ Hash?
Get bot account config for a given Basecamp person ID.
67 68 69 70 71 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 67 def bot_account_for_person(person_id) current["bot_accounts"].find do |_key, account| account["person_id"].to_s == person_id.to_s end&.then { |key, account| account.merge("key" => key) } end |
.brainiac_project_for(basecamp_project_id) ⇒ String?
Get the Brainiac project key for a Basecamp project/bucket ID.
86 87 88 89 90 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 86 def brainiac_project_for(basecamp_project_id) current["project_mappings"].find do |_key, mapping| mapping["basecamp_project_id"].to_s == basecamp_project_id.to_s end&.first end |
.current ⇒ Hash
Load and cache config. Reloads if file has changed since last read.
42 43 44 45 46 47 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 42 def current return @config if @config && @config_mtime == config_mtime load! @config end |
.deploy ⇒ Hash
Deploy configuration.
116 117 118 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 116 def deploy current["deploy"] || DEFAULT_CONFIG["deploy"] end |
.epic_prefix ⇒ String
The prefix used to identify epic todolists (e.g. "Epic: My Feature")
95 96 97 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 95 def epic_prefix current["epic_prefix"] || "Epic:" end |
.fizzy_account_id ⇒ String?
The Fizzy account ID (for building card URLs like app.fizzy.do/
102 103 104 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 102 def fizzy_account_id current["fizzy_account_id"] end |
.load! ⇒ Object
Force reload config from disk.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 50 def load! if File.exist?(CONFIG_FILE) raw = JSON.parse(File.read(CONFIG_FILE)) @config = DEFAULT_CONFIG.merge(raw) else @config = DEFAULT_CONFIG.dup end @config_mtime = config_mtime rescue JSON::ParserError => e LOG.error "[Basecamp] Config parse error: #{e.}" if defined?(LOG) @config = DEFAULT_CONFIG.dup end |
.review_gate ⇒ String
Review gate mode: "on_complete" (advance immediately) or "on_pr_merge" (wait for merge).
109 110 111 |
# File 'lib/brainiac/plugins/basecamp/config.rb', line 109 def review_gate current["review_gate"] || "on_complete" end |