Skip to content

Commit e3752e4

Browse files
committed
wip: Initial work on custom aggregator
1 parent caaeb00 commit e3752e4

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

.github/workflows/ci.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: 'ci'
2+
3+
on:
4+
schedule:
5+
- cron: '0 13 * * 0,3'
6+
7+
permissions: read-all
8+
9+
jobs:
10+
test-schedule:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: 'Updates'
14+
run: go run ./get-stars.go

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.token
1+
.env

Bakefile.sh

+4
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
task.run() {
44
starred --username hyperupcall --token "$TOKEN" --sort "$@" > './README.md'
5+
}
6+
7+
task.rungo() {
8+
go run .
59
}

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/hyperupcall/stars
2+
3+
go 1.18
4+
5+
require github.com/joho/godotenv v1.4.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
2+
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

stars.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
"os"
9+
"time"
10+
11+
dotenv "github.com/joho/godotenv"
12+
)
13+
14+
func handle(err error) {
15+
if err != nil {
16+
panic(err)
17+
}
18+
}
19+
20+
func main() {
21+
err := dotenv.Load()
22+
handle(err)
23+
24+
client := http.Client{
25+
Timeout: time.Second * 10,
26+
}
27+
req, err := http.NewRequest("GET", "https://api.github.com/users/hyperupcall/starred", nil)
28+
handle(err)
29+
30+
env, hasToken := os.LookupEnv("GITHUB_TOKEN")
31+
if hasToken {
32+
req.Header.Add("Authorization", "token "+env)
33+
}
34+
35+
res, err := client.Do(req)
36+
handle(err)
37+
defer res.Body.Close()
38+
39+
content, err := ioutil.ReadAll(res.Body)
40+
handle(err)
41+
42+
type Repo struct {
43+
name string
44+
full_name string
45+
description string
46+
fork bool
47+
url string
48+
size int
49+
stargazers_count int
50+
watchers_count int
51+
language string
52+
forks_count string
53+
license struct {
54+
key string
55+
name string
56+
spdx_id string
57+
url string
58+
}
59+
topics []string
60+
}
61+
62+
var repos []Repo
63+
err = json.Unmarshal(content, &repos)
64+
handle(err)
65+
fmt.Printf("%+v", repos)
66+
}

0 commit comments

Comments
 (0)