aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-05-06 19:31:40 -0700
committerFranck Cuny <franck@fcuny.net>2024-05-06 19:31:40 -0700
commitb3a63c28091bf13e66ddad8852ea5ac95baeffb4 (patch)
tree9ae924c575fc6a1a9079bd0ab8b899a4ea957ee1
parentmessing with stuff (diff)
downloadinfra-b3a63c28091bf13e66ddad8852ea5ac95baeffb4.tar.gz
clean up more stuff
-rw-r--r--cmd/ghalogs/main.go139
-rw-r--r--pyproject.toml2
2 files changed, 1 insertions, 140 deletions
diff --git a/cmd/ghalogs/main.go b/cmd/ghalogs/main.go
deleted file mode 100644
index f4935f0..0000000
--- a/cmd/ghalogs/main.go
+++ /dev/null
@@ -1,139 +0,0 @@
-package main
-
-import (
- "context"
- "encoding/json"
- "flag"
- "fmt"
- "net/http"
- "os"
- "strconv"
- "text/tabwriter"
- "time"
-
- "github.com/fcuny/world/internal/git"
- "github.com/fcuny/world/internal/terminal"
- "github.com/fcuny/world/internal/version"
-)
-
-const API_URL = "https://api.github.com"
-
-const usage = `Usage:
- gha-log
-`
-
-type githubActionRun struct {
- Workflows []Workflow `json:"workflow_runs"`
-}
-
-type Workflow struct {
- ID int `json:"id"`
- Name string `json:"name"`
- Title string `json:"display_title"`
- Conclusion string `json:"conclusion"`
- RunStartedAt time.Time `json:"run_started_at"`
-}
-
-type Unmarshaler interface {
- UnmarshalJSON([]byte) error
-}
-
-func (w *Workflow) UnmarshalJSON(data []byte) error {
- type Alias Workflow
- aux := &struct {
- RunStartedAt string `json:"run_started_at"`
- *Alias
- }{
- Alias: (*Alias)(w),
- }
- if err := json.Unmarshal(data, &aux); err != nil {
- return err
- }
- runStartedAt, err := time.Parse(time.RFC3339, aux.RunStartedAt)
- if err != nil {
- return err
- }
- w.RunStartedAt = runStartedAt
- return nil
-}
-
-func main() {
- flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }
-
- var (
- tokenFlag string
- userFlag string
- versionFlag bool
- )
- flag.StringVar(&tokenFlag, "token", "", "GitHub API token")
- flag.StringVar(&tokenFlag, "t", "", "GitHub API token")
- flag.StringVar(&userFlag, "user", "fcuny", "GitHub API token")
- flag.StringVar(&userFlag, "u", "fcuny", "GitHub API token")
- flag.BoolVar(&versionFlag, "version", false, "Print version information")
- flag.BoolVar(&versionFlag, "v", false, "Print version information")
-
- if versionFlag {
- information := version.VersionAndBuildInfo()
- fmt.Println(information)
- return
- }
-
- flag.Parse()
-
- if tokenFlag == "" {
- fmt.Fprintf(os.Stderr, "The API token is not set\n")
- os.Exit(1)
- }
-
- ctx := context.TODO()
-
- repositoryName, err := git.Root()
- if err != nil {
- fmt.Fprintf(os.Stderr, "could not get the repository name: %v\n", err)
- os.Exit(1)
- }
-
- url := fmt.Sprintf("%s/repos/%s/%s/actions/runs", API_URL, userFlag, repositoryName)
- req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
- if err != nil {
- fmt.Fprintf(os.Stderr, "could not create a request: %v\n", err)
- os.Exit(1)
- }
-
- req.Header.Set("Authorization", fmt.Sprintf("token %s", tokenFlag))
- req.Header.Set("Accept", "application/vnd.github.v3+json")
- req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
-
- client := http.Client{
- Timeout: 30 * time.Second,
- }
-
- res, err := client.Do(req)
- if err != nil {
- fmt.Fprintf(os.Stderr, "error making http request: %s\n", err)
- os.Exit(1)
- }
-
- if res.StatusCode != http.StatusOK {
- fmt.Fprintf(os.Stderr, "unexpected status code: %d\n", res.StatusCode)
- os.Exit(1)
- }
-
- var b githubActionRun
- if err := json.NewDecoder(res.Body).Decode(&b); err != nil {
- fmt.Fprintf(os.Stderr, "error parsing the JSON response: %v\n", err)
- os.Exit(1)
- }
-
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)
- for _, run := range b.Workflows {
- status := "✅"
- if run.Conclusion != "success" {
- status = "❌"
- }
-
- linkToAction := terminal.Link(strconv.Itoa(run.ID), fmt.Sprintf("http://github.com/%s/%s/actions/runs/%d/", userFlag, repositoryName, run.ID))
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", linkToAction, run.Name, run.RunStartedAt.Format("2006-01-02 15:04:05"), run.Title, status)
- }
- w.Flush()
-}
diff --git a/pyproject.toml b/pyproject.toml
index 3bf7f69..d74d30c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -66,7 +66,7 @@ known-first-party = ["rbx_nomad", "term", "git"]
[project.scripts]
gha_billing = "cli.gha_billing:cli"
-hashi_env = "cli.hash_env:cli"
+hashienv = "cli.hashienv:cli"
int2ip = "cli.ipconverter:int2ip"
ip2int = "cli.ipconverter:ip2int"
nomad_allocs = "cli.nomad_allocs:cli"