Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create additional labels when detecting Dendrite or Conduit homeserver #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/55.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Dendrite and Conduit labels when detected in the `server_version` field of the rageshake payload
54 changes: 33 additions & 21 deletions submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,31 @@ type jsonLogEntry struct {
type genericWebhookPayload struct {
payload
// If a github/gitlab report is generated, this is set.
ReportURL string `json:"report_url"`
ReportURL string `json:"report_url"`
// Complete link to the listing URL that contains all uploaded logs
ListingURL string `json:"listing_url"`
}

// Stores information about a request made to this server
type payload struct {
// A unique ID for this payload, generated within this server
ID string `json:"id"`
// A multi-line string containing the user description of the fault.
UserText string `json:"user_text"`
// A unique ID for this payload, generated within this server
ID string `json:"id"`
// A multi-line string containing the user description of the fault.
UserText string `json:"user_text"`
// A short slug to identify the app making the report
AppName string `json:"app"`
AppName string `json:"app"`
// Arbitrary data to annotate the report
Data map[string]string `json:"data"`
Data map[string]string `json:"data"`
// Short labels to group reports
Labels []string `json:"labels"`
Labels []string `json:"labels"`
// A list of names of logs recognised by the server
Logs []string `json:"logs"`
Logs []string `json:"logs"`
// Set if there are log parsing errors
LogErrors []string `json:"logErrors"`
LogErrors []string `json:"logErrors"`
// A list of other files (not logs) uploaded as part of the rageshake
Files []string `json:"files"`
Files []string `json:"files"`
// Set if there are file parsing errors
FileErrors []string `json:"fileErrors"`
FileErrors []string `json:"fileErrors"`
}

func (p payload) WriteTo(out io.Writer) {
Expand Down Expand Up @@ -539,9 +539,9 @@ func (s *submitServer) submitGenericWebhook(p payload, listingURL string, report
return nil
}
genericHookPayload := genericWebhookPayload{
payload: p,
ReportURL: reportURL,
ListingURL: listingURL,
payload: p,
ReportURL: reportURL,
ListingURL: listingURL,
}
for _, url := range s.cfg.GenericWebhookURLs {
// Enrich the payload with a reportURL and listingURL, to convert a single struct
Expand Down Expand Up @@ -695,14 +695,30 @@ func buildGenericIssueRequest(p payload, listingURL string) (title, body string)
return
}

func getAdditionalLabels(p payload) []string {
labels := []string{}
if serverVersion, ok := p.Data["server_version"]; ok {
// TODO: It seems only Element Android sends server_version right now and
// that Element iOS doesn't, so we should do something about that.
switch {
case strings.Contains(serverVersion, "Dendrite"):
labels = append(labels, "Dendrite")
case strings.Contains(serverVersion, "Conduit"):
labels = append(labels, "Conduit")
}
}
return labels
}

func buildGithubIssueRequest(p payload, listingURL string) github.IssueRequest {
title, body := buildGenericIssueRequest(p, listingURL)

labels := p.Labels
labels := append(p.Labels, getAdditionalLabels(p)...)
// go-github doesn't like nils
if labels == nil {
labels = []string{}
}

return github.IssueRequest{
Title: &title,
Body: &body,
Expand All @@ -713,15 +729,11 @@ func buildGithubIssueRequest(p payload, listingURL string) github.IssueRequest {
func buildGitlabIssueRequest(p payload, listingURL string, labels []string, confidential bool) *gitlab.CreateIssueOptions {
title, body := buildGenericIssueRequest(p, listingURL)

if p.Labels != nil {
labels = append(labels, p.Labels...)
}

return &gitlab.CreateIssueOptions{
Title: &title,
Description: &body,
Confidential: &confidential,
Labels: labels,
Labels: append(p.Labels, getAdditionalLabels(p)...),
}
}

Expand Down