Skip to content

Commit

Permalink
Add support for draft PRs (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Apr 26, 2020
1 parent 46d90dd commit 4ef9c1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions source/github-issue-link-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ const issueUrlRegex = /^[/]([^/]+[/][^/]+)[/](issues|pull)[/](\d+)([/]|$)/;
const stateColorMap = {
open: 'text-green',
closed: 'text-red',
merged: 'text-purple'
merged: 'text-purple',
draft: 'text-gray'
};

const stateDependentIcons = [
'closedissue',
'mergedpullrequest'
];

function anySelector(selector) {
const prefix = document.head.style.MozOrient === '' ? 'moz' : 'webkit';
return selector.replace(/:any\(/g, `:-${prefix}-any(`);
Expand Down Expand Up @@ -50,7 +56,8 @@ function buildGQL(links) {
${esc(id)}: issueOrPullRequest(number: ${id}) {
__typename
... on PullRequest {
state
state,
isDraft
}
... on Issue {
state
Expand Down Expand Up @@ -108,10 +115,14 @@ async function apply() {
for (const {link, repo, id} of links) {
try {
const item = data[esc(repo)][esc(id)];
const state = item.state.toLowerCase();
const type = item.__typename.toLowerCase();
let state = item.state.toLowerCase();
if (item.isDraft && state === 'open') {
state = 'draft';
}

link.classList.add(stateColorMap[state]);
if (state !== 'open' && state + type !== 'closedpullrequest') {
if (stateDependentIcons.includes(state + type)) {
link.querySelector('svg').outerHTML = icons[state + type];
}
} catch {/* Probably a redirect */}
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
devtool: 'source-map',
entry: {
'github-issue-link-status': './source/github-issue-link-status',
background: './source/background',
Expand Down

0 comments on commit 4ef9c1d

Please sign in to comment.