From 52103a05787d53caaea2df8f2d57f0108ef60088 Mon Sep 17 00:00:00 2001 From: glacambre Date: Mon, 8 Apr 2019 09:07:02 +0200 Subject: [PATCH] Add `:issue` excmd and autocmd to autofill new issues --- scripts/git_version.sh | 1 + src/excmds.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/lib/config.ts | 4 +++- webpack.config.js | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/git_version.sh b/scripts/git_version.sh index 462bd92f..a0d44525 100755 --- a/scripts/git_version.sh +++ b/scripts/git_version.sh @@ -5,6 +5,7 @@ manversion=$(grep '"version":' ./src/manifest.json | cut -d":" -f2 | tr -d \" | version=$manversion-$gitversion sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'"$version"'/' ./build/background.js +sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'"$version"'/' ./build/content.js sed -i.bak 's/REPLACE_ME_WITH_THE_VERSION_USING_SED/'"$version"'/' ./build/static/newtab.html rm ./build/background.js.bak rm ./build/static/newtab.html.bak diff --git a/src/excmds.ts b/src/excmds.ts index fc3566df..a2f9be52 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -4083,6 +4083,44 @@ export async function jsb(...str: string[]) { } } +/** + * Opens a new tab the url of which is "https://github.com/tridactyl/tridactyl/issues/new" and automatically fill add tridactyl, firefox and os version to the issue. + */ +//#content +export async function issue() { + const newIssueUrl = "https://github.com/tridactyl/tridactyl/issues/new" + if (window.location.href !== newIssueUrl) { + return Messaging.message("controller_background", "acceptExCmd", ["tabopen " + newIssueUrl]) + } + const textarea = document.getElementById("issue_body") + if (!(textarea instanceof HTMLTextAreaElement)) { + logger.warning("issue(): Couldn't find textarea element in github issue page.") + return + } + let template = await (fetch(browser.extension.getURL("issue_template.md")) + .then(resp => resp.body.getReader()) + .then(reader => reader.read()) + .then(r => (new TextDecoder("utf-8")).decode(r.value))) + if (textarea.value !== template) { + logger.debug("issue(): Textarea value differs from template, exiting early.") + return + } + const platform = await browserBg.runtime.getPlatformInfo(); + // Remove the bit asking the user + template = template.replace("* Operating system:\n", "") + // Add this piece of information to the top of the template + template = `Operating system: ${platform.os}\n` + template + + const info = await browserBg.runtime.getBrowserInfo() + template = template.replace("* Firefox version (Top right menu > Help > About Firefox):\n\n", "") + template = `Firefox version: ${info.vendor} ${info.name} ${info.version}\n` + template + + template = template.replace("* Tridactyl version (`:version`):\n\n", "") + template = `Tridactyl version: ${TRI_VERSION}\n` + template + + textarea.value = template +} + //#background_helper import * as Parser from "rss-parser" import * as semverCompare from "semver-compare" diff --git a/src/lib/config.ts b/src/lib/config.ts index c045c2e3..d2b398d1 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -322,7 +322,9 @@ class default_config { * * Each key corresponds to a URL fragment which, if contained within the page URL, will run the corresponding command. */ - DocLoad: {}, + DocLoad: { + "https://github.com/tridactyl/tridactyl/issues/new": "issue" + }, /** * Commands that will be run when pages are unloaded. diff --git a/webpack.config.js b/webpack.config.js index b04b1b5a..6cc12c63 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -56,6 +56,7 @@ module.exports = { ignore: ["*.psd", "*1024px.png"], }, { from: "generated/static", to: "static" }, + { from: "issue_template.md" }, ]), ], // Fix css