Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Removed github requirement #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Removed github requirement #226

wants to merge 3 commits into from

Conversation

teddy-codes
Copy link
Contributor

Closes #197

@teddy-codes teddy-codes marked this pull request as ready for review June 21, 2019 03:01
@teddy-codes
Copy link
Contributor Author

@deansheather Can you have a look at this?

Copy link
Member

@deansheather deansheather left a 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 {
Copy link
Member

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() {

Copy link
Member

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 = ....

Copy link
Contributor Author

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 😄

Copy link
Contributor Author

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")
Copy link
Member

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.

Copy link
Member

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) {
Copy link
Member

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).

Copy link
Member

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.

Copy link
Member

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")
Copy link
Member

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()
Copy link
Member

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")
Copy link
Member

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]") {
Copy link
Member

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.

@teddy-codes
Copy link
Contributor Author

Do you think that just changing the HasPrefix method should simply be changed to Contains?

@teddy-codes
Copy link
Contributor Author

@deansheather, I am unsure how I would get the path of the repo from the current code... Any ideas?

@deansheather
Copy link
Member

Actually, I just had another look at repo.go. Why can't we just use r.Host to check if the repository is on GitHub? That would simplify this PR significantly.

@deansheather
Copy link
Member

@coadler
Copy link
Contributor

coadler commented Jun 24, 2019

Getting the origin url is probably the best bet.

@teddy-codes
Copy link
Contributor Author

I think that would work for sure. Will change this when I have a moment

@deansheather
Copy link
Member

If we're getting the origin URL from git, I'd suggest something more like: https://gist.github.com/deansheather/d83477514fa0b54cfa04e1c0f4f355c4

@coadler

@coadler
Copy link
Contributor

coadler commented Jun 28, 2019

The diff gist is a bit hard to parse, but url.Parse would definitely be better here, and your diff seems to handle the : correctly.

@coadler
Copy link
Contributor

coadler commented Jun 28, 2019

Also, I may have misled you. Reread through the comments and my

Getting the origin url is probably the best bet.

comment was in response to the PR comment you pinged me in and I didn't notice the comment before it pointing out r.Host.

r.Host should solve this problem, my apologies. I made sure to handle all edge cases I could find in parseRepo so it should be robust enough to use.

@deansheather
Copy link
Member

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
@deansheather
Copy link
Member

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

@coadler
Copy link
Contributor

coadler commented Jul 1, 2019 via email

@deansheather
Copy link
Member

deansheather commented Jul 1, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove github.com requirement
3 participants