Class: Github

Inherits:
Thor
  • Object
show all
Includes:
GitConfig
Defined in:
lib/github.rb

Instance Method Summary collapse

Methods included from GitConfig

#author, #email, #github_token, #github_user, #jenkins_password, #jenkins_server, #jenkins_user

Instance Method Details

#attachObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/github.rb', line 48

def attach
  #ganked from https://gist.github.com/238305
  github_post "/#{github_user}/#{name}/edit/postreceive_urls",
    "urls[]" => "#{jenkins_server}/job/#{name}/build?token=#{options.token}",
  :raw => true
  announce "attached github project to jenkins"
rescue => e
  puts e
  abort "failed in attach"
end

#delete_projectObject



21
22
23
24
25
26
# File 'lib/github.rb', line 21

def delete_project
  abort "set --confirm to show you really mean it" unless options.confirm?
  res = github_post("/repos/delete/#{github_user}/#{name}", :name => name)
  delete_token = JSON.parse(res.body)['delete_token']
  github_post("/repos/delete/#{github_user}/#{name}", :name => name, :delete_token => delete_token)
end

#new_projectObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/github.rb', line 29

def new_project
  Dir.chdir name do
    guarded "git init"
    guarded "git add ."
    guarded "git commit -m 'initial commit'" do end
    github_post('/repos/create', :name => name)
    guarded "git remote add origin [email protected]:#{github_user}/#{name}"
    announce "new project on github"
  end
end

#preflightObject



12
13
14
15
16
17
# File 'lib/github.rb', line 12

def preflight
  abort "you already have a #{name} project on github" unless
    HTTParty.get("http://github.com/#{github_user}/#{name}").code == 404
  github_user
  github_token
end

#pushObject



41
42
43
# File 'lib/github.rb', line 41

def push
  Dir.chdir(name) { guarded "git push -u origin master" }
end