Skip to content

Commit 0997213

Browse files
committed
feat(shortcut): detect repo automatically
1 parent ab5a55d commit 0997213

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ extra-trusted-public-keys = nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq
5353
```
5454

5555
### Shortcuts on nixpkgs PR pages (optional)
56-
Add [`shortcut.user.js`](shortcut.user.js) as a user script in your browser for `https://github.com/` for example using the [User JavaScript and CSS chrome extension](https://chromewebstore.google.com/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld) or [Violentmonkey](https://violentmonkey.github.io/). Don't forget to update the `repo` constant at the top of the file to point to your fork.
56+
Add [`shortcut.user.js`](shortcut.user.js) as a userscript in your browser for `https://github.com/` for example using the [User JavaScript and CSS chrome extension](https://chromewebstore.google.com/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld) or [Violentmonkey](https://violentmonkey.github.io/).
57+
58+
The userscript assumes that you forked this repository to your personal account without changing its name. However, if you forked the repo to an orgnization instead or used a custom repo name or if you would like to use a different repo you have access to, you need to explicitly configure the userscript by updating the `repo` constant at the top of the file to point to the repository you would like to use.
5759

5860
> [!TIP]
59-
> Opening the [raw file](shortcut.user.js?raw=true) with Violetmonkey installed will prompt for installation.
61+
> Opening the [raw file](shortcut.user.js?raw=true) with Violentmonkey installed will prompt for installation.
6062
6163
## Usage
6264
1. Open the [review workflow in the "Actions" tab](../../actions/workflows/review.yml)

shortcut.user.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// @run-at document-idle
55
// ==/UserScript==
66

7-
const repo = "Defelo/nixpkgs-review-gha";
7+
const user = document.querySelector("header.GlobalNav button[data-login]")?.getAttribute("data-login") ?? null;
8+
9+
const repo = user ? `${user}/nixpkgs-review-gha` : null;
810

911
const reviewDefaults = ({ title, commits, labels, author, authoredByMe, hasLinuxRebuilds, hasDarwinRebuilds }) => {
1012
const darwinSandbox = "relaxed";
@@ -60,8 +62,7 @@ const getPrDetails = pr => {
6062
);
6163
const labels = [...document.querySelectorAll("div.js-issue-labels > a")].map(x => x.innerText);
6264
const author = document.querySelector(".js-discussion > :first-child a.author").href.split("/").at(-1);
63-
const self = document.querySelector("header.GlobalNav button[data-login]").getAttribute("data-login");
64-
const authoredByMe = author === self;
65+
const authoredByMe = author === user;
6566
const hasLinuxRebuilds = !labels.some(l => /rebuild-linux: 0$/.test(l));
6667
const hasDarwinRebuilds = !labels.some(l => /rebuild-darwin: 0$/.test(l));
6768
const state = document
@@ -125,7 +126,7 @@ const setupPrPage = async () => {
125126
const pr = match[1];
126127
const actions = await query(document, "div[data-component=PH_Actions], .gh-header-show .gh-header-actions");
127128

128-
if (actions.querySelector(".run-nixpkgs-review") === null) {
129+
if (actions.querySelector(".run-nixpkgs-review") === null && repo) {
129130
const btn = document.createElement("button");
130131
btn.classList.add("Button", "Button--secondary", "Button--small", "run-nixpkgs-review");
131132
btn.innerText = "Run nixpkgs-review";

0 commit comments

Comments
 (0)