Compare commits
5 commits
master
...
t3chguy/au
Author | SHA1 | Date | |
---|---|---|---|
|
7390a7e43f | ||
|
6ffa32a236 | ||
|
9caf46cc61 | ||
|
9f6217d159 | ||
|
36ce7c1910 |
4 changed files with 48 additions and 2 deletions
7
main.go
7
main.go
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -48,7 +49,11 @@ type config struct {
|
||||||
// A GitHub personal access token, to create a GitHub issue for each report.
|
// A GitHub personal access token, to create a GitHub issue for each report.
|
||||||
GithubToken string `yaml:"github_token"`
|
GithubToken string `yaml:"github_token"`
|
||||||
|
|
||||||
|
// Mappings from app name (as submitted in the API) to github repo for issue reporting.
|
||||||
GithubProjectMappings map[string]string `yaml:"github_project_mappings"`
|
GithubProjectMappings map[string]string `yaml:"github_project_mappings"`
|
||||||
|
// Mappings from app name (as submitted in the API) to github repo to which the issues pertain.
|
||||||
|
// Not needed if the issues are reported to the main repo as github will complete the ambiguous references correctly.
|
||||||
|
AutocompleteProjectMappings map[string]string `yaml:"autocomplete_project_mappings"`
|
||||||
|
|
||||||
SlackWebhookURL string `yaml:"slack_webhook_url"`
|
SlackWebhookURL string `yaml:"slack_webhook_url"`
|
||||||
}
|
}
|
||||||
|
@ -112,7 +117,7 @@ func main() {
|
||||||
}
|
}
|
||||||
log.Printf("Using %s/listing as public URI", apiPrefix)
|
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
|
// Make sure bugs directory exists
|
||||||
_ = os.Mkdir("bugs", os.ModePerm)
|
_ = os.Mkdir("bugs", os.ModePerm)
|
||||||
|
|
|
@ -17,6 +17,11 @@ github_token: secrettoken
|
||||||
github_project_mappings:
|
github_project_mappings:
|
||||||
my-app: octocat/HelloWorld
|
my-app: octocat/HelloWorld
|
||||||
|
|
||||||
|
# mappings from app name (as submitted in the API) to github repo 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
|
# a Slack personal webhook URL (https://api.slack.com/incoming-webhooks), which
|
||||||
# will be used to post a notification on Slack for each report.
|
# will be used to post a notification on Slack for each report.
|
||||||
slack_webhook_url: https://hooks.slack.com/services/TTTTTTT/XXXXXXXXXX/YYYYYYYYYYY
|
slack_webhook_url: https://hooks.slack.com/services/TTTTTTT/XXXXXXXXXX/YYYYYYYYYYY
|
||||||
|
|
18
submit.go
18
submit.go
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -50,7 +51,8 @@ type submitServer struct {
|
||||||
apiPrefix string
|
apiPrefix string
|
||||||
|
|
||||||
// mappings from application to github owner/project
|
// mappings from application to github owner/project
|
||||||
githubProjectMappings map[string]string
|
githubProjectMappings map[string]string
|
||||||
|
autocompleteProjectMappings map[string]string
|
||||||
|
|
||||||
slack *slackClient
|
slack *slackClient
|
||||||
}
|
}
|
||||||
|
@ -118,6 +120,16 @@ type submitResponse struct {
|
||||||
ReportURL string `json:"report_url,omitempty"`
|
ReportURL string `json:"report_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// regex to match and substitute ambiguous issue references in the rageshake body text
|
||||||
|
// matches a hash followed by digits optionally surrounded by whitespace or some punctuation
|
||||||
|
// also matches if the input starts with digits where the hash becomes optional
|
||||||
|
var ambiguousIssueRegex = regexp.MustCompile(`(^|[([{\s])(?:^|#)(\d+)([^\w]|$)`)
|
||||||
|
|
||||||
|
func replaceAmbiguousIssueReferences(ownerRepo, text string) string {
|
||||||
|
t := ambiguousIssueRegex.ReplaceAllString(text, fmt.Sprintf("${1}%s#$2$3", ownerRepo))
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
// if we attempt to return a response without reading the request body,
|
// if we attempt to return a response without reading the request body,
|
||||||
// apache gets upset and returns a 500. Let's try this.
|
// apache gets upset and returns a 500. Let's try this.
|
||||||
|
@ -163,6 +175,10 @@ func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.autocompleteProjectMappings[p.AppName] != "" {
|
||||||
|
p.UserText = replaceAmbiguousIssueReferences(s.autocompleteProjectMappings[p.AppName], p.UserText)
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := s.saveReport(req.Context(), *p, reportDir, listingURL)
|
resp, err := s.saveReport(req.Context(), *p, reportDir, listingURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error handling report submission:", err)
|
log.Println("Error handling report submission:", err)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -483,3 +484,22 @@ user_id: id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAutocompleteIssueReferences(t *testing.T) {
|
||||||
|
tests := map[string]string{
|
||||||
|
"Testing #123 Foobar": "Testing owner/repo#123 Foobar", // standard
|
||||||
|
"#123": "owner/repo#123", // first/last word
|
||||||
|
"test (#123) bar": "test (owner/repo#123) bar", // brackets
|
||||||
|
"Start #123. Now": "Start owner/repo#123. Now", // followed by punctuation
|
||||||
|
"#123foo": "#123foo", // ignore
|
||||||
|
"foo/#123": "foo/#123", // ignore
|
||||||
|
"123": "owner/repo#123", // special case for entire body being a number
|
||||||
|
}
|
||||||
|
|
||||||
|
for text, expect := range tests {
|
||||||
|
got := replaceAmbiguousIssueReferences("owner/repo", text)
|
||||||
|
if expect != got {
|
||||||
|
t.Errorf("expected %s got %s", expect, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in a new issue