class SyncIssues::GitHub
GitHub
is responsible access to GitHub's API
Attributes
client[R]
Public Class Methods
new()
click to toggle source
# File lib/sync_issues/github.rb, line 10 def initialize @client = Octokit::Client.new access_token: token @client.auto_paginate = true end
Public Instance Methods
create_issue(repository, issue, add_assignees, add_labels)
click to toggle source
# File lib/sync_issues/github.rb, line 15 def create_issue(repository, issue, add_assignees, add_labels) kwargs = {} kwargs[:assignee] = issue.assignees[0] if add_assignees kwargs[:labels] = issue.labels if add_labels new_issue = @client.create_issue(repository.full_name, issue.title, issue.content, **kwargs) if add_assignees && issue.assignees.size > 1 @client.add_assignees(repository.full_name, new_issue.number, issue.assignees[1..-1]) end end
issues(repository)
click to toggle source
# File lib/sync_issues/github.rb, line 27 def issues(repository) @client.issues(repository.full_name, state: :all) end
labels(repository)
click to toggle source
# File lib/sync_issues/github.rb, line 31 def labels(repository) @client.labels(repository.full_name) end
repository(repository_name)
click to toggle source
# File lib/sync_issues/github.rb, line 35 def repository(repository_name) @client.repository(repository_name) rescue Octokit::InvalidRepository => exc raise Error, exc.message rescue Octokit::NotFound raise Error, 'repository not found' end
update_issue(repository, issue_number, comparison)
click to toggle source
# File lib/sync_issues/github.rb, line 43 def update_issue(repository, issue_number, comparison) @client.update_issue(repository.full_name, issue_number, comparison.title, comparison.content, assignee: comparison.assignees[0], labels: comparison.labels) if comparison.assignees.size > 1 @client.add_assignees(repository.full_name, issue_number, comparison.assignees[1..-1]) end end
Private Instance Methods
token()
click to toggle source
# File lib/sync_issues/github.rb, line 56 def token path = File.expand_path('~/.config/sync_issues.yaml') raise TokenError, "#{path} does not exist" unless File.exist?(path) SafeYAML.load(File.read(path))['token'].tap do |token| raise TokenError, "#{path} missing token attribute" if token.nil? end end