From 70974f1d001a24bda9b161dd7a685fcf88dec41b Mon Sep 17 00:00:00 2001 From: Guillem Bonet Date: Thu, 10 Feb 2022 11:55:01 +0100 Subject: [PATCH] make github use mystnodes links too Signed-off-by: Guillem Bonet --- di/di.go | 7 ++++--- feedback/github.go | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/di/di.go b/di/di.go index 290df50..c6de356 100644 --- a/di/di.go +++ b/di/di.go @@ -32,9 +32,10 @@ func (c *Container) ConstructServer(gparams params.Generic, eparams params.Envir } githubReporter := feedback.NewGithubReporter(&feedback.NewGithubReporterOpts{ - Token: *eparams.EnvGithubAccessToken, - Owner: *eparams.EnvGithubOwner, - Repository: *eparams.EnvGithubRepository, + Token: *eparams.EnvGithubAccessToken, + Owner: *eparams.EnvGithubOwner, + Repository: *eparams.EnvGithubRepository, + LogProxyBaseUrl: *gparams.LogProxyBaseUrl, }) rateLimiter := infra.NewRateLimiter(*gparams.RequestsPerSecond) diff --git a/feedback/github.go b/feedback/github.go index 76a109f..df57373 100644 --- a/feedback/github.go +++ b/feedback/github.go @@ -21,7 +21,9 @@ import ( "bytes" "context" "fmt" + "path" "strconv" + "strings" "text/template" "time" @@ -31,17 +33,19 @@ import ( // GithubReporter reports issues to Github type GithubReporter struct { - client *github.Client - owner string - repository string - issueTemplate *template.Template + client *github.Client + owner string + repository string + issueTemplate *template.Template + logProxyBaseUrl string } // NewGithubReporterOpts GithubReporter initialization options type NewGithubReporterOpts struct { - Token string - Owner string - Repository string + Token string + Owner string + Repository string + LogProxyBaseUrl string } // NewGithubReporter creates a new GithubReporter @@ -53,10 +57,11 @@ func NewGithubReporter(opts *NewGithubReporterOpts) *GithubReporter { githubClient := github.NewClient(oauthClient) issueTemplate := template.Must(template.New("issueTemplate").Parse(issueTemplate)) return &GithubReporter{ - client: githubClient, - owner: opts.Owner, - repository: opts.Repository, - issueTemplate: issueTemplate, + client: githubClient, + owner: opts.Owner, + repository: opts.Repository, + issueTemplate: issueTemplate, + logProxyBaseUrl: strings.TrimSuffix(opts.LogProxyBaseUrl, "/"), } } @@ -71,24 +76,27 @@ const issueTemplate = ` ### Logs -{{.LogURL}} +{{.LogProxyBaseUrl}}/{{.LogKey}} ` // ReportIssue reports issue func (rep *GithubReporter) ReportIssue(report *Report) (issueId string, err error) { + key := path.Base(report.LogURL.String()) templateOpts := struct { Description, Email, Identity, Timestamp, - LogURL string + LogKey, + LogProxyBaseUrl string }{ - Description: report.Description, - Email: report.Email, - Identity: report.UserId, - Timestamp: time.Now().String(), - LogURL: report.LogURL.String(), + Description: report.Description, + Email: report.Email, + Identity: report.UserId, + Timestamp: time.Now().String(), + LogKey: key, + LogProxyBaseUrl: rep.logProxyBaseUrl, } var body bytes.Buffer err = rep.issueTemplate.Execute(&body, templateOpts)