Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/github-actions-grafana-jump/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"@types/greasemonkey": "~4.0.7",
"typescript": "~5.8.3"
"typescript": "~6.0.3"
}
}
8 changes: 7 additions & 1 deletion packages/github-actions-grafana-jump/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src"
"rootDir": "./src",
// This is the only package that references ambient globals from
// @types/node (the `module` test-export guard) and @types/greasemonkey
// (`GM`). Under moduleResolution: bundler, tsc does not auto-include
// these from node_modules/@types the way it does under "node"/"node10" -
// list them explicitly rather than relying on that auto-discovery.
"types": ["node", "greasemonkey"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
Expand Down
67 changes: 67 additions & 0 deletions packages/graphite-to-github-button/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ==UserScript==
// @name Graphite => GitHub button
// @description Add a button to go from app.graphite.dev to github.com
// @match https://app.graphite.dev/*
// @version 0.3.3
// @run-at document-start
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @license MIT
// @namespace https://app.graphite.dev
// @downloadURL https://update.greasyfork.org/scripts/509841/Graphite%20%3D%3E%20GitHub%20button.user.js
// @updateURL https://update.greasyfork.org/scripts/509841/Graphite%20%3D%3E%20GitHub%20button.meta.js
// ==/UserScript==

const PATH_REGEX = /^\/github\/pr\/([^\/]+)\/([^\/]+)\/([^\/]+).*$/;
const SELECTOR =
'[class^="PullRequestTitleBar_container_"] > div:nth-child(1) > div:nth-child(2)';

const addButton = (toolbar: HTMLElement) => {
const match = window.location.pathname.match(PATH_REGEX);
if (!match) return;

const [_, org, repo, pr] = match;
const gitHubLink = `https://github.com/${org}/${repo}/pull/${pr}`;

if (document.getElementById("gitHubLink") != null) {
return;
}

const anchorEl = document.createElement("a");
anchorEl.setAttribute("id", "gitHubLink");
anchorEl.setAttribute("href", gitHubLink);
anchorEl.setAttribute("target", "_blank");
anchorEl.setAttribute(
"style",
"background: #f0f0f333; padding: 6px; border-radius: 4px; flex-shrink: 0;"
);
anchorEl.appendChild(document.createTextNode("GitHub ↗️"));

toolbar.appendChild(anchorEl);
};

const toolbarObserver = new MutationObserver((_, observer) => {
const toolbar = document.querySelector(SELECTOR) as HTMLElement;
if (toolbar) {
observer.disconnect();
addButton(toolbar);
}
});

let lastPathname: string | undefined;
const routeChangeObserver = new MutationObserver(() => {
const { pathname } = window.location;

if (pathname !== lastPathname) {
lastPathname = pathname;

if (pathname.match(PATH_REGEX)) {
toolbarObserver.observe(document.body, {
childList: true,
subtree: true,
});
}
}
});

routeChangeObserver.observe(document.body, { childList: true, subtree: true });
6 changes: 5 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"target": "ES2020",
"module": "ESNext",
"lib": ["ES2020", "DOM"],
"moduleResolution": "node",
// "node" (an alias for the legacy "node10" strategy) is deprecated as of
// TypeScript 6.0 and will stop functioning in 7.0 (TS5107). "bundler" is
// the modern pairing for `module: ESNext`; no package in this repo does
// external module imports, so this has no effect on compiled output.
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ __metadata:
resolution: "@nsheaps/gm-github-actions-grafana-jump@workspace:packages/github-actions-grafana-jump"
dependencies:
"@types/greasemonkey": "npm:~4.0.7"
typescript: "npm:~5.8.3"
typescript: "npm:~6.0.3"
languageName: unknown
linkType: soft

Expand Down
Loading