diff --git a/README.md b/README.md index 79f8eb5..f54e9e6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Github PR Shortcuts Extension -A simple Chrome extension that allows you to close all github PR files. +A simple Chrome extension that makes using github easier to review PR. ## Installation @@ -15,11 +15,21 @@ To install follow these steps: ## Usage -To use the extension, simply press the `Ctrl+M` keyboard shortcut while on Github.com. +### Close all open files + +Press the `Ctrl+M` keyboard shortcut while on Github.com. This will close all PR files opened in the changed files tab. +### Request review + +Press the `Alt+R` keyboard shortcut while on Github.com. +This will request review for everyone who previously request changes to a pull request + + + + ## Contributing diff --git a/background.js b/background.js index 5255de0..0d9d6d4 100644 --- a/background.js +++ b/background.js @@ -1,8 +1,15 @@ +function sendCommandToTab(command) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.sendMessage(tabs[0].id, {action: command}); + }); +} + chrome.commands.onCommand.addListener(function(command) { - console.log('Command:', command) + console.log('Command:', command); if (command === "close-github-pr-files") { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - chrome.tabs.sendMessage(tabs[0].id, {action: "closePRFiles"}); - }); + sendCommandToTab("closePRFiles"); + } + if (command === "re-request-review") { + sendCommandToTab("requestReview"); } }); diff --git a/content.js b/content.js index ab9f8d6..9769b8b 100644 --- a/content.js +++ b/content.js @@ -4,4 +4,10 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { .filter((btn) => btn.attributes['aria-expanded']?.value === "true") .forEach((btn) => { btn.click() }); } + + if (request.action === "requestReview") { + Array.prototype.slice.call(document.querySelectorAll('.discussion-sidebar-item .octicon-file-diff')) + .map((diffIcon) => diffIcon.closest('p')?.querySelector('button[name=re_request_reviewer_id]')) + .forEach((btn) => { btn.click() }); + } }); diff --git a/manifest.json b/manifest.json index 52f1602..9a71c72 100644 --- a/manifest.json +++ b/manifest.json @@ -19,6 +19,12 @@ "default": "Ctrl+M" }, "description": "Close github PR files" + }, + "re-request-review": { + "suggested_key": { + "default": "Alt+R" + }, + "description": "Requests review for reviewers who requested changes" } } }