Class: JobsController

Inherits:
ApplicationController show all
Defined in:
lib/nexmo_developer/app/controllers/jobs_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::CONFIG

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #not_found, #redirect_vonage_domain

Methods included from ApplicationHelper

#active_sidenav_item, #canonical_base, #canonical_base_from_config, #canonical_path, #canonical_url, #dashboard_cookie, #search_enabled?, #set_utm_cookie, #theme

Instance Method Details

#code_example_pushObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nexmo_developer/app/controllers/jobs_controller.rb', line 6

def code_example_push
  if validate_github_signature
    if params['ref'] == 'refs/heads/master'
      url = "https://api.travis-ci.org/repo/#{ENV['TRAVIS_REPO_ID']}/requests"
      RestClient.post(url, {
        request: {
          branch: 'master',
          config: {
            script: 'bundle exec rake diff:execute',
            env: {
              SSH_KEY_REQUIRED: true,
            },
          },
        },
      }.to_json, {
        content_type: :json,
        accept: :json,
        Authorization: "token #{ENV['TRAVIS_TOKEN']}",
        'Travis-API-Version': '3',
      })

      render plain: 'Request forwarded to CI', status: :accepted
    else
      render plain: 'Request understood. Not master, not continuing', status: :ok
    end
  else
    head :unauthorized
  end
end

#open_pull_requestObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nexmo_developer/app/controllers/jobs_controller.rb', line 36

def open_pull_request
  if validate_ci_secret
    repo = ENV['GITHUB_REPO']
    branch_base = 'master'
    branch_head = params[:branch]
    title = '[AUTOMATED] Updated code examples'
    body = params[:body]

    client = Octokit::Client.new(access_token: ENV['GITHUB_PERSONAL_ACCESS_TOKEN'])
    client.
    client.create_pull_request(repo, branch_base, branch_head, title, body)

    head :accepted
  else
    head :unauthorized
  end
end