"Stock Replies" script

I’ve rewritten the old “Stock Replies” greasemonkey script and updated it in the launchpad-gm-scripts repo. The script’s available here:

https://code.launchpad.net/~gm-dev-launchpad/launchpad-gm-scripts/master

Overview

Greasemonkey is a Firefox add-on that lets you run Javascript code on top of a given website, to modify the web page’s behavior. The scripts in launchpad-gm-scripts use this to enhance Launchpad’s behavior.

Stock Replies is one of these scripts. It augments Launchpad bug report pages with a set of “buttons” (actually clickable links) that paste in standard bug triaging text replies.

It’s also capable of changing the Importance, Status, Assignee, and Package for the bug report. This can be used, for instance, to ask users to attach certain files or command output and then mark the bug as “Incomplete”. Or, to thank a reporter for supplying a patch, mark it “Triaged”, and subscribe a team.

Installation

To install GreaseMonkey, follow these steps:

  • From Firefox’s “hamburger menu” go to AddOns
  • In the search field type “Greasemonkey”
  • Select GreaseMonkey, and “+ Add to Firefox”

Then to install the script, download it from here:

~gm-dev-launchpad/launchpad-gm-scripts/master : contents of lp_stockreplies.user.js at revision 188

install_dialog

NOTE: I doubt this will work with Chromium, but may with sufficient fiddling. If you give it a shot, please collect findings/patches at [LP: #889167](Bug #889167 “stock-replies: LP stock responses extension does no...” : Bugs : Launchpad Greasemonkey Scripts.

Usage

Load up any Launchpad bug report. Click on the ‘>’ next to any bug task and look underneath the ‘Comment on this change’ textarea for a set of hyperlink “buttons”.

Hover over the hyperlink and a description of the reply will pop up.

When the hyperlink is clicked, it sets the text in the Comment field (clearing any existing text), and may also change Status, Importance, and other fields for the bug task. Note that if the bug report has multiple bug tasks (i.e. it’s filed against multiple packages or distros) the changes will only affect the current bug task.

Selecting Alternate Stock Reply Sets

You’ll notice a monkey face added to your Facebook toolbar. Clicking on it lets you manage and edit your Greasemonkey scripts.

Do this, and select LP_Stock_Replies_NG. This brings the Javascript file up in your editor. Find the @require line, about 10 lines down from the top. Erase the URL on that line and replace it with your own.

Eventually we’ll have several standard stock reply datasets you can link to from the script, or you can craft your own. Someday I’d like to make dataset switching more user-friendly (LP: #845203), but Greasemonkey has a few design constraints that make this challenging. For now, see below for how to write your own stock replies.

NOTE: Greasemonkey only reloads the data from the remote JSON file when the URL changes. So if the stock replies are ever modified, you have to manually reload it, unfortunately. As a workaround, you can fake a URL change by appending ‘?’ to the URL and saving.

Creating Your Own Stock Replies

The JSON file with the stock reply data looks like this:

response_data = [
    {
	name: "...",
	tip: "...",
	status: "...",
	importance: "...",
	package: "...",
	assignee: "...",
	comment: "..."
    },
    {
        ...
    }
];

The response_data list can be as long as desired. You must have a ‘name’ defined for each entry, but all the other fields are optional. A blank string for any field means to leave the bug report’s existing value unchanged.

name’ is the hyperlink text that’s displayed on the bug report webpage. Provide something short but meaningful here.

tip’ is a tooltip displayed when hovering over the hyperlink. Use it for a more detailed reminder of what this stock reply does.

status’ and ‘importance’ correspond to the values in the dropdown selection widgets. Make sure these values correspond exactly to one of the valid values for the given dropdown.

package’ will change the source package that the bug task is filed against. Be aware that it doesn’t reset to the original package, so if you select a stock reply that changes it, then a different stock reply that would normally leave the package untouched, it’ll end up with the changed version (LP: #334040).

assignee’ can be used to set a specific LP username as the assignee. It also accepts two special values: “-me”, which assigns the bug task to yourself; and “-nobody”, which unassigns the bug task.

comment’ is the text to put into the bug report’s reply textbox. This will clear any existing text. JSON doesn’t permit raw newlines inside text strings, but you can use “\n” and whitespace for formatting purposes.

A few template variables are supported in the comment field text:

  • “PROJECTNAME” - Resolves to “Ubuntu”, or other distro/project this was filed against.
  • “PKGNAME” - The source package name for the bug task.
  • “BUGNUMBER” - The bug report’s LP number.
  • “REPORTER” - The full (display) name of the bug reporter.
  • “UPSTREAMBUG” - URL to corresponding bug in an external tracker, if any.

These will be replaced with corresponding text from the bug report html.

2 Likes