pull_request.feature 36.0 KB
Newer Older
1 2
Feature: hub pull-request
  Background:
3
    Given I am in "git://github.com/mislav/coral.git" git repo
4
    And I am "mislav" on github.com with OAuth token "OTOKEN"
5
    And the git commit editor is "vim"
6

7
  Scenario: Detached HEAD
8
    Given I am in detached HEAD
9 10 11 12
    When I run `hub pull-request`
    Then the stderr should contain "Aborted: not currently on any branch.\n"
    And the exit status should be 1

13 14 15 16 17 18 19 20 21 22 23 24
  Scenario: Non-GitHub repo
    Given the "origin" remote has url "mygh:Manganeez/repo.git"
    When I run `hub pull-request`
    Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
    And the exit status should be 1

  Scenario: Create pull request respecting "insteadOf" configuration
    Given the "origin" remote has url "mygh:Manganeez/repo.git"
    When I successfully run `git config url."git@github.com:".insteadOf mygh:`
    Given the GitHub API server:
      """
      post('/repos/Manganeez/repo/pulls') {
25
        assert :base  => 'master',
26
               :head  => 'Manganeez:master',
27
               :title => 'here we go'
28
        status 201
29 30 31
        json :html_url => "https://github.com/Manganeez/repo/pull/12"
      }
      """
32
    When I successfully run `hub pull-request -m "here we go"`
33
    Then the output should contain exactly "https://github.com/Manganeez/repo/pull/12\n"
34 35 36 37 38 39

  Scenario: With Unicode characters
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 400 if request.content_charset != 'utf-8'
40
        assert :title => 'ăéñøü'
41
        status 201
42 43 44
        json :html_url => "the://url"
      }
      """
45
    When I successfully run `hub pull-request -m ăéñøü`
46
    Then the output should contain exactly "the://url\n"
47

48 49 50
  Scenario: Invalid flag
    When I run `hub pull-request -yelp`
    Then the stderr should contain "unknown shorthand flag: 'y' in -yelp\n"
J
Jingwen Owen Ou 已提交
51
    And the exit status should be 1
52

53 54 55 56 57 58 59 60 61 62 63
  Scenario: With Unicode characters in the changelog
    Given the text editor adds:
      """
      I <3 encodings
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 400 if request.content_charset != 'utf-8'
        assert :title => 'I <3 encodings',
               :body => 'ăéñøü'
64
        status 201
65 66 67 68 69 70 71 72 73 74
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    Given I make a commit with message "ăéñøü"
    And the "topic" branch is pushed to "origin/topic"
    When I successfully run `hub pull-request`
    Then the output should contain exactly "the://url\n"

75 76 77 78 79 80 81 82
  Scenario: Default message for single-commit pull request
    Given the text editor adds:
      """
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 400 if request.content_charset != 'utf-8'
83
        assert :title => 'This is somewhat of a longish title that does not get wrapped & references #1234',
84
               :body => 'Hello'
85
        status 201
86 87 88 89 90
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
91 92 93 94 95 96 97
    Given I make a commit with message:
      """
      This is somewhat of a longish title that does not get wrapped & references #1234

      Hello
      Signed-off-by: NAME <email@example.com>
      """
98 99 100 101
    And the "topic" branch is pushed to "origin/topic"
    When I successfully run `hub pull-request`
    Then the output should contain exactly "the://url\n"

102 103 104 105 106 107 108 109
  Scenario: Single-commit with pull request template
    Given the git commit editor is "true"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 400 if request.content_charset != 'utf-8'
        assert :title => 'Commit title',
               :body => <<BODY.chomp
110 111
      Commit body

112

113
       This is the pull request template
114

115 116
      Another line of template
      BODY
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    And I make a commit with message:
      """
      Commit title

      Commit body
      """
    And the "topic" branch is pushed to "origin/topic"
    Given a file named "pull_request_template.md" with:
      """
132
       This is the pull request template
