class CronForGithub::Client
Public Instance Methods
access_token()
click to toggle source
# File lib/cron_for_github/client.rb, line 42 def access_token ENV['GITHUB_ACCESS_TOKEN'] end
client()
click to toggle source
# File lib/cron_for_github/client.rb, line 3 def client @client ||= Octokit::Client.new(access_token: access_token) end
create_ref(slug, expected_ref, sha)
click to toggle source
# File lib/cron_for_github/client.rb, line 13 def create_ref(slug, expected_ref, sha) logger.info('ref creating') logger.info(slug: slug, ref: expected_ref) return_ref = client.create_ref(slug, expected_ref, sha) logger.info('ref created') logger.debug(return_ref) return_ref end
delete_ref(slug, ref)
click to toggle source
# File lib/cron_for_github/client.rb, line 33 def delete_ref(slug, ref) logger.info('ref deleting') logger.info(slug: slug, ref: ref) return_ref = client.delete_ref(slug, ref) logger.info('ref deleted') logger.debug(return_ref) return_ref end
latest_sha(slug, head_ref)
click to toggle source
# File lib/cron_for_github/client.rb, line 7 def latest_sha(slug, head_ref) response = client.ref(slug, head_ref) logger.debug(response) response.object.sha end
logger()
click to toggle source
# File lib/cron_for_github/client.rb, line 54 def logger ::CronForGithub.logger end
refs(slug, refs_prefix)
click to toggle source
# File lib/cron_for_github/client.rb, line 22 def refs(slug, refs_prefix) client .refs(slug, refs_prefix) .map(&:ref) .map { |ref| remove_prefix_refs(ref) } rescue Octokit::NotFound logger.info('no repos exist:') logger.info(slug: slug, refs_prefix: refs_prefix) [] end
remove_prefix_refs(ref)
click to toggle source
remove refs/ from “refs/heads/ping/foo-bar”
# File lib/cron_for_github/client.rb, line 47 def remove_prefix_refs(ref) regex = %r{\Arefs/(?<stripped_ref>.+)\Z} match = regex.match(ref) fail InvalidRefPrefixError, "ref: #{ref}" unless match match[:stripped_ref] end