From 66cdcf2179752ae110927e49dee8eb9b4572e3dc Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 2 Oct 2023 19:43:48 +0300 Subject: [PATCH] fixup deps Signed-off-by: Vasiliy Tolstov --- cmd/pkgdashcli/main.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/cmd/pkgdashcli/main.go b/cmd/pkgdashcli/main.go index ab7e0d6..27ac555 100644 --- a/cmd/pkgdashcli/main.go +++ b/cmd/pkgdashcli/main.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "text/template" "time" @@ -221,6 +222,45 @@ func giteaPullRequest(ctx context.Context, cfg *Config, mods map[string]modules. logger.Fatalf(ctx, "failed to get worktree: %v", err) } + type giteaPull struct { + ID int64 `json:"id"` + URL string `json:"url"` + Title string `json:"title"` + Base struct { + Ref string `json:"ref"` + } `json:"base"` + } + + var pulls []*giteaPull + req, err := http.NewRequestWithContext(ctx, http.MethodGet, envAPIURL+"/repos/"+envREPOSITORY+"/pulls?state=open&token="+envTOKEN, nil) + if err != nil { + return err + } + req.Header.Add("Accept", "application/json") + req.Header.Add("Content-Type", "application/json") + + rsp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + if rsp.StatusCode != http.StatusOK { + buf, _ = io.ReadAll(rsp.Body) + return fmt.Errorf("unknown error: %s", buf) + } + + if err = json.Unmarshal(buf, &pulls); err != nil { + logger.Fatalf(ctx, "failed to decode response: %v", err) + } + + for path := range mods { + for _, pull := range pulls { + if strings.Contains(pull.Title, path) && pull.Base.Ref == envBaseBranch { + logger.Infof(ctx, "skip %s as pr already exists %s", path, pull.URL) + delete(mods, path) + } + } + } + for path, mod := range mods { wTitle.Reset() wBody.Reset()