133 134 135 136 137 138

      Another line of template
      """
    When I successfully run `hub pull-request`
    Then the output should contain exactly "the://url\n"

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  Scenario: Single-commit with PULL_REQUEST_TEMPLATE directory
    Given the git commit editor is "true"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => 'Commit title',
               :body => 'Commit body'
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    And I make a commit with message:
      """
      Commit title

      Commit body
      """
    And the "topic" branch is pushed to "origin/topic"
    And a directory named "PULL_REQUEST_TEMPLATE"
    When I successfully run `hub pull-request`
    Then the output should contain exactly "the://url\n"

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
  Scenario: Single-commit pull request with "--no-edit"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => 'Commit title 1',
               :body => 'Commit body 1'
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    Given I make a commit with message:
      """
      Commit title 1

      Commit body 1
      """
    And the "topic" branch is pushed to "origin/topic"
    When I successfully run `hub pull-request --no-edit`
    Then the output should contain exactly "the://url\n"

  Scenario: Multiple-commit pull request with "--no-edit"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => 'Commit title 1',
               :body => 'Commit body 1'
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    Given I make a commit with message:
      """
      Commit title 1

      Commit body 1
      """
    Given I make a commit with message:
      """
      Commit title 2

      Commit body 2
      """
    And the "topic" branch is pushed to "origin/topic"
    When I successfully run `hub pull-request --no-edit`
    Then the output should contain exactly "the://url\n"

  Scenario: Pull request with "--push" and "--no-edit"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => 'Commit title 1',
               :body => 'Commit body 1'
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
    Given I make a commit with message:
      """
      Commit title 1

      Commit body 1
      """
    When I successfully run `hub pull-request --push --no-edit`
    Then the output should contain exactly "the://url\n"

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
  Scenario: Message template should include git log summary between base and head
    Given the text editor adds:
      """
      Hello
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        status 500
      }
      """
    Given I am on the "master" branch
    And I make a commit with message "One on master"
    And I make a commit with message "Two on master"
    And the "master" branch is pushed to "origin/master"
    Given I successfully run `git reset --hard HEAD~2`
    And I successfully run `git checkout --quiet -B topic origin/master`
    Given I make a commit with message "One on topic"
    And I make a commit with message "Two on topic"
    Given the "topic" branch is pushed to "origin/topic"
    And I successfully run `git reset --hard HEAD~1`
    When I run `hub pull-request`
    Given the SHAs and timestamps are normalized in ".git/PULLREQ_EDITMSG"
    Then the file ".git/PULLREQ_EDITMSG" should contain exactly:
      """
      Hello


# Requesting a pull to mislav:master from mislav:topic
#
# Write a message for this pull request. The first block
J
Justin Campbell 已提交
265
# of text is the title and the rest is the description.
266 267 268 269 270 271 272 273 274 275 276
#
# Changes:
#
# SHA1SHA (Hub, 0 seconds ago)
#    Two on topic
#
# SHA1SHA (Hub, 0 seconds ago)
#    One on topic

      """

277 278 279 280 281
  Scenario: Non-existing base
    Given the GitHub API server:
      """
      post('/repos/origin/coral/pulls') { 404 }
      """
282
    When I run `hub pull-request -b origin:master -m here`
283 284 285 286 287 288
    Then the exit status should be 1
    Then the stderr should contain:
      """
      Error creating pull request: Not Found (HTTP 404)
      Are you sure that github.com/origin/coral exists?
      """
289 290 291 292 293 294

  Scenario: Supplies User-Agent string to API calls
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 400 unless request.user_agent.include?('Hub')
295
        status 201
296 297 298
        json :html_url => "the://url"
      }
      """
299
    When I successfully run `hub pull-request -m useragent`
300
    Then the output should contain exactly "the://url\n"
301 302

  Scenario: Text editor adds title and body
303
    Given the text editor adds:
304 305 306 307 308 309 310 311
      """
      This title comes from vim!

      This body as well.
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
312 313
        assert :title => 'This title comes from vim!',
               :body  => 'This body as well.'
314
        status 201
315 316 317 318 319 320
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    When I successfully run `hub pull-request`
    Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
    And the file ".git/PULLREQ_EDITMSG" should not exist
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

  Scenario: Text editor adds title and body with multiple lines
    Given the text editor adds:
      """


      This title is on the third line


      This body


      has multiple
      lines.

      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => 'This title is on the third line',
               :body  => "This body\n\n\nhas multiple\nlines."
342
        status 201
343 344 345 346 347 348
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    When I successfully run `hub pull-request`
    Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
    And the file ".git/PULLREQ_EDITMSG" should not exist
