Class: PdkSync::GithubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/pdksync/githubclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_token, api_endpoint = nil) ⇒ GithubClient

Returns a new instance of GithubClient.

Parameters:

  • access_token

    The Github access token, required to access the Github API



13
14
15
16
17
18
# File 'lib/pdksync/githubclient.rb', line 13

def initialize(access_token, api_endpoint = nil)
  # USE ENV['OCTOKIT_API_ENDPOINT'] or pass in the api_endpoint
  Octokit.configure { |c| c.api_endpoint = api_endpoint } unless api_endpoint.nil?
  @client = Octokit::Client.new(access_token: access_token.to_s)
  @client.user.
end

Instance Method Details

#create_pull_request(repo_name, create_pr_against, head, title, message) ⇒ Object

Returns An Octokit pull request object for the newly created pull request.

Parameters:

  • repo_name (String)

    The full repository name, i.e. “namespace/repo_name” in which to create the pull request

  • create_pr_against (String)

    The target branch against which to create the pull request

  • head (String)

    The source branch from which to create the pull request

  • title (String)

    The title/name of the pull request to create

  • message (String)

    The pull request message/body

Returns:

  • An Octokit pull request object for the newly created pull request



41
42
43
# File 'lib/pdksync/githubclient.rb', line 41

def create_pull_request(repo_name, create_pr_against, head, title, message)
  @client.create_pull_request(repo_name, create_pr_against, head, title, message)
end

#delete_branch(repo_name, branch_name) ⇒ Boolean

Returns true on success, false on failure.

Parameters:

  • repo_name (String)

    The full repository name, i.e. “namespace/repo_name” in which to delete the branch

  • branch_name (String)

    The name of the branch to delete

Returns:

  • (Boolean)

    true on success, false on failure



74
75
76
# File 'lib/pdksync/githubclient.rb', line 74

def delete_branch(repo_name, branch_name)
  @client.delete_branch(repo_name, branch_name)
end

#labels(repo_name) ⇒ Array

Returns List of available labels in the repository.

Parameters:

  • repo_name (String)

    The full repository name, i.e. “namespace/repo_name”, from which to get the available labels

Returns:

  • (Array)

    List of available labels in the repository



50
51
52
# File 'lib/pdksync/githubclient.rb', line 50

def labels(repo_name)
  @client.labels(repo_name)
end

#repository?(repository) ⇒ Boolean

Returns true if the repository exists, false otherwise.

Parameters:

  • repository (String)

    The full repository name, i.e. “namespace/repo_name”

Returns:

  • (Boolean)

    true if the repository exists, false otherwise



24
25
26
# File 'lib/pdksync/githubclient.rb', line 24

def repository?(repository)
  @client.repository?(repository)
end

#update_issue(repo_name, issue_number, options) ⇒ Object

Returns An Octokit issue object of the updated issue.

Parameters:

  • repo_name (String)

    The full repository name, i.e. “namespace/repo_name” in which to update the issue

  • issue_number (Integer)

    The id number of the issue/pull request to update

  • options (Hash)

    A hash of options definint the changes to the issue

Returns:

  • An Octokit issue object of the updated issue



63
64
65
# File 'lib/pdksync/githubclient.rb', line 63

def update_issue(repo_name, issue_number, options)
  @client.update_issue(repo_name, issue_number, options)
end