Skip to content

Commit

Permalink
Merge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Nov 4, 2021
1 parent 9c39fb5 commit fe70ce1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions source/github-issue-link-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ const stateColorMap = {
},
};

function addOcticonClass(svgString) {
return svgString?.replace('<svg', '<svg class="octicon"');
function getIcon(state, type, isDraft = false) {
const iconName = isDraft && state === 'open' ? 'draft' + type : state + type;
if (!(iconName in icons)) {
console.error('GitHub Issue Link Status: No icon named', iconName, 'found');
return '';
}

if (iconName === 'draftpullrequest') {
return icons.draftpullrequest.replace('<svg', '<svg class="octicon color-text-tertiary"');
}

return icons[iconName].replace('<svg', '<svg class="octicon"');
}

function esc(repo) {
Expand Down Expand Up @@ -100,7 +110,7 @@ async function apply() {
}

for (const {link, type} of links) {
link.insertAdjacentHTML('beforeEnd', addOcticonClass(icons['open' + type]));
link.insertAdjacentHTML('beforeEnd', getIcon('open', type));
}

const query = buildGQL(links);
Expand All @@ -126,12 +136,7 @@ async function apply() {

link.classList.add(...stateColorMap[type][state]);

const iconName = item.isDraft && state === 'open' ? 'draft' + type : state + type;
if (iconName in icons) {
link.querySelector('svg').outerHTML = addOcticonClass(icons[iconName]);
} else {
console.error('GitHub Issue Link Status: No icon named', iconName, 'found');
}
link.querySelector('svg').outerHTML = getIcon(state, type, item.isDraft);
} catch {/* Probably a redirect */}
}
}
Expand Down

0 comments on commit fe70ce1

Please sign in to comment.