Class: PrComet::Github::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pr_comet/github/client.rb

Overview

GitHub API Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, remote_url) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/pr_comet/github/client.rb', line 9

def initialize(access_token, remote_url)
  @client = Octokit::Client.new(access_token: access_token)
  @repository = remote_url.match(REPOSITORY_MATCHER)[:repository]
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



7
8
9
# File 'lib/pr_comet/github/client.rb', line 7

def repository
  @repository
end

Instance Method Details

#add_labels(issue_number, *labels) ⇒ Object

Add labels to the issue.

Parameters:

  • issue_number (Integer)

    Number ID of the issue (or pull request)

  • labels (Array<String>)

    An array of labels to apply to this Issue

See Also:



33
34
35
# File 'lib/pr_comet/github/client.rb', line 33

def add_labels(issue_number, *labels)
  client.add_labels_to_an_issue(repository, issue_number, labels)
end

#add_to_project(issue_number, column_name:, project_id: nil) ⇒ Object

Adds supplied issue (or pull request) to the GitHub project

Parameters:

  • issue_number (Integer)

    Number ID of the issue (or pull request)

  • column_name (String)

    A target column name

  • project_id (Integer) (defaults to: nil)

    A target project ID. It is a optional parameter. If does not supplied, this method will find a project which associated the repository. When the repository has multiple projects, you should supply this.

See Also:



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pr_comet/github/client.rb', line 46

def add_to_project(issue_number, column_name:, project_id: nil)
  project_id ||= default_project_id
  column_id = get_project_column_id(project_id, column_name)
  issue_id = get_issue_id(issue_number)
  client.create_project_card(
    column_id,
    content_id: issue_id,
    content_type: 'PullRequest'
  )
rescue Octokit::Error => e
  raise "Failed to add a pull request to the project: #{e.message}"
end

#create_pull_request(base:, head:, title:, body:) ⇒ Integer

Create a pull request

Parameters:

  • base (String)

    The branch you want your changes pulled into

  • head (String)

    The branch where your changes are implemented

  • title (String)

    Title for the pull request

  • body (String)

    The body for the pull request

Returns:

  • (Integer)

    Created pull request number

See Also:



22
23
24
25
26
# File 'lib/pr_comet/github/client.rb', line 22

def create_pull_request(base:, head:, title:, body:)
  response =
    client.create_pull_request(repository, base, head, title, body)
  response.number
end