diff --git a/main.go b/main.go index 06f56a9..8cde844 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* -Copyright 2017 Vector Creations Ltd +Copyright 2017, 2020 Vector Creations Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -48,7 +48,8 @@ type config struct { // A GitHub personal access token, to create a GitHub issue for each report. GithubToken string `yaml:"github_token"` - GithubProjectMappings map[string]string `yaml:"github_project_mappings"` + GithubProjectMappings map[string]string `yaml:"github_project_mappings"` + AutocompleteProjectMappings map[string]string `yaml:"autocomplete_project_mappings"` SlackWebhookURL string `yaml:"slack_webhook_url"` } @@ -112,7 +113,7 @@ func main() { } log.Printf("Using %s/listing as public URI", apiPrefix) - http.Handle("/api/submit", &submitServer{ghClient, apiPrefix, cfg.GithubProjectMappings, slack}) + http.Handle("/api/submit", &submitServer{ghClient, apiPrefix, cfg.GithubProjectMappings, cfg.AutocompleteProjectMappings, slack}) // Make sure bugs directory exists _ = os.Mkdir("bugs", os.ModePerm) diff --git a/rageshake.sample.yaml b/rageshake.sample.yaml index ea68887..4d44517 100644 --- a/rageshake.sample.yaml +++ b/rageshake.sample.yaml @@ -17,6 +17,11 @@ github_token: secrettoken github_project_mappings: my-app: octocat/HelloWorld +# mappings from app name (as submitted in the API) to github repo as to which the issues pertain. +# not needed if the issues are reported to the main repo as github will complete the ambiguous references correctly. +autocomplete_project_mappings: + my-app: octocat/HelloWorld_src + # a Slack personal webhook URL (https://api.slack.com/incoming-webhooks), which # will be used to post a notification on Slack for each report. slack_webhook_url: https://hooks.slack.com/services/TTTTTTT/XXXXXXXXXX/YYYYYYYYYYY diff --git a/submit.go b/submit.go index d6b5d0a..a31aecb 100644 --- a/submit.go +++ b/submit.go @@ -1,5 +1,5 @@ /* -Copyright 2017 Vector Creations Ltd +Copyright 2017, 2020 Vector Creations Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -50,7 +50,8 @@ type submitServer struct { apiPrefix string // mappings from application to github owner/project - githubProjectMappings map[string]string + githubProjectMappings map[string]string + autocompleteProjectMappings map[string]string slack *slackClient } @@ -118,6 +119,9 @@ type submitResponse struct { ReportURL string `json:"report_url,omitempty"` } +// regex to catch and substitute ambiguous issue references with explicit ones to the actual repo they are in +var ambiguousIssueRegex = regexp.MustCompile(`[\s,.](#\d+)`) + func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { // if we attempt to return a response without reading the request body, // apache gets upset and returns a 500. Let's try this. @@ -163,6 +167,10 @@ func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } + if s.autocompleteProjectMappings[p.AppName] != "" { + p.UserText = ambiguousIssueRegex.ReplaceAllString(p.UserText, fmt.Sprintf("%s/$1", s.autocompleteProjectMappings[p.AppName])) + } + resp, err := s.saveReport(req.Context(), *p, reportDir, listingURL) if err != nil { log.Println("Error handling report submission:", err)