Um
This commit is contained in:
1 parent
5e4ab8c36a
commit
81b8adb79f
3 files changed
+55
-72
No files matched your search
@@ -6,3 +6,4 @@
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
|
|
||||||
|
bin/
|
||||||
Binary file not shown.
@@ -1,42 +1,5 @@
|
|||||||
package main
|
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 (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -46,25 +9,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
"id": 1437301516,
|
|
||||||
"name": "ThePrimeagen/omarchy",
|
|
||||||
"url
|
|
||||||
*/
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Url string `json:"url"`
|
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 {
|
type Payload struct {
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
RefType string `json:"ref_type"`
|
RefType string `json:"ref_type"`
|
||||||
@@ -72,14 +22,11 @@ type Payload struct {
|
|||||||
MasterBranch string `json:"master_branch"`
|
MasterBranch string `json:"master_branch"`
|
||||||
Desc string `json:"description"`
|
Desc string `json:"description"`
|
||||||
PusherType string `json:"pusher_type"`
|
PusherType string `json:"pusher_type"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
Action string `json:"action"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
type Objects struct {
|
||||||
"public": true,
|
|
||||||
"created_at": "2026-11-06T22:10:52Z"
|
|
||||||
*/
|
|
||||||
|
|
||||||
type Todo struct {
|
|
||||||
UserId string `json:"id"`
|
UserId string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Repo Repo `json:"repo"`
|
Repo Repo `json:"repo"`
|
||||||
@@ -88,6 +35,39 @@ type Todo struct {
|
|||||||
CreatedAt string `json:"created_at"`
|
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() {
|
func main() {
|
||||||
var user string
|
var user string
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
@@ -107,26 +87,28 @@ func main() {
|
|||||||
panic(fmt.Errorf("%s", "err: statuscode failure: "+resp.Status))
|
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)
|
log.Fatalf("Failed to decode json: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, events := range todo {
|
for _, j := range obj {
|
||||||
fmt.Printf("%s, type: %s\n", events.UserId, events.Type)
|
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