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

Prefill GitHub Issue Template automatically #927

Merged
merged 3 commits into from
Mar 1, 2024
Merged
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
25 changes: 14 additions & 11 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IMPORTANT: This template is also used for error reporting and some attributes are automatically prefilled.
# If you make changes, make sure that ATTRIBUTE IDs, LABELS and PROJECTS matches com.sourcegraph.cody.error.CodyErrorSubmitter code (and vice versa).

name: JetBrains Bug report ፨
description: "File a bug report for any of the JetBrains IDEs: IntelliJ, Goland, WebStorm, etc."
title: "bug: "
Expand All @@ -13,33 +16,33 @@ body:
Thanks for taking the time to fill out this bug report! Please include as much information as possible to help us fix the issue.

Tip: You can attach images or videos by dragging it into the text box.
- type: textarea
- id: version
type: textarea
attributes:
label: Installation Information
description: Trigger the action "About", click on "Copy and close" and paste the output here
description: Trigger the action "About", click on "Copy and Close" and paste the output here.
validations:
required: true
- type: textarea
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is. Please include steps on how to reproduce the behaviour.
description: Description of what the bug is. Please include steps on how to reproduce the behaviour.
validations:
required: true
- type: textarea
attributes:
label: Expected behavior
description: A clear and concise description of what you expected to happen.
description: Description of what you expected to happen.
validations:
required: true
- type: textarea
- id: logs
type: textarea
attributes:
label: Additional context (logs, images, etc)
label: Additional context
description: |
Please add any links, or references that can give us more context on the bug.
Please include stacktrace, logs, links, or references that can give us more context on the bug.

For logs - Trigger the action "Show Log", open the file, search for exceptions related to Cody/Sourcegraph and copy relevant lines here
Alternatively, feel free to upload idea.log as an attachment but please make sure it doesn't contain sensitive information (it normally doesn't)

Tip: You can attach images or videos by dragging it into the text box.
For logs - Trigger the action "Show Log", open the file, search for exceptions related to Cody/Sourcegraph and copy relevant lines here.
Alternatively, feel free to upload `idea.log` as an attachment but please make sure it doesn't contain sensitive information (it normally doesn't).
validations:
required: false
8 changes: 1 addition & 7 deletions src/main/kotlin/com/sourcegraph/cody/error/CodyError.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
package com.sourcegraph.cody.error

data class CodyError(
val title: String,
val pluginVersion: String?,
val ideVersion: String,
val additionalInfo: String?,
val stacktrace: String
)
data class CodyError(val title: String, val version: String, val logs: String)
18 changes: 0 additions & 18 deletions src/main/kotlin/com/sourcegraph/cody/error/CodyErrorFormatter.kt

This file was deleted.

55 changes: 38 additions & 17 deletions src/main/kotlin/com/sourcegraph/cody/error/CodyErrorSubmitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class CodyErrorSubmitter : ErrorReportSubmitter() {
try {
if (events.isNotEmpty()) {
val event = events.first()
val error = getErrorDetails(event, additionalInfo)
val markdownText = CodyErrorFormatter.formatToMarkdown(error)
val url = encodeIssue(error.title, markdownText)
val error =
CodyError(
title = getTitle(event),
version = getVersion(),
logs = getLogs(event, additionalInfo))
val url = getEncodedUrl(error)
BrowserUtil.browse(url)
}
} catch (e: Exception) {
Expand All @@ -36,24 +39,42 @@ class CodyErrorSubmitter : ErrorReportSubmitter() {
return true
}

private fun getErrorDetails(event: IdeaLoggingEvent, additionalInfo: String?) =
CodyError(
title = trimPostfix("bug: " + event.throwableText.lines().first(), 128),
pluginVersion = pluginDescriptor?.version,
ideVersion = ApplicationInfo.getInstance().build.toString(),
additionalInfo = additionalInfo,
stacktrace = trimPostfix(event.throwableText, 6500)) // max length for gh links is 8192
private fun getTitle(event: IdeaLoggingEvent): String {
val title = trimPostfix(event.throwableText.lines().first(), 128)
return "bug: $title"
}

private fun encodeIssue(title: String, body: String): String =
"https://github.com/sourcegraph/jetbrains/issues/new" +
"?labels=bug" +
"&title=${encode(title)}" +
"&body=${encode(body)}"
private fun getVersion() =
formatAttributes(
"Plugin version" to pluginDescriptor?.version,
"IDE version" to ApplicationInfo.getInstance().build.toString())

private fun encode(text: String) = URLEncoder.encode(text, "UTF-8")
private fun getLogs(event: IdeaLoggingEvent, additionalInfo: String?) =
formatAttributes(
"Stacktrace" to trimPostfix(event.throwableText, 6500), // max total length is 8192
"Additional info" to additionalInfo)

private fun trimPostfix(text: String, maxLength: Int): String {
val postfix = " (...)"
val postfix = "..."
return if (text.length > maxLength) text.take(maxLength - postfix.length) + postfix else text
}

private fun formatAttributes(vararg pairs: Pair<String, String?>) =
pairs
.flatMap { (key, value) -> value?.let { listOf(formatAttribute(key, it)) } ?: listOf() }
.joinToString("\n")

private fun formatAttribute(label: String, text: String) =
if (text.lines().size != 1) "$label:\n```text\n$text\n```" else "$label: ```$text```"

private fun getEncodedUrl(error: CodyError): String =
"https://github.com/exigow/issue-template-test/issues/new" +
"?template=bug_report.yml" +
"&labels=bug,team/jetbrains" +
"&projects=sourcegraph/381" +
"&title=${encode(error.title)}" +
"&version=${encode(error.version)}" +
"&logs=${encode(error.logs)}"

private fun encode(text: String) = URLEncoder.encode(text, "UTF-8")
}

This file was deleted.

Loading