349

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
  Scenario: Text editor with custom commentchar
    Given git "core.commentchar" is set to "/"
    And the text editor adds:
      """
      # Dat title

      / This line is commented out.

      Dem body.
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :title => '# Dat title',
               :body  => 'Dem body.'
365
        status 201
366 367 368 369 370 371
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request`
    Then the output should contain exactly "the://url\n"

372
  Scenario: Failed pull request preserves previous message
373
    Given the text editor adds:
374 375 376 377 378 379 380
      """
      This title will fail
      """
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        halt 422 if params[:title].include?("fail")
381 382
        assert :body => "This title will fail",
               :title => "But this title will prevail"
383
        status 201
384 385 386 387 388 389 390
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    When I run `hub pull-request`
    Then the exit status should be 1
    And the stderr should contain exactly:
      """
391
      Error creating pull request: Unprocessable Entity (HTTP 422)\n
392 393 394 395 396 397 398 399 400
      """
    Given the text editor adds:
      """
      But this title will prevail
      """
    When I successfully run `hub pull-request`
    Then the file ".git/PULLREQ_EDITMSG" should not exist

  Scenario: Text editor fails
401
    Given the text editor exits with error status
402 403 404 405 406
    And an empty file named ".git/PULLREQ_EDITMSG"
    When I run `hub pull-request`
    Then the stderr should contain "error using text editor for pull request message"
    And the exit status should be 1
    And the file ".git/PULLREQ_EDITMSG" should not exist
407 408 409 410 411

  Scenario: Title and body from file
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
412 413
        assert :title => 'Title from file',
               :body  => "Body from file as well.\n\nMultiline, even!"
414
        status 201
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    And a file named "pullreq-msg" with:
      """
      Title from file

      Body from file as well.

      Multiline, even!
      """
    When I successfully run `hub pull-request -F pullreq-msg`
    Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
    And the file ".git/PULLREQ_EDITMSG" should not exist

M
m_nakamura145 已提交
430 431 432 433
  Scenario: Edit title and body from file
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
434 435 436
        assert :title => 'Hello from editor',
               :body  => "Title from file\n\nBody from file as well."
        status 201
M
m_nakamura145 已提交
437 438 439 440 441 442 443 444 445
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    And a file named "pullreq-msg" with:
      """
      Title from file

      Body from file as well.
      """
446
    And the text editor adds:
M
m_nakamura145 已提交
447
      """
448
      Hello from editor
M
m_nakamura145 已提交
449
      """
450 451
    When I successfully run `hub pull-request -F pullreq-msg --edit`
    Then the file ".git/PULLREQ_EDITMSG" should not exist
M
m_nakamura145 已提交
452

453 454 455 456
  Scenario: Title and body from stdin
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
457
        assert :title => 'Unix piping is great',
458
               :body  => 'Just look at this ăéñøü'
459
        status 201
460 461 462 463 464 465 466 467
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    When I run `hub pull-request -F -` interactively
    And I pass in:
      """
      Unix piping is great

468
      Just look at this ăéñøü
469 470 471 472 473 474 475 476 477
      """
    Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
    And the exit status should be 0
    And the file ".git/PULLREQ_EDITMSG" should not exist

  Scenario: Title and body from command-line argument
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
478 479
        assert :title => 'I am just a pull',
               :body  => 'A little pull'
480
        status 201
481 482 483 484 485 486
        json :html_url => "https://github.com/mislav/coral/pull/12"
      }
      """
    When I successfully run `hub pull-request -m "I am just a pull\n\nA little pull"`
    Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
    And the file ".git/PULLREQ_EDITMSG" should not exist
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

  Scenario: Error when implicit head is the same as base
    Given I am on the "master" branch with upstream "origin/master"
    When I run `hub pull-request`
    Then the stderr should contain exactly:
      """
      Aborted: head branch is the same as base ("master")
      (use `-h <branch>` to specify an explicit pull request head)\n
      """

  Scenario: Explicit head
    Given I am on the "master" branch
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head => 'mislav:feature'
503
        status 201
504 505 506 507 508 509 510 511 512 513 514 515
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -h feature -m message`
    Then the output should contain exactly "the://url\n"

  Scenario: Explicit head with owner
    Given I am on the "master" branch
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head => 'mojombo:feature'
516
        status 201
517 518 519 520 521 522 523 524 525 526 527 528
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -h mojombo:feature -m message`
    Then the output should contain exactly "the://url\n"

  Scenario: Explicit base
    Given I am on the "feature" branch
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :base => 'develop'
529
        status 201
