Treat remote URL user name case insensitive when creating PR

See https://github.com/github/hub/issues/685
This commit is contained in:
Jingwen Owen Ou 2014-11-16 12:58:56 -08:00
Родитель aabc10b2c7
Коммит 3aeba67bad
3 изменённых файлов: 35 добавлений и 1 удалений

Просмотреть файл

@ -513,6 +513,22 @@ Feature: hub pull-request
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
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'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
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"

Просмотреть файл

@ -2,6 +2,7 @@ package github
import (
"fmt"
"strings"
"github.com/github/hub/git"
)
@ -55,7 +56,7 @@ func (r *GitHubRepo) remotesForPublish(owner string) (remotes []Remote) {
if owner != "" {
for _, remote := range r.remotes {
p, e := remote.Project()
if e == nil && p.Owner == owner {
if e == nil && strings.ToLower(p.Owner) == owner {
remotesMap[remote.Name] = remote
}
}

Просмотреть файл

@ -1,6 +1,7 @@
package github
import (
"net/url"
"testing"
"github.com/bmizerany/assert"
@ -16,3 +17,19 @@ func TestGitHubRepo_OriginRemote(t *testing.T) {
assert.Equal(t, "origin", gitRemote.Name)
assert.Equal(t, repo.Remote, gitRemote.URL.String())
}
func TestGitHubRepo_remotesForPublish(t *testing.T) {
url, _ := url.Parse("ssh://git@github.com/Owner/repo.git")
remotes := []Remote{
{
Name: "Owner",
URL: url,
},
}
repo := GitHubRepo{remotes}
remotesForPublish := repo.remotesForPublish("owner")
assert.Equal(t, 1, len(remotesForPublish))
assert.Equal(t, "Owner", remotesForPublish[0].Name)
assert.Equal(t, url.String(), remotesForPublish[0].URL.String())
}