diff --git a/src/cmd/utils/gh_p_fetcher.go b/src/cmd/utils/gh_p_fetcher.go index 30ae5d2..96f3d96 100644 --- a/src/cmd/utils/gh_p_fetcher.go +++ b/src/cmd/utils/gh_p_fetcher.go @@ -1,7 +1,44 @@ package utils import ( - + "encoding/json" + "fmt" + "net/http" + "strings" ) +type GithubProfile struct { + Login string `json:"login"` + Name string `json:"name"` +} + +func FetchGithubProfile(username string) User { + // Fetch the github profile and create a user with everything except the email + + url := fmt.Sprintf("https://api.github.com/users/%s", username) + + resp, err := http.Get(url) + if err != nil { + panic(fmt.Sprint("Error fetching github profile: ", err)) + } + defer resp.Body.Close() + + // Parse the response and create a user + var profile GithubProfile + err = json.NewDecoder(resp.Body).Decode(&profile) + if err != nil { + panic(fmt.Sprint("Error parsing github profile: ", err)) + } + + // Create a user with the github profile + return User{ + Shortname: strings.ToLower(profile.Name[:2]), + Longname: profile.Name, + Username: profile.Login, + Email: "", + Ex: false, + Groups: []string{}, + } + +}