530 531 532 533 534 535
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -b develop -m message`
    Then the output should contain exactly "the://url\n"

536 537
  Scenario: Implicit base by detecting main branch
    Given the default branch for "origin" is "develop"
538
    And I make a commit
539 540 541 542 543
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :base => 'develop',
               :head => 'mislav:master'
544
        status 201
545 546 547 548 549 550
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m message`
    Then the output should contain exactly "the://url\n"

551 552 553 554 555 556
  Scenario: Explicit base with owner
    Given I am on the "master" branch
    Given the GitHub API server:
      """
      post('/repos/mojombo/coral/pulls') {
        assert :base => 'develop'
557
        status 201
558 559 560 561 562 563 564 565 566 567 568 569
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -b mojombo:develop -m message`
    Then the output should contain exactly "the://url\n"

  Scenario: Explicit base with owner and repo name
    Given I am on the "master" branch
    Given the GitHub API server:
      """
      post('/repos/mojombo/coralify/pulls') {
        assert :base => 'develop'
570
        status 201
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -b mojombo/coralify:develop -m message`
    Then the output should contain exactly "the://url\n"

  Scenario: Error when there are unpushed commits
    Given I am on the "feature" branch with upstream "origin/feature"
    When I make 2 commits
    And I run `hub pull-request`
    Then the stderr should contain exactly:
      """
      Aborted: 2 commits are not yet pushed to origin/feature
      (use `-f` to force submit a pull request anyway)\n
      """

  Scenario: Ignore unpushed commits with `-f`
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head => 'mislav:feature'
593
        status 201
594 595 596 597 598 599 600 601 602 603 604
        json :html_url => "the://url"
      }
      """
    When I make 2 commits
    And I successfully run `hub pull-request -f -m message`
    Then the output should contain exactly "the://url\n"

  Scenario: Pull request fails on the server
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
605
      tries = 0
606
      post('/repos/mislav/coral/pulls') {
607 608 609 610 611 612 613 614 615 616 617 618
        tries += 1
        if tries == 1
          status 422
          json :message => 'Validation Failed',
               :errors => [{
                 :resource => 'PullRequest',
                 :code => 'invalid',
                 :field => 'head'
               }]
        else
          status 400
        end
619 620 621 622 623 624
      }
      """
    When I run `hub pull-request -m message`
    Then the stderr should contain exactly:
      """
      Error creating pull request: Unprocessable Entity (HTTP 422)
625
      Invalid value for "head"\n
626
      """
627
    And the exit status should be 1
628 629 630 631 632 633

  Scenario: Convert issue to pull request
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
634
        assert :issue => 92
635
        status 201
636 637 638 639
        json :html_url => "https://github.com/mislav/coral/pull/92"
      }
      """
    When I successfully run `hub pull-request -i 92`
640 641 642 643 644
    Then the output should contain exactly:
      """
      https://github.com/mislav/coral/pull/92
      Warning: Issue to pull request conversion is deprecated and might not work in the future.\n
      """
645 646 647 648 649 650

  Scenario: Convert issue URL to pull request
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
651
        assert :issue => 92
652
        status 201
653 654 655 656
        json :html_url => "https://github.com/mislav/coral/pull/92"
      }
      """
    When I successfully run `hub pull-request https://github.com/mislav/coral/issues/92`
657 658 659 660 661
    Then the output should contain exactly:
      """
      https://github.com/mislav/coral/pull/92
      Warning: Issue to pull request conversion is deprecated and might not work in the future.\n
      """
662 663 664 665 666 667 668

  Scenario: Enterprise host
    Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
    And I am "mislav" on git.my.org with OAuth token "FITOKEN"
    And "git.my.org" is a whitelisted Enterprise host
    Given the GitHub API server:
      """
669 670 671
      post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
        assert :base => 'master',
               :head => 'mislav:master'
672
        status 201
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m enterprisey`
    Then the output should contain exactly "the://url\n"

  Scenario: Enterprise remote witch matching branch but no tracking
    Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
    And I am "mislav" on git.my.org with OAuth token "FITOKEN"
    And "git.my.org" is a whitelisted Enterprise host
    And I am on the "feature" branch pushed to "origin/feature"
    Given the GitHub API server:
      """
      post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
        assert :base => 'master',
               :head => 'mislav:feature'
689
        status 201
690 691 692 693 694
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m enterprisey`
    Then the output should contain exactly "the://url\n"
695 696 697 698 699 700 701 702 703 704 705

  Scenario: Create pull request from branch on the same remote
    Given the "origin" remote has url "git://github.com/github/coral.git"
    And the "mislav" remote has url "git://github.com/mislav/coral.git"
    And I am on the "feature" branch pushed to "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/github/coral/pulls') {
        assert :base  => 'master',
               :head  => 'github:feature',
               :title => 'hereyougo'
706
        status 201
707 708 709 710 711
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"
712 713 714 715 716 717 718 719 720 721 722

  Scenario: Create pull request from branch on the personal fork case sensitive
    Given the "origin" remote has url "git://github.com/github/coral.git"
    And the "doge" remote has url "git://github.com/Mislav/coral.git"
    And I am on the "feature" branch pushed to "doge/feature"
    Given the GitHub API server:
      """
      post('/repos/github/coral/pulls') {
        assert :base  => 'master',
               :head  => 'Mislav:feature',
               :title => 'hereyougo'
723
        status 201
724 725 726 727 728
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"
729 730 731 732 733 734 735 736 737 738 739

  Scenario: Create pull request from branch on the personal fork
    Given the "origin" remote has url "git://github.com/github/coral.git"
    And the "doge" remote has url "git://github.com/mislav/coral.git"
    And I am on the "feature" branch pushed to "doge/feature"
    Given the GitHub API server:
      """
      post('/repos/github/coral/pulls') {
        assert :base  => 'master',
               :head  => 'mislav:feature',
               :title => 'hereyougo'
740
        status 201
741 742 743 744 745 746
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"

747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
  Scenario: Create pull request from branch on the personal fork, capitalized
    Given the "origin" remote has url "git://github.com/LightAlf/FirstRepo.git"
    And the "Kristinita" remote has url "git@github.com:Kristinita/FirstRepo.git"
    And I am on the "add-py3kwarn" branch pushed to "Kristinita/add-py3kwarn"
    And I am "Kristinita" on github.com with OAuth token "OTOKEN"
    Given the GitHub API server:
      """
      post('/repos/LightAlf/FirstRepo/pulls') {
        assert :base  => 'master',
               :head  => 'Kristinita:add-py3kwarn',
               :title => 'hereyougo'
        status 201
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"

765 766 767 768 769 770 771 772 773
  Scenario: Create pull request to "upstream" remote
    Given the "upstream" remote has url "git://github.com/github/coral.git"
    And I am on the "master" branch pushed to "origin/master"
    Given the GitHub API server:
      """
      post('/repos/github/coral/pulls') {
        assert :base  => 'master',
               :head  => 'mislav:master',
               :title => 'hereyougo'
774
        status 201
775 776 777 778 779
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"
780 781 782 783 784

  Scenario: Open pull request in web browser
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
785
        status 201
786 787 788 789 790
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -o -m hereyougo`
    Then "open the://url" should be run
791 792 793

  Scenario: Current branch is tracking local branch
    Given git "push.default" is set to "upstream"
794
    And I make a commit
795 796 797 798 799 800
    And I am on the "feature" branch with upstream "refs/heads/master"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :base  => 'master',
               :head  => 'mislav:feature'
801
        status 201
802 803 804 805 806
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"
J
Jingwen Owen Ou 已提交
807 808 809 810

  Scenario: Branch with quotation mark in name
    Given I am on the "feat'ure" branch with upstream "origin/feat'ure"
    Given the GitHub API server:
811 812 813
      """
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feat'ure"
814
        status 201
815 816 817
        json :html_url => "the://url"
      }
      """
J
Jingwen Owen Ou 已提交
818 819
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"
M
Marko Mikulicic 已提交
820

821
  Scenario: Pull request with assignees
M
Marko Mikulicic 已提交
822 823 824 825 826
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
827
        status 201
M
Marko Mikulicic 已提交
828 829 830
        json :html_url => "the://url", :number => 1234
      }
      patch('/repos/mislav/coral/issues/1234') {
831
        assert :assignees => ["mislav", "josh", "pcorpet"], :labels => :no
M
Marko Mikulicic 已提交
832 833 834
        json :html_url => "the://url"
      }
      """
835
    When I successfully run `hub pull-request -m hereyougo -a mislav,josh -apcorpet`
M
Marko Mikulicic 已提交
836
    Then the output should contain exactly "the://url\n"
837

838 839 840 841 842 843 844 845 846 847
  Scenario: Pull request with reviewers
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
        status 201
        json :html_url => "the://url", :number => 1234
      }
      post('/repos/mislav/coral/pulls/1234/requested_reviewers') {
848
        halt 415 unless request.accept?('application/vnd.github.thor-preview+json')
849
        assert :reviewers => ["mislav", "josh", "pcorpet"]
850
        assert :team_reviewers => ["robots", "js"]
851
        status 201
852 853 854
        json :html_url => "the://url"
      }
      """
