module Unwrappr::GitHub::Client

GitHub Interactions

Public Class Methods

make_pull_request!(lock_files) click to toggle source
# File lib/unwrappr/github/client.rb, line 15
def make_pull_request!(lock_files)
  create_and_annotate_pull_request(lock_files)
rescue Octokit::ClientError => e
  raise "Failed to create and annotate pull request: #{e}"
end
reset_client() click to toggle source
# File lib/unwrappr/github/client.rb, line 10
def reset_client
  @git_client = nil
  @github_token = nil
end

Private Class Methods

annotate_pull_request(pr_number, lock_files) click to toggle source
# File lib/unwrappr/github/client.rb, line 53
def annotate_pull_request(pr_number, lock_files)
  LockFileAnnotator.annotate_github_pull_request(
    repo: repo_name_and_org,
    pr_number: pr_number,
    lock_files: lock_files,
    client: git_client
  )
end
create_and_annotate_pull_request(lock_files) click to toggle source
# File lib/unwrappr/github/client.rb, line 30
def create_and_annotate_pull_request(lock_files)
  pr = git_client.create_pull_request(
    repo_name_and_org,
    repo_default_branch,
    Unwrappr::GitCommandRunner.current_branch_name,
    'Automated Bundle Update',
    pull_request_body
  )
  annotate_pull_request(pr.number, lock_files)
end
git_client() click to toggle source
# File lib/unwrappr/github/client.rb, line 62
def git_client
  @git_client ||= Octokit::Client.new(access_token: github_token)
end
github_token() click to toggle source
# File lib/unwrappr/github/client.rb, line 66
        def github_token
          @github_token ||= ENV.fetch('GITHUB_TOKEN')
        rescue KeyError
          raise %(
Missing environment variable GITHUB_TOKEN.
See https://github.com/settings/tokens to set up personal access tokens.
Add to the environment:

    export GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

            )
        end
pull_request_body() click to toggle source
# File lib/unwrappr/github/client.rb, line 46
        def pull_request_body
          <<~BODY
            Gems brought up-to-date with :heart: by [Unwrappr](https://github.com/envato/unwrappr).
             See individual annotations below for details.
          BODY
        end
repo_default_branch() click to toggle source
# File lib/unwrappr/github/client.rb, line 41
def repo_default_branch
  git_client.repository(repo_name_and_org)
            .default_branch
end
repo_name_and_org() click to toggle source
# File lib/unwrappr/github/client.rb, line 23
def repo_name_and_org
  repo_url = Unwrappr::GitCommandRunner.remote.gsub(/\.git$/, '')
  pattern = %r{github.com[/:](?<org>.*)/(?<repo>.*)}
  m = pattern.match(repo_url)
  [m[:org], m[:repo]].join('/')
end