Add means to autocomplete issue references to a different repo
This commit is contained in:
parent
690e59d258
commit
36ce7c1910
3 changed files with 19 additions and 5 deletions
5
main.go
5
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.
|
||||
|
@ -49,6 +49,7 @@ type config struct {
|
|||
GithubToken string `yaml:"github_token"`
|
||||
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
10
submit.go
10
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.
|
||||
|
@ -51,6 +51,7 @@ type submitServer struct {
|
|||
|
||||
// mappings from application to github owner/project
|
||||
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)
|
||||
|
|
Reference in a new issue