Commit 030865c7 authored by John Jarvis's avatar John Jarvis

Make installing and running the report generator better.

* github.com/GeertJohan/go.rice the relocated executable can find the template file
* allow loading settings in your homedir because it makes more sense there
parent d56cf0cd
Pipeline #14330519 passed with stage
in 2 minutes and 12 seconds
.settings.yaml
.oncall-settings.yaml
oncall-robot-assistant
vendor
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/GeertJohan/go.rice"
packages = [".","embedded"]
revision = "c02ca9a983da5807ddf7d796784928f5be4afd09"
[[projects]]
branch = "master"
name = "github.com/PagerDuty/go-pagerduty"
packages = ["."]
revision = "078a3284fb0ee5256d2164b53b9ed44ff3b3b05e"
[[projects]]
branch = "master"
name = "github.com/daaku/go.zipexe"
packages = ["."]
revision = "a5fe2436ffcb3236e175e5149162b41cd28bd27d"
[[projects]]
branch = "master"
name = "github.com/google/go-querystring"
packages = ["query"]
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
[[projects]]
branch = "master"
name = "github.com/kardianos/osext"
packages = ["."]
revision = "ae77be60afb1dcacde03767a8c37337fad28ac14"
[[projects]]
name = "github.com/xanzy/go-gitlab"
packages = ["."]
......@@ -28,6 +46,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "fd6b96c78b52a2948a330675c47e1673bbbc437fad9e7df8d888fb4dcbcad5d7"
inputs-digest = "46fda45d0012a0900a3fece5d97f57ff127bda45c8894c8c7023d302a37b5e7a"
solver-name = "gps-cdcl"
solver-version = 1
......@@ -28,3 +28,7 @@
[[constraint]]
name = "github.com/xanzy/go-gitlab"
version = "0.6.2"
[[constraint]]
branch = "master"
name = "github.com/GeertJohan/go.rice"
......@@ -10,8 +10,16 @@ tasks. It's main purpose to help generate the weekly reports.
* `dep init`
* `go build`
* `go install`
* Copy `settings-example.yaml` to `.settings.yaml` and update the pagerduty, grafana and gitlab tokens.
* `./on-call-robot-assistant`
* Copy `oncall-settings-example.yaml` to `~/.oncall-settings.yaml` and update the pagerduty, grafana and gitlab tokens.
* `on-call-robot-assistant`
This will create an issue link, modify the issue as you see fit
and move it into infrastructure, and add the "oncall report" label.
## To move the issue
* Click the move link on the right side
* Search for "infrastructure"
* Scroll down until you find gitlab.com / infrastructure
_Note: you may need to update the image links because of https://gitlab.com/gitlab-org/gitlab-ce/issues/40536_
......@@ -31,7 +31,7 @@ func TestParseConfigWrong(t *testing.T) {
}
func TestParseConfigCorrectly(t *testing.T) {
f, err := os.Open("../settings-example.yaml")
f, err := os.Open("../oncall-settings-example.yaml")
defer f.Close()
if err != nil {
......
......@@ -6,11 +6,29 @@ import (
"gitlab.com/gl-infra/oncall-robot-assistant/config"
oncall "gitlab.com/gl-infra/oncall-robot-assistant/oncall"
"log"
"os"
"path"
"time"
)
const settings_fname = ".oncall-settings.yaml"
func main() {
cfgFile := flag.String("config", "./.settings.yaml", "the configuration file")
var filepath string
if _, err := os.Stat(path.Join(".", settings_fname)); err == nil {
filepath = path.Join(".", settings_fname)
}
if _, err := os.Stat(path.Join(os.Getenv("HOME"), settings_fname)); err == nil {
filepath = path.Join(os.Getenv("HOME"), settings_fname)
}
if _, err := os.Stat(filepath); os.IsNotExist(err) {
log.Fatal(fmt.Sprintf("ERROR: Unable to locate %s", settings_fname))
}
cfgFile := flag.String("config", filepath, "the configuration file")
flag.Parse()
config, err := config.ReadConfig(*cfgFile)
......
......@@ -3,13 +3,13 @@ package oncall
import (
"bytes"
"fmt"
"github.com/GeertJohan/go.rice"
gitlab "github.com/xanzy/go-gitlab"
config "gitlab.com/gl-infra/oncall-robot-assistant/config"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"sync"
"text/template"
"time"
......@@ -159,13 +159,21 @@ func GenerateTemplate(config *config.Config, weekly_ops_graphs []WeeklyOpsGraph)
for _, graph := range weekly_ops_graphs {
template_data.WeeklyOpsGraphs = append(template_data.WeeklyOpsGraphs, graph)
}
ex, err := os.Executable()
templateBox, err := rice.FindBox("../templates")
if err != nil {
log.Fatal(err)
}
templateString, err := templateBox.String("on-call-report.tmpl")
if err != nil {
log.Fatal(err)
}
tmpl, err := template.New("message").Parse(templateString)
if err != nil {
log.Fatal(err)
}
dir := path.Dir(ex)
tmpl, err := template.New("on-call-report.tmpl").
ParseFiles(path.Join(dir, "./templates/on-call-report.tmpl"))
var desc bytes.Buffer
tmpl.Execute(&desc, template_data)
return &desc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment