Class: Octopolo::Scripts::AcceptPull

Inherits:
Object
  • Object
show all
Includes:
CLIWrapper, ConfigWrapper, GitWrapper, Base
Defined in:
lib/octopolo/scripts/accept_pull.rb

Instance Attribute Summary collapse

Attributes included from CLIWrapper

#cli

Attributes included from ConfigWrapper

#config

Attributes included from GitWrapper

#git

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

included

Constructor Details

#initialize(pull_request_id, options = {}) ⇒ AcceptPull

Returns a new instance of AcceptPull.



21
22
23
24
# File 'lib/octopolo/scripts/accept_pull.rb', line 21

def initialize(pull_request_id, options={})
  @pull_request_id = pull_request_id
  @force = options[:force]
end

Instance Attribute Details

#pull_request_idObject

Returns the value of attribute pull_request_id.



14
15
16
# File 'lib/octopolo/scripts/accept_pull.rb', line 14

def pull_request_id
  @pull_request_id
end

Class Method Details

.execute(pull_request_id, options) ⇒ Object



16
17
18
19
# File 'lib/octopolo/scripts/accept_pull.rb', line 16

def self.execute(pull_request_id, options)
  pull_request_id ||= Integer(cli.prompt "Pull Request ID: ")
  new(pull_request_id, options).execute
end

Instance Method Details

#changelogObject



53
54
55
# File 'lib/octopolo/scripts/accept_pull.rb', line 53

def changelog
  @changelog ||= Changelog.new
end

#executeObject

Public: Perform the script



27
28
29
30
31
32
33
34
35
# File 'lib/octopolo/scripts/accept_pull.rb', line 27

def execute
  GitHub.connect do
    pull_request = GitHub::PullRequest.new(config.github_repo, pull_request_id)
    merge pull_request
    update_changelog pull_request
  end
rescue GitHub::PullRequest::NotFound
  cli.say "Unable to find a pull request #{pull_request_id} for #{config.github_repo}. Please verify."
end

#merge(pull_request) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/octopolo/scripts/accept_pull.rb', line 37

def merge pull_request
  Git.fetch
  if pull_request.mergeable?
    if pull_request.status_checks_passed? || @force
      cli.perform "git merge --no-ff origin/#{pull_request.branch} -m \"Merge pull request ##{pull_request_id} from origin/#{pull_request.branch}\""
    else
      cli.say 'Previous action not completed. Status checks have not passed on this pull request.'
      exit!
    end
  else
    cli.say "There is a merge conflict with this branch and #{config.deploy_branch}."
    cli.say "Please update this branch with #{config.deploy_branch} or perform the merge manually and fix any conflicts"
    exit!
  end
end

#update_changelog(pull_request) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/octopolo/scripts/accept_pull.rb', line 57

def update_changelog pull_request
  title = pull_request.title
  authors = pull_request.author_names
  commenters = pull_request.commenter_names
  url = pull_request.url

  changelog.open do |log|
    log.puts "* #{title}"
    log.puts
    log.puts "  > #{authors.join(", ")}: #{commenters.join(', ')}: #{url}"
    log.puts
  end
end