From 22cb7d2e05d197cf1a2d439a1e516c077305ef65 Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 01:06:13 +0900 Subject: [PATCH 1/6] Use cache --- .github/workflows/go.yml | 7 +++++++ .github/workflows/release.yml | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b66c0d71..23deb519 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index abfce958..25cf2ab7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 From 0545bb874206789f3babee48c3aadf1caad6543e Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 02:22:04 +0900 Subject: [PATCH 2/6] Update dashboard --- main.go | 4 ++-- pkg/dd/board.go | 52 +++++++++++++++++++++++++++++++++++++++++++++ pkg/dd/dashboard.go | 52 --------------------------------------------- pkg/dd/variables.go | 5 ++++- 4 files changed, 58 insertions(+), 55 deletions(-) create mode 100644 pkg/dd/board.go delete mode 100644 pkg/dd/dashboard.go diff --git a/main.go b/main.go index 228616f7..c24bbaf3 100644 --- a/main.go +++ b/main.go @@ -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) } } diff --git a/pkg/dd/board.go b/pkg/dd/board.go new file mode 100644 index 00000000..6bcd4ef9 --- /dev/null +++ b/pkg/dd/board.go @@ -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" +} diff --git a/pkg/dd/dashboard.go b/pkg/dd/dashboard.go deleted file mode 100644 index 01a89f2b..00000000 --- a/pkg/dd/dashboard.go +++ /dev/null @@ -1,52 +0,0 @@ -package dd - -import ( - "fmt" - - aw "github.com/deanishe/awgo" - "gopkg.in/zorkian/go-datadog-api.v2" -) - -// Dashboard is workflow structure of the dashboard. -type Dashboard struct { - client *datadog.Client - cacheName string - wf *aw.Workflow -} - -// NewDashboard returns a new dd.Dashboard. -func NewDashboard(client *datadog.Client, wf *aw.Workflow) Dashboard { - return Dashboard{ - cacheName: dashboardCacheName(), - client: client, - wf: wf, - } -} - -// ListDashboards is fetch dashboard and appends to workflow items. -func (d *Dashboard) ListDashboards() error { - var dashboards []datadog.DashboardLite - - call := func() (interface{}, error) { - return d.client.GetDashboards() - } - - if err := d.wf.Cache.LoadOrStoreJSON(d.cacheName, maxCacheAge, call, &dashboards); err != nil { - return err - } - - for _, dash := range dashboards { - url := fmt.Sprintf("https://app.datadoghq.com/dash/%d/datadog", dash.GetId()) - d.wf.NewItem(dash.GetTitle()). - Subtitle(url). - Arg(url). - UID(dash.GetTitle()). - Valid(true) - } - return nil -} - -// monitorCacheName returns filename for the dashbaord's cache. -func dashboardCacheName() string { - return "dashboard.json" -} diff --git a/pkg/dd/variables.go b/pkg/dd/variables.go index 105efdda..718abc47 100644 --- a/pkg/dd/variables.go +++ b/pkg/dd/variables.go @@ -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" +) From f4b15499c5dcc2bb2deab26d4d434e6f1b4911ee Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 02:23:50 +0900 Subject: [PATCH 3/6] Add rebase --- .github/workflows/rebase.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/rebase.yml diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 00000000..7540cabf --- /dev/null +++ b/.github/workflows/rebase.yml @@ -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/rebase@1.3.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 07282b90388c45ccd3d8cc3e3207702ebd28e70f Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 02:28:06 +0900 Subject: [PATCH 4/6] Fix for lint --- pkg/dd/variables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/dd/variables.go b/pkg/dd/variables.go index 718abc47..3d60dd11 100644 --- a/pkg/dd/variables.go +++ b/pkg/dd/variables.go @@ -5,5 +5,5 @@ import "time" // How long to cache repo list for var ( maxCacheAge = 180 * time.Minute - baseUrl = "https://app.datadoghq.com" + baseURL = "https://app.datadoghq.com" ) From 36eeeb6d570abf5d6aaeb0f8af199fad60963946 Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 02:33:10 +0900 Subject: [PATCH 5/6] Fix indent --- .github/workflows/go.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 23deb519..fc0fba47 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,12 +22,12 @@ 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- + - 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: | From c08bc15340ab5f910e60f66505a16e54347a961b Mon Sep 17 00:00:00 2001 From: nekottyo Date: Tue, 2 Jun 2020 02:35:55 +0900 Subject: [PATCH 6/6] Fix typo --- pkg/dd/board.go | 2 +- pkg/dd/monitor.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/dd/board.go b/pkg/dd/board.go index 6bcd4ef9..5676353b 100644 --- a/pkg/dd/board.go +++ b/pkg/dd/board.go @@ -36,7 +36,7 @@ func (d *Board) ListBoards() error { } for _, board := range boards { - url := fmt.Sprintf("%s/dashboard/%s", baseUrl, board.GetId()) + url := fmt.Sprintf("%s/dashboard/%s", baseURL, board.GetId()) d.wf.NewItem(board.GetTitle()). Subtitle(url). Arg(url). diff --git a/pkg/dd/monitor.go b/pkg/dd/monitor.go index 7068dc2d..55bbecbd 100644 --- a/pkg/dd/monitor.go +++ b/pkg/dd/monitor.go @@ -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).