Class: Cp8Cli::Github::PullRequest

Inherits:
Object
  • Object
show all
Includes:
Api::Client
Defined in:
lib/cp8_cli/github/pull_request.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Api::Client

#client

Constructor Details

#initialize(from: nil, to: "master", title: nil, body: nil, expand: 1, html_url: nil, **attributes) ⇒ PullRequest

Returns a new instance of PullRequest.



19
20
21
22
23
24
25
26
# File 'lib/cp8_cli/github/pull_request.rb', line 19

def initialize(from: nil, to: "master", title: nil, body: nil, expand: 1, html_url: nil, **attributes)
  @from = from
  @to = to
  @title = title
  @body = body
  @expand = expand
  @html_url = html_url
end

Class Method Details

.create(attributes = {}) ⇒ Object



9
10
11
# File 'lib/cp8_cli/github/pull_request.rb', line 9

def self.create(attributes = {})
  new(attributes).save
end

.find_by(repo:, branch:) ⇒ Object



13
14
15
16
17
# File 'lib/cp8_cli/github/pull_request.rb', line 13

def self.find_by(repo:, branch:)
  client.pull_requests(repo.shorthand, head: "#{repo.user}:#{branch}").map do |data|
    new(data)
  end.first
end

Instance Method Details

#openObject



28
29
30
# File 'lib/cp8_cli/github/pull_request.rb', line 28

def open
  Command.open_url(url)
end

#saveObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cp8_cli/github/pull_request.rb', line 32

def save
  client.create_pull_request(
    repo.shorthand,
    to,
    from,
    title,
    body,
    draft: true,
    accept: "application/vnd.github.shadow-cat-preview" # waiting for https://github.com/octokit/octokit.rb/pull/1114
  )
end