Module: ZombieFans::Actions::Repo

Included in:
Robot
Defined in:
lib/zombie_fans/actions/repo.rb

Instance Method Summary collapse

Instance Method Details

#create_repoObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zombie_fans/actions/repo.rb', line 3

def create_repo
  agent.get('https://github.com/new') do |page|
    page.form_with(action: '/repositories') do |form|
      name = Faker::Internet.domain_word
      description = Faker::Hacker.say_something_smart
      @repos ||= []
      @repos << name

      log_action 'CreateRepo', "with name: #{name}, description: #{description}."

      form['repository[name]'] = name
      form['repository[description]'] = description
    end.submit

    save
  end
end

#make_repo_private(repo) ⇒ Object



44
45
46
# File 'lib/zombie_fans/actions/repo.rb', line 44

def make_repo_private repo
  toggle_permission repo, "private"
end

#make_repo_public(repo) ⇒ Object



48
49
50
# File 'lib/zombie_fans/actions/repo.rb', line 48

def make_repo_public repo
  toggle_permission repo, "public"
end

#star_repo(repo) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zombie_fans/actions/repo.rb', line 21

def star_repo repo
  page = agent.get("https://github.com/#{repo}")
  form = page.at('.starring-container:not(.on) form.unstarred')
  return unless form

  log_action 'StarRepo', "#{repo}."

  authenticity_token = form.at('input[name=authenticity_token]').attr('value')
  star_repo_url = form.attr('action')

  query = {
    authenticity_token: authenticity_token
  }

  header = {
    'X-Requested-With' => 'XMLHttpRequest'
  }

  # agent.agent.allowed_error_codes = [400]
  page = agent.post(star_repo_url, query, header)
  response = JSON.parse page.body
end

#toggle_permission(repo, permission) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zombie_fans/actions/repo.rb', line 52

def toggle_permission repo, permission
  page = agent.get("https://github.com/#{repo}/settings")
  button = page.at('a[href="#visibility_confirm"]')
  return unless button && button.text == "Make #{permission}"

  log_action 'TogglePermission', "#{repo} #{permission}."

  page = page.form_with(action: "/#{repo}/settings/toggle_permission") do |form|
    form['verify'] = repo
  end.submit
end