mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 20:55:47 +00:00
feat(gh_fetcher): a small fetcher designed to get info of a github user through gh API
might try and see if the gh cli allows for tokened requests later this will maek life a lot easier for the user
This commit is contained in:
@@ -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{},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user