summaryrefslogtreecommitdiff
path: root/cmd/stanuki/main.go
blob: 332c1adc082dd59f3f7bbfc23c5fbcbba2a947d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"context"
	"fmt"
	"io"
	"net/http"

	"github.com/xlgmokha/x/pkg/env"
	"github.com/xlgmokha/x/pkg/serde"
	"github.com/xlgmokha/x/pkg/x"
)

type Issue struct {
	ID          int    `json:"id"`
	IID         int    `json:"iid"`
	ProjectID   int    `json:"project_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

func main() {
	token := env.Fetch("GITLAB_TOKEN", "")
	url := "https://gitlab.com/api/v4/groups/9970/issues"
	client := http.Client{}
	request := x.Must(http.NewRequestWithContext(context.TODO(), "GET", url, nil))
	request.Header.Add("Authorization", fmt.Sprintf("Bearer %v", token))
	response := x.Must(client.Do(request))
	if env.Fetch("DUMP", "") != "" {
		fmt.Println(string(x.Must(io.ReadAll(response.Body))))
	} else {
		issues := x.Must(serde.From[[]Issue](response.Body, serde.JSON))
		for _, issue := range issues {
			fmt.Printf("%v: %v\n", issue.ID, issue.Title)
		}
	}
}