855
    When I successfully run `hub pull-request -m hereyougo -r mislav,josh -rgithub/robots -rpcorpet -r github/js`
856 857
    Then the output should contain exactly "the://url\n"

858 859 860 861
  Scenario: Pull request with milestone
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
      get('/repos/mislav/coral/milestones') {
        status 200
        json [
          { :number => 237, :title => "prerelease" },
          { :number => 1337, :title => "v1" },
          { :number => 41319, :title => "Hello World!" }
        ]
      }
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
        status 201
        json :html_url => "the://url", :number => 1234
      }
      patch('/repos/mislav/coral/issues/1234') {
        assert :milestone => 41319
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo -M "Hello World!"`
    Then the output should contain exactly "the://url\n"

  Scenario: Pull request with case-insensitive milestone
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      get('/repos/mislav/coral/milestones') {
        status 200
        json [
          { :number => 237, :title => "prerelease" },
          { :number => 1337, :title => "v1" },
          { :number => 41319, :title => "Hello World!" }
        ]
      }
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
        status 201
        json :html_url => "the://url", :number => 1234
      }
      patch('/repos/mislav/coral/issues/1234') {
        assert :milestone => 41319
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo -M "hello world!"`
    Then the output should contain exactly "the://url\n"

  Scenario: Pull request uses integer milestone number for BC
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      get('/repos/mislav/coral/milestones') {
        status 200
        json [{ :number => 237, :title => "prerelease" }]
      }
916 917
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
918
        status 201
919 920 921
        json :html_url => "the://url", :number => 1234
      }
      patch('/repos/mislav/coral/issues/1234') {
922
        assert :milestone => 55
923 924 925
        json :html_url => "the://url"
      }
      """
926
    When I successfully run `hub pull-request -m hereyougo -M 55`
927 928
    Then the output should contain exactly "the://url\n"

929 930 931 932 933 934 935 936 937 938 939 940 941
  Scenario: Pull request fails with unknown milestone before it's created
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      get('/repos/mislav/coral/milestones') {
        status 200
        json []
      }
      """
    When I run `hub pull-request -m hereyougo -M "unknown"`
    Then the exit status should be 1
    And the stderr should contain exactly "error: no milestone found with name 'unknown'\n"

