summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook/githubrepo.rb
blob: fe7301549811e9827b7d812b8acc8372754f921c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class GithubRepo < Oxidized::Hook
  def validate_cfg!
    cfg.has_key?('remote_repo') or raise KeyError, 'remote_repo is required'
  end

  def run_hook(ctx)
    credentials = Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password)
    repo = Rugged::Repository.new(Oxidized.config.output.git.repo)
    log "Pushing local repository(#{repo.path})..."
    remote = repo.remotes['origin'] || repo.remotes.create('origin', cfg.remote_repo)
    log "to remote: #{remote.url}"
    remote.push(['refs/heads/master'], credentials: credentials)
  end
end