Compare commits

...
This repository has been archived on 2022-08-18. You can view files and clone it, but cannot push or open issues or pull requests.

5 Commits

Author SHA1 Message Date
Michael Telatynski 7390a7e43f Merge branch 't3chguy/autocomplete' of https://github.com/matrix-org/rageshake into t3chguy/autocomplete 2020-04-04 11:58:51 +01:00
Michael Telatynski 6ffa32a236 iterate PR 2020-04-04 11:58:38 +01:00
Michael Telatynski 9caf46cc61
Apply suggestions from code review
Co-Authored-By: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
2020-04-01 13:00:38 +01:00
Michael Telatynski 9f6217d159 Fix copyrights, improve comments, fix autocomplete regexp and add tests 2020-03-18 00:58:14 +00:00
Michael Telatynski 36ce7c1910 Add means to autocomplete issue references to a different repo 2020-03-15 13:01:50 +00:00
4 changed files with 48 additions and 2 deletions

View File

@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (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.
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"`
// 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"`
}
@ -112,7 +117,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)

View File

@ -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 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

View File

@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -50,7 +51,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 +120,16 @@ type submitResponse struct {
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) {
// 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 +175,10 @@ func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
if s.autocompleteProjectMappings[p.AppName] != "" {
p.UserText = replaceAmbiguousIssueReferences(s.autocompleteProjectMappings[p.AppName], p.UserText)
}
resp, err := s.saveReport(req.Context(), *p, reportDir, listingURL)
if err != nil {
log.Println("Error handling report submission:", err)

View File

@ -1,5 +1,6 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (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)
}
}
}