Last active
April 16, 2023 16:37
-
-
Save champierre/6290acc1c21cb4d33a5d2b373642be28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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