github.com/scorpionis/hub@v2.2.1+incompatible/features/pull_request.feature (about)

     1  Feature: hub pull-request
     2    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      When I run `hub pull-request`
    10      Then the stderr should contain "Aborted: not currently on any branch.\n"
    11      And the exit status should be 1
    12  
    13    Scenario: Non-GitHub repo
    14      Given the "origin" remote has url "mygh:Manganeez/repo.git"
    15      When I run `hub pull-request`
    16      Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
    17      And the exit status should be 1
    18  
    19    Scenario: Create pull request respecting "insteadOf" configuration
    20      Given the "origin" remote has url "mygh:Manganeez/repo.git"
    21      When I successfully run `git config url."git@github.com:".insteadOf mygh:`
    22      Given the GitHub API server:
    23        """
    24        post('/repos/Manganeez/repo/pulls') {
    25          assert :base  => 'master',
    26                 :head  => 'Manganeez:master',
    27                 :title => 'here we go'
    28          json :html_url => "https://github.com/Manganeez/repo/pull/12"
    29        }
    30        """
    31      When I successfully run `hub pull-request -m "here we go"`
    32      Then the output should contain exactly "https://github.com/Manganeez/repo/pull/12\n"
    33  
    34    Scenario: With Unicode characters
    35      Given the GitHub API server:
    36        """
    37        post('/repos/mislav/coral/pulls') {
    38          halt 400 if request.content_charset != 'utf-8'
    39          assert :title => 'ăéñøü'
    40          json :html_url => "the://url"
    41        }
    42        """
    43      When I successfully run `hub pull-request -m ăéñøü`
    44      Then the output should contain exactly "the://url\n"
    45  
    46    Scenario: Invalid flag
    47      When I run `hub pull-request -yelp`
    48      Then the stderr should contain "unknown shorthand flag: 'y' in -yelp\n"
    49      And the exit status should be 1
    50  
    51    Scenario: With Unicode characters in the changelog
    52      Given the text editor adds:
    53        """
    54        I <3 encodings
    55        """
    56      Given the GitHub API server:
    57        """
    58        post('/repos/mislav/coral/pulls') {
    59          halt 400 if request.content_charset != 'utf-8'
    60          assert :title => 'I <3 encodings',
    61                 :body => 'ăéñøü'
    62          json :html_url => "the://url"
    63        }
    64        """
    65      Given I am on the "master" branch pushed to "origin/master"
    66      When I successfully run `git checkout --quiet -b topic`
    67      Given I make a commit with message "ăéñøü"
    68      And the "topic" branch is pushed to "origin/topic"
    69      When I successfully run `hub pull-request`
    70      Then the output should contain exactly "the://url\n"
    71  
    72    Scenario: Default message for single-commit pull request
    73      Given the text editor adds:
    74        """
    75        """
    76      Given the GitHub API server:
    77        """
    78        post('/repos/mislav/coral/pulls') {
    79          halt 400 if request.content_charset != 'utf-8'
    80          assert :title => 'This is somewhat of a longish title that does not get wrapped & references #1234',
    81                 :body => nil
    82          json :html_url => "the://url"
    83        }
    84        """
    85      Given I am on the "master" branch pushed to "origin/master"
    86      When I successfully run `git checkout --quiet -b topic`
    87      Given I make a commit with message "This is somewhat of a longish title that does not get wrapped & references #1234"
    88      And the "topic" branch is pushed to "origin/topic"
    89      When I successfully run `hub pull-request`
    90      Then the output should contain exactly "the://url\n"
    91  
    92    Scenario: Message template should include git log summary between base and head
    93      Given the text editor adds:
    94        """
    95        Hello
    96        """
    97      Given the GitHub API server:
    98        """
    99        post('/repos/mislav/coral/pulls') {
   100          status 500
   101        }
   102        """
   103      Given I am on the "master" branch
   104      And I make a commit with message "One on master"
   105      And I make a commit with message "Two on master"
   106      And the "master" branch is pushed to "origin/master"
   107      Given I successfully run `git reset --hard HEAD~2`
   108      And I successfully run `git checkout --quiet -B topic origin/master`
   109      Given I make a commit with message "One on topic"
   110      And I make a commit with message "Two on topic"
   111      Given the "topic" branch is pushed to "origin/topic"
   112      And I successfully run `git reset --hard HEAD~1`
   113      When I run `hub pull-request`
   114      Given the SHAs and timestamps are normalized in ".git/PULLREQ_EDITMSG"
   115      Then the file ".git/PULLREQ_EDITMSG" should contain exactly:
   116        """
   117        Hello
   118  
   119  
   120  # Requesting a pull to mislav:master from mislav:topic
   121  #
   122  # Write a message for this pull request. The first block
   123  # of text is the title and the rest is description.
   124  #
   125  # Changes:
   126  #
   127  # SHA1SHA (Hub, 0 seconds ago)
   128  #    Two on topic
   129  #
   130  # SHA1SHA (Hub, 0 seconds ago)
   131  #    One on topic
   132  
   133        """
   134  
   135    Scenario: Non-existing base
   136      Given the GitHub API server:
   137        """
   138        post('/repos/origin/coral/pulls') { 404 }
   139        """
   140      When I run `hub pull-request -b origin:master -m here`
   141      Then the exit status should be 1
   142      Then the stderr should contain:
   143        """
   144        Error creating pull request: Not Found (HTTP 404)
   145        Are you sure that github.com/origin/coral exists?
   146        """
   147  
   148    Scenario: Supplies User-Agent string to API calls
   149      Given the GitHub API server:
   150        """
   151        post('/repos/mislav/coral/pulls') {
   152          halt 400 unless request.user_agent.include?('Hub')
   153          json :html_url => "the://url"
   154        }
   155        """
   156      When I successfully run `hub pull-request -m useragent`
   157      Then the output should contain exactly "the://url\n"
   158  
   159    Scenario: Text editor adds title and body
   160      Given the text editor adds:
   161        """
   162        This title comes from vim!
   163  
   164        This body as well.
   165        """
   166      Given the GitHub API server:
   167        """
   168        post('/repos/mislav/coral/pulls') {
   169          assert :title => 'This title comes from vim!',
   170                 :body  => 'This body as well.'
   171          json :html_url => "https://github.com/mislav/coral/pull/12"
   172        }
   173        """
   174      When I successfully run `hub pull-request`
   175      Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
   176      And the file ".git/PULLREQ_EDITMSG" should not exist
   177  
   178    Scenario: Text editor adds title and body with multiple lines
   179      Given the text editor adds:
   180        """
   181  
   182  
   183        This title is on the third line
   184  
   185  
   186        This body
   187  
   188  
   189        has multiple
   190        lines.
   191  
   192        """
   193      Given the GitHub API server:
   194        """
   195        post('/repos/mislav/coral/pulls') {
   196          assert :title => 'This title is on the third line',
   197                 :body  => "This body\n\n\nhas multiple\nlines."
   198          json :html_url => "https://github.com/mislav/coral/pull/12"
   199        }
   200        """
   201      When I successfully run `hub pull-request`
   202      Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
   203      And the file ".git/PULLREQ_EDITMSG" should not exist
   204  
   205    Scenario: Text editor with custom commentchar
   206      Given git "core.commentchar" is set to "/"
   207      And the text editor adds:
   208        """
   209        # Dat title
   210  
   211        / This line is commented out.
   212  
   213        Dem body.
   214        """
   215      Given the GitHub API server:
   216        """
   217        post('/repos/mislav/coral/pulls') {
   218          assert :title => '# Dat title',
   219                 :body  => 'Dem body.'
   220          json :html_url => "the://url"
   221        }
   222        """
   223      When I successfully run `hub pull-request`
   224      Then the output should contain exactly "the://url\n"
   225  
   226    Scenario: Failed pull request preserves previous message
   227      Given the text editor adds:
   228        """
   229        This title will fail
   230        """
   231      Given the GitHub API server:
   232        """
   233        post('/repos/mislav/coral/pulls') {
   234          halt 422 if params[:title].include?("fail")
   235          assert :body => "This title will fail",
   236                 :title => "But this title will prevail"
   237          json :html_url => "https://github.com/mislav/coral/pull/12"
   238        }
   239        """
   240      When I run `hub pull-request`
   241      Then the exit status should be 1
   242      And the stderr should contain exactly:
   243        """
   244        Error creating pull request: Unprocessable Entity (HTTP 422)\n
   245        """
   246      Given the text editor adds:
   247        """
   248        But this title will prevail
   249        """
   250      When I successfully run `hub pull-request`
   251      Then the file ".git/PULLREQ_EDITMSG" should not exist
   252  
   253    Scenario: Text editor fails
   254      Given the text editor exits with error status
   255      And an empty file named ".git/PULLREQ_EDITMSG"
   256      When I run `hub pull-request`
   257      Then the stderr should contain "error using text editor for pull request message"
   258      And the exit status should be 1
   259      And the file ".git/PULLREQ_EDITMSG" should not exist
   260  
   261    Scenario: Title and body from file
   262      Given the GitHub API server:
   263        """
   264        post('/repos/mislav/coral/pulls') {
   265          assert :title => 'Title from file',
   266                 :body  => "Body from file as well.\n\nMultiline, even!"
   267          json :html_url => "https://github.com/mislav/coral/pull/12"
   268        }
   269        """
   270      And a file named "pullreq-msg" with:
   271        """
   272        Title from file
   273  
   274        Body from file as well.
   275  
   276        Multiline, even!
   277        """
   278      When I successfully run `hub pull-request -F pullreq-msg`
   279      Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
   280      And the file ".git/PULLREQ_EDITMSG" should not exist
   281  
   282    Scenario: Title and body from stdin
   283      Given the GitHub API server:
   284        """
   285        post('/repos/mislav/coral/pulls') {
   286          assert :title => 'Unix piping is great',
   287                 :body  => 'Just look at this ăéñøü'
   288          json :html_url => "https://github.com/mislav/coral/pull/12"
   289        }
   290        """
   291      When I run `hub pull-request -F -` interactively
   292      And I pass in:
   293        """
   294        Unix piping is great
   295  
   296        Just look at this ăéñøü
   297        """
   298      Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
   299      And the exit status should be 0
   300      And the file ".git/PULLREQ_EDITMSG" should not exist
   301  
   302    Scenario: Title and body from command-line argument
   303      Given the GitHub API server:
   304        """
   305        post('/repos/mislav/coral/pulls') {
   306          assert :title => 'I am just a pull',
   307                 :body  => 'A little pull'
   308          json :html_url => "https://github.com/mislav/coral/pull/12"
   309        }
   310        """
   311      When I successfully run `hub pull-request -m "I am just a pull\n\nA little pull"`
   312      Then the output should contain exactly "https://github.com/mislav/coral/pull/12\n"
   313      And the file ".git/PULLREQ_EDITMSG" should not exist
   314  
   315    Scenario: Error when implicit head is the same as base
   316      Given I am on the "master" branch with upstream "origin/master"
   317      When I run `hub pull-request`
   318      Then the stderr should contain exactly:
   319        """
   320        Aborted: head branch is the same as base ("master")
   321        (use `-h <branch>` to specify an explicit pull request head)\n
   322        """
   323  
   324    Scenario: Explicit head
   325      Given I am on the "master" branch
   326      Given the GitHub API server:
   327        """
   328        post('/repos/mislav/coral/pulls') {
   329          assert :head => 'mislav:feature'
   330          json :html_url => "the://url"
   331        }
   332        """
   333      When I successfully run `hub pull-request -h feature -m message`
   334      Then the output should contain exactly "the://url\n"
   335  
   336    Scenario: Explicit head with owner
   337      Given I am on the "master" branch
   338      Given the GitHub API server:
   339        """
   340        post('/repos/mislav/coral/pulls') {
   341          assert :head => 'mojombo:feature'
   342          json :html_url => "the://url"
   343        }
   344        """
   345      When I successfully run `hub pull-request -h mojombo:feature -m message`
   346      Then the output should contain exactly "the://url\n"
   347  
   348    Scenario: Explicit base
   349      Given I am on the "feature" branch
   350      Given the GitHub API server:
   351        """
   352        post('/repos/mislav/coral/pulls') {
   353          assert :base => 'develop'
   354          json :html_url => "the://url"
   355        }
   356        """
   357      When I successfully run `hub pull-request -b develop -m message`
   358      Then the output should contain exactly "the://url\n"
   359  
   360    Scenario: Implicit base by detecting main branch
   361      Given the default branch for "origin" is "develop"
   362      And I am on the "master" branch
   363      Given the GitHub API server:
   364        """
   365        post('/repos/mislav/coral/pulls') {
   366          assert :base => 'develop',
   367                 :head => 'mislav:master'
   368          json :html_url => "the://url"
   369        }
   370        """
   371      When I successfully run `hub pull-request -m message`
   372      Then the output should contain exactly "the://url\n"
   373  
   374    Scenario: Explicit base with owner
   375      Given I am on the "master" branch
   376      Given the GitHub API server:
   377        """
   378        post('/repos/mojombo/coral/pulls') {
   379          assert :base => 'develop'
   380          json :html_url => "the://url"
   381        }
   382        """
   383      When I successfully run `hub pull-request -b mojombo:develop -m message`
   384      Then the output should contain exactly "the://url\n"
   385  
   386    Scenario: Explicit base with owner and repo name
   387      Given I am on the "master" branch
   388      Given the GitHub API server:
   389        """
   390        post('/repos/mojombo/coralify/pulls') {
   391          assert :base => 'develop'
   392          json :html_url => "the://url"
   393        }
   394        """
   395      When I successfully run `hub pull-request -b mojombo/coralify:develop -m message`
   396      Then the output should contain exactly "the://url\n"
   397  
   398    Scenario: Error when there are unpushed commits
   399      Given I am on the "feature" branch with upstream "origin/feature"
   400      When I make 2 commits
   401      And I run `hub pull-request`
   402      Then the stderr should contain exactly:
   403        """
   404        Aborted: 2 commits are not yet pushed to origin/feature
   405        (use `-f` to force submit a pull request anyway)\n
   406        """
   407  
   408    Scenario: Ignore unpushed commits with `-f`
   409      Given I am on the "feature" branch with upstream "origin/feature"
   410      Given the GitHub API server:
   411        """
   412        post('/repos/mislav/coral/pulls') {
   413          assert :head => 'mislav:feature'
   414          json :html_url => "the://url"
   415        }
   416        """
   417      When I make 2 commits
   418      And I successfully run `hub pull-request -f -m message`
   419      Then the output should contain exactly "the://url\n"
   420  
   421    Scenario: Pull request fails on the server
   422      Given I am on the "feature" branch with upstream "origin/feature"
   423      Given the GitHub API server:
   424        """
   425        post('/repos/mislav/coral/pulls') {
   426          status 422
   427          json(:message => "I haz fail!")
   428        }
   429        """
   430      When I run `hub pull-request -m message`
   431      Then the stderr should contain exactly:
   432        """
   433        Error creating pull request: Unprocessable Entity (HTTP 422)
   434        I haz fail!\n
   435        """
   436  
   437    Scenario: Convert issue to pull request
   438      Given I am on the "feature" branch with upstream "origin/feature"
   439      Given the GitHub API server:
   440        """
   441        post('/repos/mislav/coral/pulls') {
   442          assert :issue => '92'
   443          json :html_url => "https://github.com/mislav/coral/pull/92"
   444        }
   445        """
   446      When I successfully run `hub pull-request -i 92`
   447      Then the output should contain exactly:
   448        """
   449        https://github.com/mislav/coral/pull/92
   450        Warning: Issue to pull request conversion is deprecated and might not work in the future.\n
   451        """
   452  
   453    Scenario: Convert issue URL to pull request
   454      Given I am on the "feature" branch with upstream "origin/feature"
   455      Given the GitHub API server:
   456        """
   457        post('/repos/mislav/coral/pulls') {
   458          assert :issue => '92'
   459          json :html_url => "https://github.com/mislav/coral/pull/92"
   460        }
   461        """
   462      When I successfully run `hub pull-request https://github.com/mislav/coral/issues/92`
   463      Then the output should contain exactly:
   464        """
   465        https://github.com/mislav/coral/pull/92
   466        Warning: Issue to pull request conversion is deprecated and might not work in the future.\n
   467        """
   468  
   469    Scenario: Enterprise host
   470      Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
   471      And I am "mislav" on git.my.org with OAuth token "FITOKEN"
   472      And "git.my.org" is a whitelisted Enterprise host
   473      Given the GitHub API server:
   474        """
   475        post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
   476          assert :base => 'master',
   477                 :head => 'mislav:master'
   478          json :html_url => "the://url"
   479        }
   480        """
   481      When I successfully run `hub pull-request -m enterprisey`
   482      Then the output should contain exactly "the://url\n"
   483  
   484    Scenario: Enterprise remote witch matching branch but no tracking
   485      Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
   486      And I am "mislav" on git.my.org with OAuth token "FITOKEN"
   487      And "git.my.org" is a whitelisted Enterprise host
   488      And I am on the "feature" branch pushed to "origin/feature"
   489      Given the GitHub API server:
   490        """
   491        post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
   492          assert :base => 'master',
   493                 :head => 'mislav:feature'
   494          json :html_url => "the://url"
   495        }
   496        """
   497      When I successfully run `hub pull-request -m enterprisey`
   498      Then the output should contain exactly "the://url\n"
   499  
   500    Scenario: Create pull request from branch on the same remote
   501      Given the "origin" remote has url "git://github.com/github/coral.git"
   502      And the "mislav" remote has url "git://github.com/mislav/coral.git"
   503      And I am on the "feature" branch pushed to "origin/feature"
   504      Given the GitHub API server:
   505        """
   506        post('/repos/github/coral/pulls') {
   507          assert :base  => 'master',
   508                 :head  => 'github:feature',
   509                 :title => 'hereyougo'
   510          json :html_url => "the://url"
   511        }
   512        """
   513      When I successfully run `hub pull-request -m hereyougo`
   514      Then the output should contain exactly "the://url\n"
   515  
   516    Scenario: Create pull request from branch on the personal fork case sensitive
   517      Given the "origin" remote has url "git://github.com/github/coral.git"
   518      And the "doge" remote has url "git://github.com/Mislav/coral.git"
   519      And I am on the "feature" branch pushed to "doge/feature"
   520      Given the GitHub API server:
   521        """
   522        post('/repos/github/coral/pulls') {
   523          assert :base  => 'master',
   524                 :head  => 'Mislav:feature',
   525                 :title => 'hereyougo'
   526          json :html_url => "the://url"
   527        }
   528        """
   529      When I successfully run `hub pull-request -m hereyougo`
   530      Then the output should contain exactly "the://url\n"
   531  
   532    Scenario: Create pull request from branch on the personal fork
   533      Given the "origin" remote has url "git://github.com/github/coral.git"
   534      And the "doge" remote has url "git://github.com/mislav/coral.git"
   535      And I am on the "feature" branch pushed to "doge/feature"
   536      Given the GitHub API server:
   537        """
   538        post('/repos/github/coral/pulls') {
   539          assert :base  => 'master',
   540                 :head  => 'mislav:feature',
   541                 :title => 'hereyougo'
   542          json :html_url => "the://url"
   543        }
   544        """
   545      When I successfully run `hub pull-request -m hereyougo`
   546      Then the output should contain exactly "the://url\n"
   547  
   548    Scenario: Create pull request to "upstream" remote
   549      Given the "upstream" remote has url "git://github.com/github/coral.git"
   550      And I am on the "master" branch pushed to "origin/master"
   551      Given the GitHub API server:
   552        """
   553        post('/repos/github/coral/pulls') {
   554          assert :base  => 'master',
   555                 :head  => 'mislav:master',
   556                 :title => 'hereyougo'
   557          json :html_url => "the://url"
   558        }
   559        """
   560      When I successfully run `hub pull-request -m hereyougo`
   561      Then the output should contain exactly "the://url\n"
   562  
   563    Scenario: Open pull request in web browser
   564      Given the GitHub API server:
   565        """
   566        post('/repos/mislav/coral/pulls') {
   567          json :html_url => "the://url"
   568        }
   569        """
   570      When I successfully run `hub pull-request -o -m hereyougo`
   571      Then "open the://url" should be run
   572  
   573    Scenario: Current branch is tracking local branch
   574      Given git "push.default" is set to "upstream"
   575      And I am on the "feature" branch with upstream "refs/heads/master"
   576      Given the GitHub API server:
   577        """
   578        post('/repos/mislav/coral/pulls') {
   579          assert :base  => 'master',
   580                 :head  => 'mislav:feature'
   581          json :html_url => "the://url"
   582        }
   583        """
   584      When I successfully run `hub pull-request -m hereyougo`
   585      Then the output should contain exactly "the://url\n"
   586  
   587    Scenario: Branch with quotation mark in name
   588      Given I am on the "feat'ure" branch with upstream "origin/feat'ure"
   589      Given the GitHub API server:
   590        """
   591        post('/repos/mislav/coral/pulls') {
   592          assert :head  => "mislav:feat'ure"
   593          json :html_url => "the://url"
   594        }
   595        """
   596      When I successfully run `hub pull-request -m hereyougo`
   597      Then the output should contain exactly "the://url\n"