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:
Slug-Boi
2025-04-04 19:46:00 +02:00
parent 97f514ccce
commit 187fbed439
+38 -1
View File
@@ -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{},
}
}