GitHub: Blame Previous Commit Button

Add a button to `git blame` the `sha^` (parent commit) on each commit on a `git blame` page.

< Feedback on GitHub: Blame Previous Commit Button

Question/comment

§
Posted: 2016-05-25

Support for other GitHubs

I use GitHub Enterprise at work, which is on a different domain but works just like GitHub. It would be great if this would support that. I added the domain to the includes, but it appears the script is specifically looking for github.com links.

ZrenAuthor
§
Posted: 2016-05-25
Edited: 2016-05-25

I don't use enterprise. Do I have to just support dynamic hostnames? In that case, I just need to do:

//var blameUrlPattern = /^(https:\/\/github.com\/[^\/]+\/[^\/]+\/blame\/)([^\/]+)(.*)$/;
var blameUrlPattern = "^(https:\\/\\/"
blameUrlPattern += document.location.hostname.replace(".", "\\.")
blameUrlPattern += "\\/[^\\/]+\\/[^\\/]+\\/blame\\/)([^\\/]+)(.*)$"
blameUrlPattern = new RegExp(blameUrlPattern)
§
Posted: 2016-05-26

Yeah, I think it's just the host name that's the problem. The rest should be the same.

Why even check the host name? You should be able to assume you're on (a) GitHub based on the includes. Just look for a /blame URL, no matter the host.

ZrenAuthor
§
Posted: 2016-06-08

Sorry for taking so long to update the script. You raised a really good point (I should just be regexing the document.location.pathname) and have the browser autofill the domain in the href="/".

Post reply

Sign in to post a reply.