├── .gitignore ├── .ko.yaml ├── assets ├── home.png └── dashboard.png ├── Makefile ├── .github ├── dependabot.yml └── workflows │ ├── lint.yaml │ ├── ci.yaml │ ├── snapshot.yaml │ └── release.yaml ├── go.mod ├── .golangci.yml ├── README.md ├── .goreleaser.yaml ├── kodata └── templates │ ├── input.html │ └── dashboard.html ├── main.go ├── go.sum ├── github.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | github-actions-dashboard 2 | dist/* 3 | -------------------------------------------------------------------------------- /.ko.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | defaultBaseImage: cgr.dev/chainguard/static:latest 3 | -------------------------------------------------------------------------------- /assets/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpanato/github-actions-dashboard/HEAD/assets/home.png -------------------------------------------------------------------------------- /assets/dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpanato/github-actions-dashboard/HEAD/assets/dashboard.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | .PHONY: ko-local 4 | ko-local: 5 | KO_DOCKER_REPO=ko.local LDFLAGS="$(LDFLAGS)" \ 6 | KOCACHE=$(KOCACHE_PATH) ko build --base-import-paths \ 7 | github.com/cpanato/github-actions-dashboard 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 2 3 | updates: 4 | - package-ecosystem: gomod 5 | directory: "/" 6 | schedule: 7 | interval: "daily" 8 | open-pull-requests-limit: 10 9 | - package-ecosystem: "github-actions" 10 | directory: "/" 11 | schedule: 12 | interval: "daily" 13 | open-pull-requests-limit: 10 14 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/cpanato/github-actions-dashboard 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/google/go-github/v53 v53.2.0 7 | github.com/patrickmn/go-cache v2.1.0+incompatible 8 | golang.org/x/oauth2 v0.26.0 9 | ) 10 | 11 | require ( 12 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect 13 | github.com/cloudflare/circl v1.3.7 // indirect 14 | github.com/google/go-querystring v1.1.0 // indirect 15 | golang.org/x/crypto v0.31.0 // indirect 16 | golang.org/x/sys v0.28.0 // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | linters: 3 | enable: 4 | - asciicheck 5 | - unused 6 | - errcheck 7 | - errorlint 8 | - forbidigo 9 | - gofmt 10 | - goimports 11 | - gosec 12 | - gocritic 13 | - importas 14 | - prealloc 15 | - revive 16 | - misspell 17 | - stylecheck 18 | - tparallel 19 | - unconvert 20 | - unparam 21 | - whitespace 22 | 23 | output: 24 | uniq-by-line: false 25 | issues: 26 | max-issues-per-linter: 0 27 | max-same-issues: 0 28 | run: 29 | issues-exit-code: 1 30 | timeout: 10m 31 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | name: lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: 8 | 9 | jobs: 10 | golangci: 11 | name: lint 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 15 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 16 | with: 17 | go-version: '1.20' 18 | check-latest: true 19 | - name: golangci-lint 20 | uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0 21 | with: 22 | version: v1.53 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Actions Dashboard 2 | 3 | This simple project lets you track your CI jobs visually to see what jobs are passing, failing, or running. 4 | 5 | It will show the past 12 hours of GitHub workflows that ran. 6 | 7 | ### Requirements 8 | 9 | - A GitHub token to run authenticated requests (because it can run more API calls can be made), and if you need to access any private repo, you will need the `repo` permission. 10 | 11 | ### Roadmap and upcoming work 12 | 13 | - [ ] Helm chart 14 | - [ ] Example of how to deploy in Google Cloud Run 15 | 16 | ### Screenshots 17 | 18 | ![home](https://github.com/cpanato/github-actions-dashboard/blob/main/assets/home.png?raw=true) 19 | 20 | 21 | ![dashboard](https://github.com/cpanato/github-actions-dashboard/blob/main/assets/dashboard.png?raw=true) 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: 8 | 9 | jobs: 10 | tests: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 15 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 16 | with: 17 | go-version: '1.20' 18 | check-latest: true 19 | - name: Run Go tests 20 | run: go test ./... 21 | 22 | build: 23 | runs-on: ubuntu-latest 24 | 25 | steps: 26 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 27 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 28 | with: 29 | go-version: '1.20' 30 | check-latest: true 31 | - uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9 32 | 33 | - run: go build ./... 34 | 35 | - name: build ko image 36 | run: make ko-local 37 | -------------------------------------------------------------------------------- /.github/workflows/snapshot.yaml: -------------------------------------------------------------------------------- 1 | name: snapshot 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | pull_request: 8 | 9 | jobs: 10 | snapshot: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 14 | 15 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 16 | with: 17 | go-version: '1.20' 18 | check-latest: true 19 | 20 | # This installs the current latest release. 21 | - uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9 22 | 23 | - uses: imjasonh/setup-crane@31b88efe9de28ae0ffa220711af4b60be9435f6e # v0.4 24 | 25 | - uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2 26 | 27 | - name: Set tag output 28 | id: tag 29 | run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT" 30 | 31 | - uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 32 | id: run-goreleaser 33 | with: 34 | version: latest 35 | args: release --snapshot --clean 36 | env: 37 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 38 | -------------------------------------------------------------------------------- /.goreleaser.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | before: 4 | hooks: 5 | - go mod tidy 6 | - /bin/bash -c 'if [ -n "$(git --no-pager diff --exit-code go.mod go.sum)" ]; then exit 1; fi' 7 | 8 | builds: 9 | - id: binary 10 | main: . 11 | env: 12 | - CGO_ENABLED=0 13 | flags: 14 | - -trimpath 15 | goos: 16 | - windows 17 | - linux 18 | - darwin 19 | goarch: 20 | - amd64 21 | - arm64 22 | - s390x 23 | - 386 24 | - mips64le 25 | - ppc64le 26 | - riscv64 27 | 28 | kos: 29 | - id: ko-image 30 | build: binary 31 | main: . 32 | base_image: cgr.dev/chainguard/static:latest 33 | platforms: 34 | - all 35 | tags: 36 | - '{{ .Tag }}' 37 | - '{{ .FullCommit }}' 38 | - latest 39 | sbom: spdx 40 | bare: true 41 | preserve_import_paths: false 42 | base_import_paths: false 43 | 44 | archives: 45 | - id: with-version 46 | name_template: >- 47 | {{ .ProjectName }}_ 48 | {{- .Version }}_ 49 | {{- title .Os }}_ 50 | {{- if eq .Arch "amd64" }}x86_64 51 | {{- else if eq .Arch "386" }}i386 52 | {{- else }}{{ .Arch }}{{ end }} 53 | 54 | checksum: 55 | name_template: 'checksums.txt' 56 | 57 | snapshot: 58 | name_template: "{{ .Tag }}-next" 59 | 60 | changelog: 61 | sort: asc 62 | use: github 63 | filters: 64 | exclude: 65 | - '^docs:' 66 | - '^test:' 67 | -------------------------------------------------------------------------------- /kodata/templates/input.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Github Actions Dashboard 8 | 10 | 11 | 12 | 13 | 15 |
16 |

Github Actions Dashboard

17 |

Type your Github Organization and the Repository that you want to check the Actions Dashboard

18 |
19 |
20 |
21 | GitHub Owner/Organization 22 | 23 |
24 |
25 | GitHub Repository 26 | 27 |
28 |
29 | 30 |
31 |
32 |
33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /kodata/templates/dashboard.html: -------------------------------------------------------------------------------- 1 | {{define "dashboard"}} 2 | 3 | 4 | 5 | 6 | 7 | Github Actions Dashboard 8 | 10 | 11 | 12 |
13 |
14 |
15 |

Github Actions Dashboard

16 |

For {{ .Owner }}/{{ .Repo }}

17 |
18 |
19 |
20 | 22 | {{ range $key, $value := .Data }} 23 | 24 | 25 | 26 | 27 | {{range $value }} 28 | 29 | {{end}} 30 | 31 | 32 | 33 | 34 | 35 | {{range $value }} 36 | 37 | {{end}} 38 | 39 | 40 |
job Name/sha{{ .SHA }}
{{ $key }}{{ .Status }}/{{ .Conclusion }}
{{if .PRUrl }}Event Type:{{ .Event }}{{else}}Event Type:{{ .Event }}{{end}}
41 |

42 | {{end}} 43 | Generated at {{ .DateGenerated }}. Next update at {{ .NextGeneration }} 44 |
45 | 46 | 47 | {{end}} 48 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | release: 10 | 11 | permissions: 12 | packages: write 13 | id-token: write 14 | contents: write 15 | 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 19 | 20 | - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 21 | with: 22 | go-version: '1.20' 23 | check-latest: true 24 | 25 | # This installs the current latest release. 26 | - uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9 27 | 28 | - uses: imjasonh/setup-crane@31b88efe9de28ae0ffa220711af4b60be9435f6e # v0.4 29 | 30 | - uses: sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2 31 | 32 | - name: Set tag output 33 | id: tag 34 | run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT" 35 | 36 | - uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 37 | id: run-goreleaser 38 | with: 39 | version: latest 40 | args: release --clean 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | 44 | - name: sign ko-image 45 | run: | 46 | digest=$(crane digest "${REGISTRY}":"${GIT_TAG}") 47 | cosign sign --yes \ 48 | -a GIT_HASH="${GIT_HASH}" \ 49 | -a GIT_TAG="${GIT_TAG}" \ 50 | -a RUN_ID="${RUN_ID}" \ 51 | -a RUN_ATTEMPT="${RUN_ATTEMPT}" \ 52 | "${REGISTRY}@${digest}" 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | GIT_HASH: ${{ github.sha }} 56 | GIT_TAG: ${{ steps.tag.outputs.tag_name }} 57 | RUN_ATTEMPT: ${{ github.run_attempt }} 58 | RUN_ID: ${{ github.run_id }} 59 | REGISTRY: "ghcr.io/${{ github.repository }}" 60 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "html/template" 7 | "log" 8 | "net/http" 9 | "os" 10 | "path/filepath" 11 | "time" 12 | 13 | "github.com/patrickmn/go-cache" 14 | ) 15 | 16 | var c *cache.Cache 17 | 18 | type Dashboard struct { 19 | Owner string 20 | Repo string 21 | DateGenerated string 22 | NextGeneration string 23 | Data map[string][]Status 24 | } 25 | 26 | func main() { 27 | c = cache.New(15*time.Minute, 30*time.Minute) 28 | 29 | http.HandleFunc("/", handleRequest) 30 | 31 | log.Print("Listening on :3000...") 32 | err := http.ListenAndServe(":3000", nil) //nolint: gosec 33 | if err != nil { 34 | log.Fatal(err) 35 | } 36 | } 37 | 38 | type Status struct { 39 | SHA string 40 | Status string 41 | Event string 42 | Conclusion string 43 | TableStatus string 44 | JobHTML string 45 | WorkflowID int64 46 | CreatedAt time.Time 47 | PRUrl string 48 | } 49 | 50 | func handleRequest(w http.ResponseWriter, r *http.Request) { 51 | if r.URL.Path != "/" { 52 | http.Error(w, "404 not found.", http.StatusNotFound) 53 | return 54 | } 55 | 56 | switch r.Method { 57 | case "GET": 58 | input := fmt.Sprintf("%s/templates/input.html", http.Dir(os.Getenv("KO_DATA_PATH"))) 59 | http.ServeFile(w, r, input) 60 | case "POST": 61 | if err := r.ParseForm(); err != nil { 62 | fmt.Fprintf(w, "ParseForm() err: %v", err) 63 | return 64 | } 65 | 66 | owner := r.FormValue("owner") 67 | repo := r.FormValue("repo") 68 | serveTemplate(w, r, owner, repo) 69 | default: 70 | fmt.Fprintf(w, "Sorry, only GET and POST methods are supported.") 71 | } 72 | } 73 | 74 | func serveTemplate(w http.ResponseWriter, _ *http.Request, owner, repo string) { 75 | dataReport := getJobs(c, owner, repo) 76 | lp := filepath.Join(os.Getenv("KO_DATA_PATH"), "templates/dashboard.html") 77 | 78 | tmpl, _ := template.ParseFiles(lp) 79 | w.Header().Set("Content-Type", "text/html") 80 | 81 | err := tmpl.ExecuteTemplate(w, "dashboard", dataReport) 82 | if err != nil { 83 | // Log the detailed error 84 | log.Print(err.Error()) 85 | http.Error(w, http.StatusText(500), 500) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= 2 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= 3 | github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= 4 | github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= 5 | github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= 6 | github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= 7 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 8 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 9 | github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI= 10 | github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= 11 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= 12 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= 13 | github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= 14 | github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= 15 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 16 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 17 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 18 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 19 | golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE= 20 | golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= 21 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 22 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 23 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 24 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 25 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 26 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 27 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 28 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 29 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 30 | -------------------------------------------------------------------------------- /github.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "time" 9 | 10 | "github.com/google/go-github/v53/github" 11 | "github.com/patrickmn/go-cache" 12 | "golang.org/x/oauth2" 13 | ) 14 | 15 | func getJobs(c *cache.Cache, owner, repo string) Dashboard { 16 | data, found := c.Get(fmt.Sprintf("%s-%s", owner, repo)) 17 | if found { 18 | log.Println("cache found") 19 | return data.(Dashboard) 20 | } 21 | 22 | log.Println("cache not found") 23 | 24 | ctx := context.Background() 25 | ts := oauth2.StaticTokenSource( 26 | &oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")}, 27 | ) 28 | tc := oauth2.NewClient(ctx, ts) 29 | 30 | client := github.NewClient(tc) 31 | 32 | windowStart := time.Now().Add(time.Duration(-12) * time.Hour).UTC().Format(time.RFC3339) 33 | opt := &github.ListWorkflowRunsOptions{ 34 | ListOptions: github.ListOptions{PerPage: 100}, 35 | Created: ">=" + windowStart, 36 | } 37 | 38 | var runs []*github.WorkflowRun 39 | for { 40 | resp, rr, err := client.Actions.ListRepositoryWorkflowRuns(context.Background(), owner, repo, opt) 41 | if rlErr, ok := err.(*github.RateLimitError); ok { //nolint: errorlint 42 | log.Printf("ListRepositoryWorkflowRuns ratelimited. Pausing until %s", rlErr.Rate.Reset.Time.String()) 43 | time.Sleep(time.Until(rlErr.Rate.Reset.Time)) 44 | continue 45 | } else if err != nil { 46 | log.Printf("ListRepositoryWorkflowRuns error for repo %s/%s: %s", owner, repo, err.Error()) 47 | os.Exit(1) 48 | } 49 | 50 | runs = append(runs, resp.WorkflowRuns...) 51 | if rr.NextPage == 0 { 52 | break 53 | } 54 | opt.Page = rr.NextPage 55 | } 56 | 57 | var report = make(map[string][]Status) 58 | for _, run := range runs { 59 | conclusion := run.GetConclusion() 60 | if run.GetStatus() == "in_progress" { 61 | conclusion = "progress" 62 | } else if run.GetStatus() == "queued" { 63 | conclusion = "queued" 64 | } 65 | 66 | tableStatus := getTableStatus(conclusion) 67 | 68 | prInfo := "" 69 | if run.GetEvent() == "pull_request" || run.GetEvent() == "pull_request_target" { 70 | owner = run.GetRepository().GetOwner().GetLogin() 71 | repo = run.GetRepository().GetName() 72 | 73 | opts := &github.PullRequestListOptions{ 74 | State: "all", 75 | } 76 | pull, _, err := client.PullRequests.ListPullRequestsWithCommit(context.Background(), owner, repo, run.GetHeadSHA(), opts) 77 | if rlErr, ok := err.(*github.RateLimitError); ok { //nolint: errorlint 78 | log.Printf("ListRepositoryWorkflowRuns ratelimited. Pausing until %s", rlErr.Rate.Reset.Time.String()) 79 | time.Sleep(time.Until(rlErr.Rate.Reset.Time)) 80 | continue 81 | } else if err != nil { 82 | log.Printf("ListPullRequestsWithCommit error for repo %s/%s: %s", owner, repo, err.Error()) 83 | os.Exit(1) 84 | } 85 | 86 | prInfo = "" 87 | if len(pull) == 1 { 88 | prInfo = pull[0].GetHTMLURL() 89 | } 90 | } 91 | 92 | _, ok := report[run.GetName()] 93 | if ok { 94 | report[run.GetName()] = append(report[run.GetName()], Status{ 95 | SHA: run.GetHeadSHA(), 96 | Conclusion: conclusion, 97 | TableStatus: tableStatus, 98 | Status: run.GetStatus(), 99 | JobHTML: run.GetHTMLURL(), 100 | WorkflowID: run.GetWorkflowID(), 101 | CreatedAt: run.GetCreatedAt().Time, 102 | Event: run.GetEvent(), 103 | PRUrl: prInfo, 104 | }) 105 | } else { 106 | report[run.GetName()] = []Status{ 107 | { 108 | SHA: run.GetHeadSHA(), 109 | Conclusion: conclusion, 110 | TableStatus: tableStatus, 111 | Status: run.GetStatus(), 112 | JobHTML: run.GetHTMLURL(), 113 | WorkflowID: run.GetWorkflowID(), 114 | CreatedAt: run.GetCreatedAt().Time, 115 | Event: run.GetEvent(), 116 | PRUrl: prInfo, 117 | }, 118 | } 119 | } 120 | } 121 | 122 | dash := Dashboard{ 123 | Owner: owner, 124 | Repo: repo, 125 | DateGenerated: time.Now().Local().Format(time.RFC3339), 126 | NextGeneration: time.Now().Add(15 * time.Minute).Local().Format(time.RFC3339), 127 | Data: report, 128 | } 129 | 130 | c.Set(fmt.Sprintf("%s-%s", owner, repo), dash, 15*time.Minute) 131 | return dash 132 | } 133 | 134 | func getTableStatus(conclusion string) string { 135 | switch conclusion { 136 | case "success": 137 | return "success" 138 | case "failure": 139 | return "danger" 140 | case "queued": 141 | return "info" 142 | case "cancelled": 143 | return "secondary" 144 | default: 145 | return "warning" 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------