From 61c174dd2bdabcb4ee953e2e50ea141567515140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Wed, 27 Dec 2023 13:20:51 +0100 Subject: [PATCH] move update into data.go --- data.go | 43 ++++++++++++++++++++++++++++++++++++++++--- main.go | 24 ++++++------------------ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/data.go b/data.go index 5512f0f..4f92795 100644 --- a/data.go +++ b/data.go @@ -39,12 +39,12 @@ type Data struct { token string num int projectId int - filterId int minimumVersion string tmpl *template.Template ctx context.Context Issues Issues + Projects Projects Timestamp time.Time Freq time.Duration Lasterror error @@ -70,9 +70,29 @@ func NewData(ctx context.Context, url, token string, num int) *Data { return data } +const statusFilter = `status%5B%5D=10&status%5B%5D=20&status%5B%5D=30&status%5B%5D=40&status%5B%5D=50&severity%5B%5D=20` + +var fields = []string{"id", + "description", + "summary", + "category", + "target_version", + "status", + "reporter", + "handler", + "resolution", + "priority", + "severity", + "created_at", + "updated_at", + "relationships", + "tags", +} + func (d *Data) update() { - url := fmt.Sprintf("%s?project_id=%dfilter_id=%d&page_size=%d", - d.url, d.projectId, d.filterId, d.num) + url := fmt.Sprintf("%s/issues?project_id=%d&page_size=%d&%s&select=%s", + d.url, d.projectId, d.num, statusFilter, + strings.Join(fields, ",")) req, e := http.NewRequestWithContext(d.ctx, "GET", url, nil) if nil != e { d.mux.Lock() @@ -115,6 +135,23 @@ func (d *Data) update() { } } d.Issues = issues + fmt.Println("got", len(issues), "issues") +} + +func (d *Data) Loop() { + d.update() + go func() { + var ticker = time.NewTicker(d.Freq) + for range ticker.C { + select { + case <-d.ctx.Done(): + return + default: + fmt.Println("updating data") + d.update() + } + } + }() } func (d *Data) printJSON(w io.Writer) { diff --git a/main.go b/main.go index f40184b..05f120d 100644 --- a/main.go +++ b/main.go @@ -31,12 +31,13 @@ import ( ) var ( - fl_url = flag.String("url", "https://bugs.gnunet.org/api/rest/issues", "URL to the issues") + fl_url = flag.String("url", "https://bugs.gnunet.org/api/rest", "URL to the issues") fl_token = flag.String("token", os.Getenv("MANTIS_API_TOKEN"), "API-Token") fl_port = flag.String("port", ":8080", "[ip]:port to serve") - fl_num = flag.Int("num", 100, "number of issues to retrieve at once") + fl_num = flag.Int("num", 250, "number of issues to retrieve at once") fl_min = flag.String("min", "0.9.3", "minimum version we care for") - fl_freq = flag.Duration("fr", time.Minute, "update frequency") + fl_freq = flag.Duration("fr", time.Minute, "update frequency") + fl_proj = flag.Int("project", 23, "project id to use") ) func main() { @@ -45,24 +46,11 @@ func main() { var ctx = context.Background() var data = NewData(ctx, *fl_url, *fl_token, *fl_num) - data.filterId = 230 - data.projectId = 23 + data.projectId = *fl_proj data.minimumVersion = *fl_min data.Freq = *fl_freq - data.update() - go func() { - var ticker = time.NewTicker(*fl_freq) - for range ticker.C { - select { - case <-ctx.Done(): - return - default: - fmt.Println("updating data") - data.update() - } - } - }() + data.Loop() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Println("got request for table")