Class: SyncIssues::GitHub
- Inherits:
-
Object
- Object
- SyncIssues::GitHub
- Defined in:
- lib/sync_issues/github.rb
Overview
GitHub is responsible access to GitHub’s API
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #create_issue(repository, issue, add_assignees, add_labels) ⇒ Object
-
#initialize ⇒ GitHub
constructor
A new instance of GitHub.
- #issues(repository) ⇒ Object
- #labels(repository) ⇒ Object
- #repository(repository_name) ⇒ Object
- #update_issue(repository, issue_number, comparison) ⇒ Object
Constructor Details
#initialize ⇒ GitHub
Returns a new instance of GitHub.
10 11 12 13 |
# File 'lib/sync_issues/github.rb', line 10 def initialize @client = Octokit::Client.new access_token: token @client.auto_paginate = true end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/sync_issues/github.rb', line 8 def client @client end |
Instance Method Details
#create_issue(repository, issue, add_assignees, add_labels) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
27 28 29 |
# File 'lib/sync_issues/github.rb', line 27 def issues(repository) @client.issues(repository.full_name, state: :all) end |
#labels(repository) ⇒ Object
31 32 33 |
# File 'lib/sync_issues/github.rb', line 31 def labels(repository) @client.labels(repository.full_name) end |
#repository(repository_name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sync_issues/github.rb', line 35 def repository(repository_name) @client.repository(repository_name) rescue Octokit::InvalidRepository => exc raise Error, exc. rescue Octokit::NotFound raise Error, 'repository not found' end |
#update_issue(repository, issue_number, comparison) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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 |