Method: Hub::Commands#pull_request
- Defined in:
- lib/hub/commands.rb
#pull_request(args) ⇒ Object Also known as: e_note
$ hub pull-request $ hub pull-request “My humble contribution” $ hub pull-request github.com/rtomayko/tilt/issues/92
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/hub/commands.rb', line 125 def pull_request(args) args.shift = { } force = explicit_owner = false base_project = local_repo.main_project tracked_branch, head_project = remote_branch_and_project(method(:github_user)) unless current_branch abort "Aborted: not currently on any branch." end unless base_project abort "Aborted: the origin remote doesn't point to a GitHub repository." end from_github_ref = lambda do |ref, context_project| if ref.index(':') owner, ref = ref.split(':', 2) project = github_project(context_project.name, owner) end [project || context_project, ref] end while arg = args.shift case arg when '-f' force = true when '-F', '--file' file = args.shift text = file == '-' ? $stdin.read : File.read(file) [:title], [:body] = read_msg(text) when '-m', '--message' text = args.shift [:title], [:body] = read_msg(text) when '-b' base_project, [:base] = from_github_ref.call(args.shift, base_project) when '-h' head = args.shift explicit_owner = !!head.index(':') head_project, [:head] = from_github_ref.call(head, head_project) when '-i' [:issue] = args.shift when '-o', '--browse' open_with_browser = true else if url = resolve_github_url(arg) and url.project_path =~ /^issues\/(\d+)/ [:issue] = $1 base_project = url.project elsif ![:title] && arg.index('-') != 0 [:title] = arg warn "hub: Specifying pull request title without a flag is deprecated." warn "Please use one of `-m' or `-F' options." else abort "invalid argument: #{arg}" end end end if [:issue] warn "Warning: Issue to pull request conversion is deprecated and might not work in the future." end [:project] = base_project [:base] ||= master_branch.short_name if [:head].nil? && tracked_branch if !tracked_branch.remote? # The current branch is tracking another local branch. Pretend there is # no upstream configuration at all. tracked_branch = nil elsif base_project == head_project and tracked_branch.short_name == [:base] $stderr.puts "Aborted: head branch is the same as base (#{[:base].inspect})" warn "(use `-h <branch>` to specify an explicit pull request head)" abort end end [:head] ||= (tracked_branch || current_branch).short_name remote_branch = "#{head_project.remote}/#{[:head]}" [:head] = "#{head_project.owner}:#{[:head]}" if !force and tracked_branch and local_commits = rev_list(remote_branch, nil) $stderr.puts "Aborted: #{local_commits.split("\n").size} commits are not yet pushed to #{remote_branch}" warn "(use `-f` to force submit a pull request anyway)" abort end if args.noop? puts "Would request a pull to #{base_project.owner}:#{[:base]} from #{[:head]}" exit end unless [:title] or [:issue] base_branch = "#{base_project.remote}/#{[:base]}" commits = rev_list(base_branch, remote_branch).to_s.split("\n") case commits.size when 0 = commit_summary = nil when 1 format = '%s%n%+b' = git_command "show -s --format='#{format}' #{commits.first}" commit_summary = nil else format = '%h (%aN, %ar)%n%w(78,3,3)%s%n%+b' = nil commit_summary = git_command "log --no-color --format='%s' --cherry '%s...%s'" % [ format, base_branch.to_s.gsub("'", "\\'"), remote_branch.to_s.gsub("'", "\\'") ] end [:title], [:body] = pullrequest_editmsg(commit_summary) { |msg, , cc| ||= msg.puts if msg.puts "" msg.puts "#{cc} Requesting a pull to #{base_project.owner}:#{[:base]} from #{[:head]}" msg.puts "#{cc}" msg.puts "#{cc} Write a message for this pull request. The first block" msg.puts "#{cc} of text is the title and the rest is description." } end pull = api_client.create_pullrequest() args.push('-u') unless open_with_browser browse_command(args) do pull['html_url'] end rescue GitHubAPI::Exceptions response = $!.response display_api_exception("creating pull request", response) if 404 == response.status base_url = base_project.web_url.split('://', 2).last warn "Are you sure that #{base_url} exists?" end exit 1 else delete_editmsg end |