Class: Sambot::SourceControl

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/source_control.rb

Constant Summary collapse

ET_GITHUB_API =
'https://github.exacttarget.com/api/v3'
ET_GITHUB =
'https://github.exacttarget.com'
ET_GITHUB_HOST =
'github.exacttarget.com'
WRAPPER_COOKBOOKS =
'ads-wrapper-cookbooks'
ROLE_COOKBOOKS =
'ads-role-cookbooks'

Class Method Summary collapse

Class Method Details

.add_deploy_key(config) ⇒ Object



25
26
27
28
29
# File 'lib/sambot/source_control.rb', line 25

def add_deploy_key(config)
  # Create deploy key
  # Add it to Vault
  # Run Chef-Client against TeamCity
end

.checkout(organization) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/sambot/source_control.rb', line 58

def checkout(organization)
  repositories = list_organization_repositories(organization)
  repositories.each do |repository|
    if Dir.exist?(repository.name)
      UI.info("#{repository.name} already exists and will be updated")
      Dir.chdir(repository.name) do
        `git pull`
      end
    else
      `git clone #{repository.ssh_url}`
    end
  end
end

.create_repository(config) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sambot/source_control.rb', line 31

def create_repository(config)
  target = identify_repository(config)
  if api.repos.get user: target[:organization], repo: target[:name]
    UI.info("The repository #{target[:organization]}/#{target[:name]} exists and will not be recreated")
    return 1
  else
    api.repos.create "name": target[:name], org: target[:organization],
        "private": false,
        "has_issues": true,
        "has_wiki": false,
        "has_downloads": true
      UI.info("The repository #{target[:organization]}/#{target[:name]} has been created")
    return 0
  end
end

.delete_repository(config) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/sambot/source_control.rb', line 47

def delete_repository(config)
  target = identify_repository(config)
  if api.repos.get "#{target[:organization]}/#{target[:name]}"
    UI.info("The repository #{target[:organization]}/#{arget[:name]} does not exist and will not be deleted")
    return 1
  else
    api.repos.delete organization, repo
    return 0
  end
end

.edit_file(organization, repository, path, contents, file, msg) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/sambot/source_control.rb', line 80

def edit_file(organization, repository, path, contents, file, msg)
  contents_api.update organization, repository, path,
    content: contents,
    path: path,
    message: msg,
    sha: file.sha
end

.get_file(organization, repository, path) ⇒ Object



76
77
78
# File 'lib/sambot/source_control.rb', line 76

def get_file(organization, repository, path)
  contents_api.find user: organization, repo: repository, path: path
end

.list_organization_repositories(organization) ⇒ Object



72
73
74
# File 'lib/sambot/source_control.rb', line 72

def list_organization_repositories(organization)
  api.repos.list org: organization
end

.set_git_remote(config) ⇒ Object



18
19
20
21
22
23
# File 'lib/sambot/source_control.rb', line 18

def set_git_remote(config)
  target = identify_repository(config)
  cmd = "git remote set-url origin git@#{ET_GITHUB_HOST}:#{target[:organization]}/#{target[:name]}"
  UI.info("Running the following command: #{cmd}")
  `#{cmd}`
end