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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions repo.go
Original file line number Diff line number Diff line change
@@ -110,17 +110,29 @@ func parseRepo(defaultSchema, defaultHost, defaultOrganization, name string) (re
return r, nil
}

// language returns the language of a repository using github's detected language.
// This is a best effort try and will return the empty string if something fails.
// language tries to determine the language of a repository. If any error is
// encountered, an empty string is returned.
func (r repo) language() string {
switch strings.ToLower(r.Host) {
case "github.com":
return r.getGitHubLanguage()
default:
return ""
}
}

// getGitHubLanguage returns the language of a repository using GitHub's
// detected language. This is a best effort try and will return the empty string
// if something fails.
func (r repo) getGitHubLanguage() string {
orgRepo := strings.SplitN(r.trimPath(), "/", 2)
if len(orgRepo) != 2 {
return ""
}

repo, resp, err := github.NewClient(nil).Repositories.Get(context.Background(), orgRepo[0], orgRepo[1])
if err != nil {
flog.Error("unable to get repo language: %v", err)
flog.Error("unable to get repo language from GitHub: %v", err)
return ""
}