Files
github-user-activity/main.go
T

133 lines
2.7 KiB
Go

package main
/*
{
"id": "26550475315",
"type": "CreateEvent",
need struct for actor
"actor": {
"id": 4458174,
"login": "ThePrimeagen",
"display_login": "ThePrimeagen",
"gravatar_id": "",
"url": "https://api.github.com/users/ThePrimeagen",
"avatar_url": "https://avatars.githubusercontent.com/u/4458174?"
},
need struct for repo
"repo": {
"id": 1437301516,
"name": "ThePrimeagen/omarchy",
"url": "https://api.github.com/repos/ThePrimeagen/omarchy"
},
need struct for payload
"payload": {
"ref": "fix/keybindings-to-menu",
"ref_type": "branch",
"full_ref": "refs/heads/fix/keybindings-to-menu",
"master_branch": "quattro",
"description": "Beautiful, Modern & Opinionated Linux",
"pusher_type": "user"
},
"public": true,
"created_at": "2026-11-06T22:10:52Z"
}
*/
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"time"
)
/*
"id": 1437301516,
"name": "ThePrimeagen/omarchy",
"url
*/
type Repo struct {
Id int `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
}
/*
"ref": "fix/keybindings-to-menu",
"ref_type": "branch",
"full_ref": "refs/heads/fix/keybindings-to-menu",
"master_branch": "quattro",
"description": "Beautiful, Modern & Opinionated Linux",
"pusher_type": "user"
*/
type Payload struct {
Ref string `json:"ref"`
RefType string `json:"ref_type"`
FullRef string `json:"full_ref"`
MasterBranch string `json:"master_branch"`
Desc string `json:"description"`
PusherType string `json:"pusher_type"`
}
/*
"public": true,
"created_at": "2026-11-06T22:10:52Z"
*/
type Todo struct {
UserId string `json:"id"`
Type string `json:"type"`
Repo Repo `json:"repo"`
Payload Payload `json:"payload"`
Public bool `json:"public"`
CreatedAt string `json:"created_at"`
}
func main() {
var user string
args := os.Args[1:]
if len(args) > 0 {
user = args[0]
}
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get("https://api.github.com/users/" + user + "/events")
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
panic(fmt.Errorf("%s", "err: statuscode failure: "+resp.Status))
}
var todo []Todo
if err := json.NewDecoder(resp.Body).Decode(&todo); err != nil {
log.Fatalf("Failed to decode json: %v", err)
}
for _, events := range todo {
fmt.Printf("%s, type: %s\n", events.UserId, events.Type)
}
var fileName string = "test.json"
file, err := os.Create(fileName)
if err != nil {
panic(err)
}
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
encoder.Encode(todo)
}