Skip to content

Instantly share code, notes, and snippets.

@mgerdts
Last active January 29, 2020 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgerdts/91cd0f6a91b3251708943259585e85c1 to your computer and use it in GitHub Desktop.
Save mgerdts/91cd0f6a91b3251708943259585e85c1 to your computer and use it in GitHub Desktop.
Colapse Confirmed

Collapse Confirmed

This user script may be used with Tamper Monkey or similar to add a "Collapsed Confirmed" button to github pull requests.

Why is this needed?

I have observed:

  • Large PRs can generate hundreds of comment threads.
  • There is no good for the submitter to mark "ok, I've done the work" and for the commenter to say "yep, looks good now".
  • Reviewing the latest changes does not necessarily allow one to see the comments (if any) that inspired a change.
  • It is rather painful to manually sort through which comment threads still need attention.

Who does what in a PR?

This was implemented for a PR where:

  1. I made a bunch of comments
  2. The submitter addressed comments here and there, marking them resolved as things progressed. Marking resolved corresponded with a change in the submitter's workspace. That code generally made it up to github hours to days later.
  3. From time to time I reviewed the recent fixes. To indicate my happiness with them, I added a "confirmed" comment. To express my displeasure, I explained what was wrong and marked the comment thread unresolved.

How can this script be used?

  1. Install tamper monkey or similar user script extension
  2. Add the expand expand expand script.
  3. Add the Collapse Confirmed scrpt (below)
  4. Visit a PR, first click on the expand button. When it is done, click on the collapse button.

A good PR to try it on is TritonDataCenter/kbmd#2.

// ==UserScript==
// @name GitHub PR: mgerdts collapse confirmed
// @namespace http://mgerdts.github.io/
// @version 0.5
// @description After "expand, expand!" collapse the threads that end with a "confirmed" comment
// @author findepi
// @license MIT
// @match https://github.com/*/*/pull/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
(function() {
'use strict';
console.log('Installing "Confirmed - mgerdts"');
var box = jQuery(".pagehead-actions").first();
box.prepend('<li><a id="_f_mgerdts_confirm" class="btn btn-sm">Hide Confirmed</a></li>');
jQuery('#_f_mgerdts_confirm').click(collapseConfirmed);
var lastthread = undefined;
function collapseConfirmed() {
for (var thread of jQuery("details.js-resolvable-timeline-thread-container")) {
lastthread = thread;
var attrs = thread.attributes;
console.log(attrs);
if (!attrs["data-resolved"] || !attrs.hasOwnProperty("open")) {
continue;
}
var comments = $(thread).find(".review-comment");
if (comments.length == 0) {
continue;
}
var text = comments[comments.length - 1].innerText;
console.log('MG text: ' + text);
var lines = text.split("\n");
if (lines.length == 4 && lines[3].trim().match("confirmed.?")) {
thread.open = false;
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment