Class: Rolemodel::GithubGenerator

Inherits:
GeneratorBase
  • Object
show all
Defined in:
lib/generators/rolemodel/github/github_generator.rb

Constant Summary collapse

GITHUB_ACTIONS_REPO =
'https://github.com/RoleModel/actions.git'

Instance Method Summary collapse

Instance Method Details

#install_dependabot_and_codeownersObject



30
31
32
33
34
35
# File 'lib/generators/rolemodel/github/github_generator.rb', line 30

def install_dependabot_and_codeowners
  copy_file 'dependabot.yml', '.github/dependabot.yml', force: true
  copy_file 'CODEOWNERS', '.github/CODEOWNERS'

  say '👉 See CODEOWNERS file for important instructions.', %i[bold red on_blue]
end

#install_github_configObject



24
25
26
27
28
# File 'lib/generators/rolemodel/github/github_generator.rb', line 24

def install_github_config
  directory 'instructions', '.github/instructions'
  directory 'workflows', '.github/workflows', force: true
  template 'pull_request_template.md', '.github/pull_request_template.md'
end

#set_rm_actions_versionObject



15
16
17
18
# File 'lib/generators/rolemodel/github/github_generator.rb', line 15

def set_rm_actions_version
  tags = `git ls-remote --tags #{GITHUB_ACTIONS_REPO}` rescue 'refs/tags/v3'
  @rm_actions_version = tags.scan(%r{refs/tags/v(\d+)\s*$}).flatten.max_by(&:to_i)
end

#set_webdriverObject



20
21
22
# File 'lib/generators/rolemodel/github/github_generator.rb', line 20

def set_webdriver
  @webdriver = options.playwright? ? 'playwright' : 'selenium'
end

#update_database_yml_for_ciObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/rolemodel/github/github_generator.rb', line 37

def update_database_yml_for_ci
  insert_into_file 'config/database.yml', after: /database: .*_test.*\n/ do
    optimize_indentation <<~YML, 2
      <% if ENV.has_key?("POSTGRES_USER") %>
      username: <%= ENV.fetch("POSTGRES_USER") %>
      password: <%= ENV.fetch("POSTGRES_PASSWORD") { nil } %>
      host: localhost
      <% end %>
    YML
  end
end