-
Notifications
You must be signed in to change notification settings - Fork 37
Removed github requirement #226
base: master
Are you sure you want to change the base?
Conversation
@deansheather Can you have a look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of using git -C /path/to/repo remote -v
and checking all remotes we should maybe just use the output of git -C /path/to/repo remote get-url origin
to only check the origin remote. Thoughts @coadler?
repo.go
Outdated
@@ -118,6 +137,10 @@ func (r repo) language() string { | |||
return "" | |||
} | |||
|
|||
if ok := r.isGithubRemote(); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be if !r.isGithubRemote() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this block should be moved to the top of language()
before orgRepo = ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, was tired when putting this together 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I would not be able to move this if I included a specific check for the org repo 😛. I think it should stay where it is for now. Once I update the PR, you can have another look.
repo.go
Outdated
@@ -110,6 +111,24 @@ func parseRepo(defaultSchema, defaultHost, defaultOrganization, name string) (re | |||
return r, nil | |||
} | |||
|
|||
func (r repo) isGithubRemote() (ok bool) { | |||
cmd := xexec.Fmt("git remote -v") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be using xexec.Fmt
here since you're not using a format string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work unless the current working directory is inside the repository, which isn't guaranteed. You can tell git to use a different path by giving it the -C
parameter. Maybe xexec.Fmt
is a good idea after all.
repo.go
Outdated
@@ -110,6 +111,24 @@ func parseRepo(defaultSchema, defaultHost, defaultOrganization, name string) (re | |||
return r, nil | |||
} | |||
|
|||
func (r repo) isGithubRemote() (ok bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be called isGitHubRemote
(capital H).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ok bool)
should just be bool
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, instead of logging errors, this function should return them.
repo.go
Outdated
cmd := xexec.Fmt("git remote -v") | ||
out, err := cmd.Output() | ||
if err != nil { | ||
flog.Error("Unable to check repo remotes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flog.Error("unable to check Git remotes: %s", out)
repo.go
Outdated
@@ -110,6 +111,24 @@ func parseRepo(defaultSchema, defaultHost, defaultOrganization, name string) (re | |||
return r, nil | |||
} | |||
|
|||
func (r repo) isGithubRemote() (ok bool) { | |||
cmd := xexec.Fmt("git remote -v") | |||
out, err := cmd.Output() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cmd.CombinedOutput
so we can use this in the error as well.
repo.go
Outdated
return false | ||
} | ||
|
||
o := strings.Split(string(out), "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work, as git remote -v
is prefixed with the name of each remote.
repo.go
Outdated
o := strings.Split(string(out), "\n") | ||
|
||
for _, url := range o { | ||
if strings.HasPrefix(url, "https://github.com") || strings.HasPrefix(url, "[email protected]") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should at least know the username/repo
of the repository, so I think we should check that the URL matches exactly against what we expect it to be. For example, for Sail it should be https://github.com/cdr/sail.git
or [email protected]:cdr/sail.git
.
Do you think that just changing the |
@deansheather, I am unsure how I would get the path of the repo from the current code... Any ideas? |
Actually, I just had another look at repo.go. Why can't we just use |
Getting the origin url is probably the best bet. |
I think that would work for sure. Will change this when I have a moment |
If we're getting the origin URL from |
The diff gist is a bit hard to parse, but |
Also, I may have misled you. Reread through the comments and my
comment was in response to the PR comment you pinged me in and I didn't notice the comment before it pointing out
|
Alright, I'm going to apply the first diff then. |
- This means that only repositories on github.com will have their language autodetected through GitHub API
One issue I just found with
|
Unlucky, didn’t think about that
…On Sun, Jun 30, 2019 at 10:33 PM Dean Sheather ***@***.***> wrote:
One issue I just found with r.Host is that it's not correct if you do
something like:
sail run gitlab.com/deansheather/some-repo => r.Host is gitlab.com
sail run deansheather/some-repo => r.Host is github.com even though it's already cloned from another host
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#226>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQJ7BZFXI6265KFV2QDC2DP5F3KBANCNFSM4H2IRQ2Q>
.
|
I think the best way to fix this is probably to add the `git remote get-url
origin` check to `parseRepo()` if the repo is already on disk. Problem with
that, though, is that parseRepo doesn't know where to look for the
repository, so we'll have to add even more params.
…On Mon, Jul 1, 2019 at 5:44 AM Colin ***@***.***> wrote:
Unlucky, didn’t think about that
On Sun, Jun 30, 2019 at 10:33 PM Dean Sheather ***@***.***>
wrote:
> One issue I just found with r.Host is that it's not correct if you do
> something like:
>
> sail run gitlab.com/deansheather/some-repo => r.Host is gitlab.com
> sail run deansheather/some-repo => r.Host is github.com even though
it's already cloned from another host
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#226
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/ABQJ7BZFXI6265KFV2QDC2DP5F3KBANCNFSM4H2IRQ2Q
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#226>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACVYSVFRNCSGXGXNRR22XN3P5GKUFANCNFSM4H2IRQ2Q>
.
|
Closes #197