Class: Octopolo::GitHub::PullRequest

Inherits:
Issue
  • Object
show all
Extended by:
CLIWrapper, ConfigWrapper, UserConfigWrapper
Defined in:
lib/octopolo/github/pull_request.rb

Constant Summary

Constants inherited from Issue

Issue::CommentFailed, Issue::MissingParameter, Issue::NotFound

Instance Attribute Summary

Attributes included from CLIWrapper

#cli

Attributes included from ConfigWrapper

#config

Attributes included from UserConfigWrapper

#user_config

Attributes inherited from Issue

#number, #repo_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Issue

#add_labels, #body, #comments, #exclude_octopolo_user, #external_urls, #human_app_name, #initialize, #remove_labels, #title, #url, #write_comment

Constructor Details

This class inherits a constructor from Octopolo::GitHub::Issue

Class Method Details

.closed(repo_name) ⇒ Object

Public: All closed pull requests for a given repo

repo_name - Full name (“account/repo”) of the repo in question

Returns an Array of PullRequest objects



18
19
20
21
22
# File 'lib/octopolo/github/pull_request.rb', line 18

def self.closed repo_name
  GitHub.pull_requests(repo_name, "closed").map do |data|
    new repo_name, data.number, data
  end
end

.create(repo_name, options) ⇒ Object

Public: Create a pull request for the given repo

repo_name - Full name (“account/repo”) of the repo in question options - Hash of pull request information

title: Title of the pull request
description: Brief description of the pull request
release: Boolean indicating if the pull request is for Release
destination_branch: Which branch to merge into
source_branch: Which branch to be merged

Returns a PullRequest instance



35
36
37
38
39
40
# File 'lib/octopolo/github/pull_request.rb', line 35

def self.create repo_name, options
  # create via the API
  creator = PullRequestCreator.perform(repo_name, options)
  # wrap in our class
  new repo_name, creator.number, creator.data
end

.currentObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/octopolo/github/pull_request.rb', line 80

def self.current
  current_branch = Git.current_branch
  query = "repo:#{config.github_repo} type:pr is:open head:#{current_branch}"
  pulls = GitHub.search_issues(query)
  if pulls.total_count!= 1
    cli.say "Multiple pull requests found for branch #{current_branch}" if pulls.total_count > 1
    cli.say "No pull request found for branch #{current_branch}" if pulls.total_count < 1
    return nil
  else
    cli.say "Pull request for current branch is number #{pulls.items.first.number}"
    pulls.items.first

  end
rescue => e
  cli.say "An error occurred while getting the current branch: #{e.message}"
  return nil
end

Instance Method Details

#author_namesObject



64
65
66
# File 'lib/octopolo/github/pull_request.rb', line 64

def author_names
  exclude_octopolo_user commits.map(&:author_name).uniq
end

#branchObject



48
49
50
# File 'lib/octopolo/github/pull_request.rb', line 48

def branch
  data.head.ref
end

#commenter_namesObject



60
61
62
# File 'lib/octopolo/github/pull_request.rb', line 60

def commenter_names
  exclude_octopolo_user (comments.map{ |comment| GitHub::User.new(comment.user.).author_name }.uniq - author_names)
end

#commitsObject



68
69
70
# File 'lib/octopolo/github/pull_request.rb', line 68

def commits
  @commits ||= Commit.for_pull_request self
end

#dataObject



42
43
44
45
46
# File 'lib/octopolo/github/pull_request.rb', line 42

def data
  @data ||= GitHub.pull_request(repo_name, number)
rescue Octokit::NotFound
  raise NotFound
end

#mergeable?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/octopolo/github/pull_request.rb', line 52

def mergeable?
  data.mergeable
end

#statusObject



76
77
78
# File 'lib/octopolo/github/pull_request.rb', line 76

def status
  GitHub.status(repo_name, data.head.sha)[:state]
end

#status_checks_passed?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/octopolo/github/pull_request.rb', line 72

def status_checks_passed?
  status == 'success'
end

#weekObject



56
57
58
# File 'lib/octopolo/github/pull_request.rb', line 56

def week
  Week.parse data.closed_at
end