mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
187fbed439
might try and see if the gh cli allows for tokened requests later this will maek life a lot easier for the user
45 lines
902 B
Go
45 lines
902 B
Go
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{},
|
|
}
|
|
|
|
}
|
|
|