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

Class Method Details

.basecamp_project_for(brainiac_project) ⇒ String?

Get the Basecamp project ID for a Brainiac project key.

Parameters:

  • brainiac_project (String)

    Brainiac project key

Returns:

  • (String, nil)

    Basecamp project ID



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.

Parameters:

  • person_id (String, Integer)

    Basecamp person ID

Returns:

  • (Hash, nil)

    Bot account config or nil



67
68
69
70
71
# File 'lib/brainiac/plugins/basecamp/config.rb', line 67

def (person_id)
  current["bot_accounts"].find do |_key, |
    ["person_id"].to_s == person_id.to_s
  end&.then { |key, | .merge("key" => key) }
end

.brainiac_project_for(basecamp_project_id) ⇒ String?

Get the Brainiac project key for a Basecamp project/bucket ID.

Parameters:

  • basecamp_project_id (String, Integer)

    Basecamp bucket ID

Returns:

  • (String, nil)

    Brainiac project key



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

.currentHash

Load and cache config. Reloads if file has changed since last read.

Returns:

  • (Hash)


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

.deployHash

Deploy configuration.

Returns:

  • (Hash)


116
117
118
# File 'lib/brainiac/plugins/basecamp/config.rb', line 116

def deploy
  current["deploy"] || DEFAULT_CONFIG["deploy"]
end

.epic_prefixString

The prefix used to identify epic todolists (e.g. "Epic: My Feature")

Returns:

  • (String)


95
96
97
# File 'lib/brainiac/plugins/basecamp/config.rb', line 95

def epic_prefix
  current["epic_prefix"] || "Epic:"
end

.fizzy_account_idString?

The Fizzy account ID (for building card URLs like app.fizzy.do//cards/N).

Returns:

  • (String, nil)


102
103
104
# File 'lib/brainiac/plugins/basecamp/config.rb', line 102

def 
  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.message}" if defined?(LOG)
  @config = DEFAULT_CONFIG.dup
end

.review_gateString

Review gate mode: "on_complete" (advance immediately) or "on_pr_merge" (wait for merge).

Returns:

  • (String)


109
110
111
# File 'lib/brainiac/plugins/basecamp/config.rb', line 109

def review_gate
  current["review_gate"] || "on_complete"
end