Skip to content

Commit

Permalink
Merge pull request #27 from nekottyo/dashboad-list
Browse files Browse the repository at this point in the history
  • Loading branch information
nekottyo authored Jun 1, 2020
2 parents 9efd6cf + c08bc15 commit f104a46
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 56 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
go get -v -t -d ./...
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
issue_comment:
types: [created]
name: Automatic Rebase
jobs:
rebase:
name: Rebase
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Automatic Rebase
uses: cirrus-actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: make action-release
run: make action-release

- name: Build Alfred Workflow
id: alfred_builder
uses: mperezi/build-alfred-workflow@v1
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func run() {
}
}
if doDashboard {
d := dd.NewDashboard(client, wf)
if err := d.ListDashboards(); err != nil {
d := dd.NewBoard(client, wf)
if err := d.ListBoards(); err != nil {
wf.FatalError(err)
}
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/dd/board.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dd

import (
"fmt"

aw "github.com/deanishe/awgo"
"gopkg.in/zorkian/go-datadog-api.v2"
)

// Board is workflow structure of the board.
type Board struct {
client *datadog.Client
cacheName string
wf *aw.Workflow
}

// NewBoard returns a new dd.Board.
func NewBoard(client *datadog.Client, wf *aw.Workflow) Board {
return Board{
cacheName: boardCacheName(),
client: client,
wf: wf,
}
}

// ListBoards is fetch board and appends to workflow items.
func (d *Board) ListBoards() error {
var boards []datadog.BoardLite

call := func() (interface{}, error) {
return d.client.GetBoards()
}

if err := d.wf.Cache.LoadOrStoreJSON(d.cacheName, maxCacheAge, call, &boards); err != nil {
return err
}

for _, board := range boards {
url := fmt.Sprintf("%s/dashboard/%s", baseURL, board.GetId())
d.wf.NewItem(board.GetTitle()).
Subtitle(url).
Arg(url).
UID(board.GetTitle()).
Valid(true)
}
return nil
}

// monitorCacheName returns filename for the dashbaord's cache.
func boardCacheName() string {
return "board.json"
}
52 changes: 0 additions & 52 deletions pkg/dd/dashboard.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/dd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (d *Monitor) ListMonitors() error {
}

for _, monitor := range monitors {
url := fmt.Sprintf("https://app.datadoghq.com/monitors/%d", monitor.GetId())
url := fmt.Sprintf("%s/monitors/%d", baseURL, monitor.GetId())
status := fmt.Sprintf("[%s] %s", monitor.GetOverallState(), monitor.GetName())
d.wf.NewItem(status).
Subtitle(url).
Expand Down
5 changes: 4 additions & 1 deletion pkg/dd/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package dd
import "time"

// How long to cache repo list for
var maxCacheAge = 180 * time.Minute
var (
maxCacheAge = 180 * time.Minute
baseURL = "https://app.datadoghq.com"
)

0 comments on commit f104a46

Please sign in to comment.