// ==UserScript== // @name GitHub - list own PRs in a repository // @description A brief description of your script // @namespace http://arantius.com/misc/greasemonkey/ // @author Sagi Dayan // @match https://github.com/* // @version 1.0 // ==/UserScript== // Update These const GITHUB_AUTH = ''; // https://github.com/settings/tokens const GITHUB_USERNAME = ''; // let currentRepo = ''; // fetch my prs async function getPRs() { const response = await fetch("https://api.github.com/graphql", { "method": "POST", "headers": { "Content-Type": "application/json", "Authorization": `token ${GITHUB_AUTH}` }, "body": "{\"query\":\"{\\n user(login: \\\"" + GITHUB_USERNAME + "\\\") {\\n pullRequests(first: 100, states: OPEN, baseRefName:\\\"master\\\") {\\n totalCount\\n nodes {\\n createdAt\\n number\\n title\\n mergeable\\n url\\n commits(last:1) {\\n nodes {\\n commit {\\n statusCheckRollup{\\n state\\n }\\n }\\n }\\n }\\n baseRefName\\n headRefName\\n repository{\\n nameWithOwner\\n }\\n }\\n pageInfo {\\n hasNextPage\\n endCursor\\n }\\n }\\n }\\n}\"}" }); const payload = await response.json(); const prs = payload.data.user.pullRequests.nodes.filter(pr => { return pr.repository.nameWithOwner === currentRepo; }); const main = document.getElementsByTagName('main')[0]; if (!main) return; prs.forEach(pr => { main.lastElementChild.insertBefore(createPrHTML(pr), main.lastElementChild.firstElementChild); }); } setInterval(() => { const urlSplit = document.URL.split('/'); if (urlSplit.length !== 5) return; // Not A base repo URL const location = urlSplit.slice(-2).join('/') if (location !== currentRepo) { currentRepo = location; getPRs(); } }, 1000); function createPrHTML(pr) { const div = document.createElement('div'); const prState = pr.commits.nodes[0].commit.statusCheckRollup.state; const prStateColor = prState === 'FAILURE' ? 'red' : (prState === 'SUCCESS' ? 'green' : 'yellow'); div.className = "d-sm-flex Box mb-2 Box-body color-bg-secondary"; div.innerHTML = `
${prState}

${pr.title}

Open
`; return div; }