942
  Scenario: Pull request with labels
M
Marko Mikulicic 已提交
943 944 945 946 947
    Given I am on the "feature" branch with upstream "origin/feature"
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        assert :head  => "mislav:feature"
948
        status 201
M
Marko Mikulicic 已提交
949 950 951
        json :html_url => "the://url", :number => 1234
      }
      patch('/repos/mislav/coral/issues/1234') {
952
        assert :labels => ["feature", "release", "docs"], :assignees => :no
953 954 955
        json :html_url => "the://url"
      }
      """
956
    When I successfully run `hub pull-request -m hereyougo -l feature,release -ldocs`
957
    Then the output should contain exactly "the://url\n"
958 959 960 961 962 963 964 965 966 967 968

  Scenario: Pull request to a fetch-only upstream
    Given the "upstream" remote has url "git://github.com/github/coral.git"
    And the "upstream" remote has push url "no_push"
    And I am on the "master" branch pushed to "origin/master"
    Given the GitHub API server:
      """
      post('/repos/github/coral/pulls') {
        assert :base  => 'master',
               :head  => 'mislav:master',
               :title => 'hereyougo'
969
        status 201
M
Marko Mikulicic 已提交
970 971 972
        json :html_url => "the://url"
      }
      """
973
    When I successfully run `hub pull-request -m hereyougo`
M
Marko Mikulicic 已提交
974
    Then the output should contain exactly "the://url\n"
975 976 977 978 979 980

  Scenario: Pull request with redirect
    Given the "origin" remote has url "https://github.com/mislav/coral.git"
    And I am on the "feature" branch pushed to "origin/feature"
    Given the GitHub API server:
      """
