Class: Flo::Provider::GithubFlo

Inherits:
Base
  • Object
show all
Defined in:
lib/flo/provider/github_flo.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ GithubFlo

Creates a new GithubFlo Provider instance

Parameters:

  • opts (Hash) (defaults to: {})

    The options needed to create the provider

Options Hash (opts):

  • :user (String)

    The username of the github user

  • :token (String)

    an access token for the user

  • :repo (String)

    the name of the repo, e.g. ‘salesforce/github_flo’



20
21
22
23
24
25
26
# File 'lib/flo/provider/github_flo.rb', line 20

def initialize(opts={})
  username = opts[:user]
  token = opts[:token]
  @repo = opts[:repo]

  @client = opts[:client] || Octokit::Client.new(login: username, password: token)
end

Instance Method Details

#add_labels_to_an_issue(opts = {}) ⇒ Object

Adds labels to a Github Issue

Remaining options will be passed to octokit. See octokit’s documentation for updating issues

Parameters:

  • opts (Hash) (defaults to: {})

    Options for updating an issue

Options Hash (opts):

  • :number (String)

    The issue number to update

  • :labels (Array<String>)

    A list of labels to add to the issue



49
50
51
52
53
# File 'lib/flo/provider/github_flo.rb', line 49

def add_labels_to_an_issue(opts={})
  options = {repo: @repo}.merge(opts)
  @client.add_labels_to_an_issue(options.delete(:repo), options.delete(:number), options[:labels])
  OpenStruct.new(success?: true)
end

#create_pull_request(opts = {}) ⇒ Object

Creates a Github pull request

Remaining options will be passed to octokit. See octokit’s documentation for updating issues

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • base (String) — default: 'master'

    The base branch for the pull request

  • head (String)

    The head containing the new changes

  • Title (String)

    The title for the pull request

  • Body (String)

    The body of the pull request



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/flo/provider/github_flo.rb', line 77

def create_pull_request(opts={})
  repo = opts[:repo] || @repo
  @client.create_pull_request(
                              repo,
                              opts.delete(:base),
                              opts.delete(:head),
                              opts.delete(:title),
                              opts.delete(:body)
                              )
  OpenStruct.new(success?: true)
end

#issue(opts = {}) ⇒ Sawyer::Resource

Provides an Octokit issue. This is helpful when you want to take some other action based on the state of an issue.

Parameters:

  • opts (Hash) (defaults to: {})

    Options for finding the issue

Options Hash (opts):

  • :number (String)

    The issue number to fetch

Returns:

  • (Sawyer::Resource)

    The issue returned from octokit



63
64
65
66
# File 'lib/flo/provider/github_flo.rb', line 63

def issue(opts={})
  options = {repo: @repo}.merge(opts)
  @client.issue(options[:repo], options[:number])
end

#update_issue(opts = {}) ⇒ Object

Updates a Github issue

Remaining options will be passed to octokit. See octokit’s documentation for updating issues

Parameters:

  • opts (Hash) (defaults to: {})

    Options for updating an issue

Options Hash (opts):

  • :number (String)

    The issue number to update



35
36
37
38
39
# File 'lib/flo/provider/github_flo.rb', line 35

def update_issue(opts={})
  options = {repo: @repo}.merge(opts)
  @client.update_issue(options.delete(:repo), options.delete(:number), options)
  OpenStruct.new(success?: true)
end