Class: BuPr::Handlers::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/bu_pr/handlers/github.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, current_branch:) ⇒ Github

Returns a new instance of Github.

Parameters:

  • [BuPr::Configuration] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options



29
30
31
32
33
34
35
# File 'lib/bu_pr/handlers/github.rb', line 29

def initialize config:, current_branch:
  @current = current_branch
  @base    = config.branch
  @repo    = config.repo
  @title   = config.title
  @token   = config.token
end

Instance Attribute Details

#baseString (readonly)

Returns base branch name.

Returns:

  • (String)

    base branch name



9
10
11
# File 'lib/bu_pr/handlers/github.rb', line 9

def base
  @base
end

#currentString (readonly)

Returns current branch.

Returns:

  • (String)

    current branch



10
11
12
# File 'lib/bu_pr/handlers/github.rb', line 10

def current
  @current
end

#linkerCompareLinker (readonly)

Returns:

  • (CompareLinker)


14
15
16
# File 'lib/bu_pr/handlers/github.rb', line 14

def linker
  @linker
end

#repoString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/bu_pr/handlers/github.rb', line 11

def repo
  @repo
end

#titleString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/bu_pr/handlers/github.rb', line 12

def title
  @title
end

#tokenString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/bu_pr/handlers/github.rb', line 13

def token
  @token
end

Class Method Details

.call(config:, current_branch:) ⇒ Object

Entry point

Parameters:

  • [BuPr::Configuration] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options



20
21
22
23
24
25
# File 'lib/bu_pr/handlers/github.rb', line 20

def self.call config:, current_branch:
  new(
    config:         config,
    current_branch: current_branch
  ).call
end

Instance Method Details

#callObject



37
38
39
# File 'lib/bu_pr/handlers/github.rb', line 37

def call
  diff_comment create_pull_request
end

#create_pull_requestInteger

Returns pull-request ID.

Returns:

  • (Integer)

    pull-request ID



42
43
44
45
46
47
48
49
50
# File 'lib/bu_pr/handlers/github.rb', line 42

def create_pull_request
  res = client.create_pull_request \
    repo,
    base,
    current,
    title

  res[:number]
end

#diff_comment(pr_number) ⇒ Object

Parameters:

  • pr_number (Integer)


53
54
55
56
# File 'lib/bu_pr/handlers/github.rb', line 53

def diff_comment pr_number
  load_linker pr_number
  linker.add_comment repo, pr_number, comment_content
end