981 982 983 984 985 986
      get('/repos/mislav/coral') {
        redirect 'https://api.github.com/repositories/12345', 301
      }
      get('/repositories/12345') {
        json :name => 'coralify', :owner => { :login => 'coral-org' }
      }
987 988 989 990 991
      post('/repos/mislav/coral/pulls') {
        redirect 'https://api.github.com/repositories/12345', 307
      }
      post('/repositories/12345', :host_name => 'api.github.com') {
        assert :base  => 'master',
992
               :head  => 'coral-org:feature',
993
               :title => 'hereyougo'
994
        status 201
995 996 997 998 999 1000
        json :html_url => "the://url"
      }
      """
    When I successfully run `hub pull-request -m hereyougo`
    Then the output should contain exactly "the://url\n"

1001
  Scenario: Default message with --push
N
Natalie Weizenbaum 已提交
1002
    Given the git commit editor is "true"
1003 1004 1005
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
M
Mislav Marohnić 已提交
1006
        assert :title => 'The commit I never pushed',
1007 1008 1009 1010 1011 1012 1013
               :body => nil
        status 201
        json :html_url => "the://url"
      }
      """
    Given I am on the "master" branch pushed to "origin/master"
    When I successfully run `git checkout --quiet -b topic`
M
Mislav Marohnić 已提交
1014
    Given I make a commit with message "The commit I never pushed"
1015 1016
    When I successfully run `hub pull-request -p`
    Then the output should contain exactly "the://url\n"
1017
    And "git push --set-upstream origin HEAD:topic" should be run
1018 1019 1020 1021 1022 1023

  Scenario: Text editor fails with --push
    Given the text editor exits with error status
    And I am on the "master" branch pushed to "origin/master"
    And an empty file named ".git/PULLREQ_EDITMSG"
    When I successfully run `git checkout --quiet -b topic`
N
Natalie Weizenbaum 已提交
1024
    Given I make a commit
1025 1026 1027 1028
    When I run `hub pull-request -p`
    Then the stderr should contain "error using text editor for pull request message"
    And the exit status should be 1
    And the file ".git/PULLREQ_EDITMSG" should not exist
1029
    And "git push --set-upstream origin HEAD:topic" should not be run
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066

  Scenario: Automatically retry when --push resulted in 422
    Given The default aruba timeout is 7 seconds
    And the text editor adds:
      """
      hello!
      """
    Given the GitHub API server:
      """
      first_try_at = nil
      tries = 0

      post('/repos/mislav/coral/pulls') {
        tries += 1
        assert :title => 'hello!', :head => 'mislav:topic'

        if !first_try_at || (Time.now - first_try_at) < 5
          first_try_at ||= Time.now
          status 422
          json :message => 'Validation Failed',
               :errors => [{
                 :resource => 'PullRequest',
                 :code => 'invalid',
                 :field => 'head'
               }]
        else
          status 201
          json :html_url => "the://url?tries=#{tries}"
        end
      }
      """
    Given I am on the "topic" branch
    When I successfully run `hub pull-request -p`
    Then the output should contain exactly "the://url?tries=3\n"
    And the file ".git/PULLREQ_EDITMSG" should not exist

  Scenario: Eventually give up on retries for --push
M
Mislav Marohnić 已提交
1067
    Given The default aruba timeout is 7 seconds
1068 1069 1070 1071
    And the text editor adds:
      """
      hello!
      """
M
Mislav Marohnić 已提交
1072
    And $HUB_RETRY_TIMEOUT is "5"
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
    Given the GitHub API server:
      """
      post('/repos/mislav/coral/pulls') {
        status 422
        json :message => 'Validation Failed',
             :errors => [{
               :resource => 'PullRequest',
               :code => 'invalid',
               :field => 'head'
             }]
      }
      """
    Given I am on the "topic" branch
    When I run `hub pull-request -p`
    Then the stderr should contain:
      """
      Error creating pull request: Unprocessable Entity (HTTP 422)
      Invalid value for "head"\n
      """
M
Mislav Marohnić 已提交
1092
    And the output should match /Given up after retrying for 5\.\d seconds\./
1093
    And a file named ".git/PULLREQ_EDITMSG" should exist