Module: Jenkins::Bundle::Update::Pr

Defined in:
lib/jenkins/bundle/update/pr.rb,
lib/jenkins/bundle/update/pr/version.rb

Constant Summary collapse

VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.create_if_needed(git_username: nil, git_email: nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jenkins/bundle/update/pr.rb', line 73

def self.create_if_needed(git_username: nil, git_email: nil)
  raise "$GITHUB_PROJECT_USERNAME isn't set" unless ENV['GITHUB_PROJECT_USERNAME']
  raise "$GITHUB_PROJECT_REPONAME isn't set" unless ENV['GITHUB_PROJECT_REPONAME']
  raise "$GITHUB_ACCESS_TOKEN isn't set" unless ENV['GITHUB_ACCESS_TOKEN']

  return unless need?

  now = Time.now

  git_username ||= client.user.
  git_email    ||= "#{git_username}@users.noreply.github.com"

  repo_full_name = "#{ENV['GITHUB_PROJECT_USERNAME']}/#{ENV['GITHUB_PROJECT_REPONAME']}"
  branch         = "bundle-update-#{now.strftime('%Y%m%d%H%M%S')}"

  create_branch(git_username, git_email, branch)
  pull_request = create_pull_request(repo_full_name, branch, now)
  add_comment_of_compare_linker(repo_full_name, pull_request[:number])
end