Skip to content

Instantly share code, notes, and snippets.

@danielhickman
Created January 6, 2016 04:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhickman/bbe5dbc82b862de94270 to your computer and use it in GitHub Desktop.
Save danielhickman/bbe5dbc82b862de94270 to your computer and use it in GitHub Desktop.
JavScript Bug Reporter for GitHub Repos

JavaScript:

(function() {
	"use strict";
	// Set me!
	githubURL = "https://github.com/username/repo";
	title = "[Bug Report]: Blah Blah Blah";


	var errors = [];
	window.onerror = function(error, url, line) {
		error = {"error": error, "url": url, "line": line};
		if (errors.length > 0) {
			var lastError = errors[errors.length - 1];
			if (error.error === lastError.error && error.url === lastError.url && error.line === lastError.line) {
				typeof lastError.recurrences === "number" ? lastError.recurrences ++ : lastError.recurrences = 1;
				return;
			}
		}
		errors.push(error);
	};

	function bugReport() {
		var url = githubURL + "/issues/new?title=" + encodeURIComponent(title) + "&body=" + encodeURIComponent("Explain your problem here: \n\n*Please leave this for the developers:*\n```json\nErrors: ");
		if (errors.length > 0) {
			for (var i = 0; i < errors.length; i++) {
				url += encodeURIComponent(JSON.stringify(errors[i]));
			}
		} else {
			url += encodeURIComponent("None. (Yay!)");
		}
		url += encodeURIComponent("\n\nUser-Agent: " + navigator.userAgent + "\n```");
		var win = window.open(url, '_blank');
		win.focus();
	}
});

Instructions:

  1. Set githubURL
  2. Add to your script or a <script> tag
  3. Call bugReport(); in a script, in onclick, or in a href (with javascript:bugReport();)

Note:

  • This isn't automatic, that'd require hub and a script a server
  • Users have to be signed in to GitHub or sign in after clicking the link
@crutchcorn
Copy link

👍 Using this for everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment