Um
This commit is contained in:
1 parent
5e4ab8c36a
commit
81b8adb79f
3 files changed
+56
-73
No files matched your search
@@ -6,3 +6,4 @@
|
||||
.env
|
||||
.env.*
|
||||
|
||||
bin/
|
||||
Binary file not shown.
@@ -1,42 +1,5 @@
|
||||
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"
|
||||
@@ -46,25 +9,12 @@ import (
|
||||
"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"`
|
||||
@@ -72,14 +22,11 @@ type Payload struct {
|
||||
MasterBranch string `json:"master_branch"`
|
||||
Desc string `json:"description"`
|
||||
PusherType string `json:"pusher_type"`
|
||||
Size int `json:"size"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
/*
|
||||
"public": true,
|
||||
"created_at": "2026-11-06T22:10:52Z"
|
||||
*/
|
||||
|
||||
type Todo struct {
|
||||
type Objects struct {
|
||||
UserId string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Repo Repo `json:"repo"`
|
||||
@@ -88,6 +35,39 @@ type Todo struct {
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
type Output struct {
|
||||
Name string
|
||||
Key string
|
||||
Count int
|
||||
}
|
||||
|
||||
func indexObjects(table []Objects) []Output {
|
||||
var res []Output
|
||||
data := make(map[string]string)
|
||||
data_count := make(map[string]int)
|
||||
|
||||
for _, j := range table {
|
||||
data[j.Repo.Name] = j.Type
|
||||
data_count[j.Type]++
|
||||
}
|
||||
|
||||
for repoName, repoType := range data {
|
||||
count := data_count[repoType]
|
||||
res = append(res, Output{Name: repoName, Key: repoType, Count: count})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func findKeyOutput(output []Output, targetKey string) *Output {
|
||||
for i := range output {
|
||||
if output[i].Key == targetKey {
|
||||
return &output[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var user string
|
||||
args := os.Args[1:]
|
||||
@@ -107,26 +87,28 @@ func main() {
|
||||
panic(fmt.Errorf("%s", "err: statuscode failure: "+resp.Status))
|
||||
}
|
||||
|
||||
var todo []Todo
|
||||
var obj []Objects
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&todo); err != nil {
|
||||
if err := json.NewDecoder(resp.Body).Decode(&obj); err != nil {
|
||||
log.Fatalf("Failed to decode json: %v", err)
|
||||
}
|
||||
|
||||
for _, events := range todo {
|
||||
fmt.Printf("%s, type: %s\n", events.UserId, events.Type)
|
||||
for _, j := range obj {
|
||||
switch j.Type {
|
||||
case "PushEvent":
|
||||
fmt.Printf("- Pushed %d commit(s) to %s\n", j.Payload.Size, j.Repo.Name)
|
||||
case "IssuesEvent":
|
||||
fmt.Printf("- %s an issue in %s\n", j.Payload.Action, j.Repo.Name)
|
||||
case "WatchEvent":
|
||||
fmt.Printf("- Starred %s\n", j.Repo.Name)
|
||||
case "ForkEvent":
|
||||
fmt.Printf("- Forked %s\n", j.Repo.Name)
|
||||
case "CreateEvent":
|
||||
fmt.Printf("- Created %s %s in %s\n", j.Payload.RefType, j.Payload.Ref, j.Repo.Name)
|
||||
case "PullRequestEvent":
|
||||
fmt.Printf("- %s a pull request in %s\n", j.Payload.Action, j.Repo.Name)
|
||||
default:
|
||||
fmt.Printf("- %s in %s\n", j.Type, j.Repo.Name)
|
||||
}
|
||||
}
|
||||
|
||||
var fileName string = "test.json"
|
||||
|
||||
file, err := os.Create(fileName)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
encoder.Encode(todo)
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user