Class: Dependabot::PullRequestCreator::Github

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Clients::GithubResourceParser
Defined in:
lib/dependabot/pull_request_creator/github.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

PR_DESCRIPTION_MAX_LENGTH =

GitHub limits PR descriptions to a max of 65,536 characters: https://github.com/orgs/community/discussions/27190#discussioncomment-3726017

65_535

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, branch_name:, base_commit:, credentials:, files:, commit_message:, pr_description:, pr_name:, author_details:, signature_key:, custom_headers:, labeler:, reviewers:, assignees:, milestone:, require_up_to_date_base:) ⇒ Github

Returns a new instance of Github.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/dependabot/pull_request_creator/github.rb', line 90

def initialize(
  source:,
  branch_name:,
  base_commit:,
  credentials:,
  files:,
  commit_message:,
  pr_description:,
  pr_name:,
  author_details:,
  signature_key:,
  custom_headers:,
  labeler:,
  reviewers:,
  assignees:,
  milestone:,
  require_up_to_date_base:
)
  @source                  = source
  @branch_name             = branch_name
  @base_commit             = base_commit
  @credentials             = credentials
  @files                   = files
  @commit_message          = commit_message
  @pr_description          = pr_description
  @pr_name                 = pr_name
  @author_details          = author_details
  @signature_key           = signature_key
  @custom_headers          = custom_headers
  @labeler                 = labeler
  @reviewers               = reviewers
  @assignees               = assignees
  @milestone               = milestone
  @require_up_to_date_base = require_up_to_date_base
end

Instance Attribute Details

#assigneesObject (readonly)

Returns the value of attribute assignees.



64
65
66
# File 'lib/dependabot/pull_request_creator/github.rb', line 64

def assignees
  @assignees
end

#author_detailsObject (readonly)

Returns the value of attribute author_details.



49
50
51
# File 'lib/dependabot/pull_request_creator/github.rb', line 49

def author_details
  @author_details
end

#base_commitObject (readonly)

Returns the value of attribute base_commit.



31
32
33
# File 'lib/dependabot/pull_request_creator/github.rb', line 31

def base_commit
  @base_commit
end

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



28
29
30
# File 'lib/dependabot/pull_request_creator/github.rb', line 28

def branch_name
  @branch_name
end

#commit_messageObject (readonly)

Returns the value of attribute commit_message.



46
47
48
# File 'lib/dependabot/pull_request_creator/github.rb', line 46

def commit_message
  @commit_message
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



34
35
36
# File 'lib/dependabot/pull_request_creator/github.rb', line 34

def credentials
  @credentials
end

#custom_headersObject (readonly)

Returns the value of attribute custom_headers.



55
56
57
# File 'lib/dependabot/pull_request_creator/github.rb', line 55

def custom_headers
  @custom_headers
end

#filesObject (readonly)

Returns the value of attribute files.



37
38
39
# File 'lib/dependabot/pull_request_creator/github.rb', line 37

def files
  @files
end

#labelerObject (readonly)

Returns the value of attribute labeler.



58
59
60
# File 'lib/dependabot/pull_request_creator/github.rb', line 58

def labeler
  @labeler
end

#milestoneObject (readonly)

Returns the value of attribute milestone.



67
68
69
# File 'lib/dependabot/pull_request_creator/github.rb', line 67

def milestone
  @milestone
end

#pr_descriptionObject (readonly)

Returns the value of attribute pr_description.



40
41
42
# File 'lib/dependabot/pull_request_creator/github.rb', line 40

def pr_description
  @pr_description
end

#pr_nameObject (readonly)

Returns the value of attribute pr_name.



43
44
45
# File 'lib/dependabot/pull_request_creator/github.rb', line 43

def pr_name
  @pr_name
end

#reviewersObject (readonly)

Returns the value of attribute reviewers.



61
62
63
# File 'lib/dependabot/pull_request_creator/github.rb', line 61

def reviewers
  @reviewers
end

#signature_keyObject (readonly)

Returns the value of attribute signature_key.



52
53
54
# File 'lib/dependabot/pull_request_creator/github.rb', line 52

def signature_key
  @signature_key
end

#sourceObject (readonly)

Returns the value of attribute source.



25
26
27
# File 'lib/dependabot/pull_request_creator/github.rb', line 25

def source
  @source
end

Instance Method Details

#createObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/dependabot/pull_request_creator/github.rb', line 127

def create
  Dependabot.logger.info(
    "Initiating Github pull request."
  )

  if branch_exists?(branch_name) && no_pull_request_exists?
    Dependabot.logger.info(
      "Existing branch \"#{branch_name}\" found. Pull request not created."
    )
    raise BranchAlreadyExists, "Duplicate branch #{branch_name} already exists"
  end

  if branch_exists?(branch_name) && open_pull_request_exists?
    number = github_integer(T.must(open_pull_requests.first), :number, "pull request")
    raise UnmergedPRExists, "PR ##{number} already exists"
  end
  if require_up_to_date_base? && !base_commit_is_up_to_date?
    raise BaseCommitNotUpToDate, "HEAD #{head_commit} does not match base #{base_commit}"
  end

  create_annotated_pull_request
rescue AnnotationError, Octokit::Error => e
  handle_error(e)
end