Skip to content

Instantly share code, notes, and snippets.

@champierre
Last active April 16, 2023 16:37
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 champierre/6290acc1c21cb4d33a5d2b373642be28 to your computer and use it in GitHub Desktop.
Save champierre/6290acc1c21cb4d33a5d2b373642be28 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Auto Rubocop Suggestion
// @namespace https://champierre.com/
// @version 1.0
// @description Automatically fill the title and body of suggestions provided by reviewdog/action-rubocop
// @author champierre
// @match https://github.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('DOMContentLoaded', function(event) {
const commentBodies = document.querySelectorAll('.comment-body');
for (let i = 0; i < commentBodies.length; i++) {
const suggestionButton = commentBodies[i].querySelectorAll('.js-apply-suggestion-button')[0];
const p = commentBodies[i].querySelectorAll('p[dir="auto"]')[0];
if (suggestionButton && p) {
const title = `Fix rubocop error: ${p.childNodes[1].textContent}`;
const body = `${title}\n${p.childNodes[4].textContent}`;
suggestionButton.addEventListener('click', (el) => {
const selectMenu = el.target.nextElementSibling;
selectMenu.querySelectorAll('.js-suggestion-commit-title')[0].value = title;
selectMenu.querySelectorAll('.js-quick-submit')[0].value = body;
});
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment