Skip to content

Commit

Permalink
feat: only show priority label
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Dec 8, 2024
1 parent 6d4b076 commit f55ab79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/home/fetch-github/fetch-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function fetchIssueFromPullRequest(pullRequest: GitHubPullRequest): Promis

if (issueUrlMatch) {
// Full URL to the issue is provided
const [,, owner, repo, issueNumber] = issueUrlMatch;
const [, , owner, repo, issueNumber] = issueUrlMatch;
apiUrl = `https://api.github.com/repos/${owner}/${repo}/issues/${issueNumber}`;
} else if (issueNumberMatch) {
// Only issue number is provided, construct API URL using current repo info
Expand Down
20 changes: 5 additions & 15 deletions src/home/rendering/render-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,50 +113,40 @@ function setUpIssueElement(
}

function parseAndGenerateLabels(notification: GitHubIssue) {
type LabelKey = "Price: " | "Time: " | "Priority: ";
type LabelKey = "Priority: ";

const labelOrder: Record<LabelKey, number> = { "Price: ": 1, "Time: ": 2, "Priority: ": 3 };
const labelOrder: Record<LabelKey, number> = { "Priority: ": 1 };

const { labels, otherLabels } = notification.labels.reduce(
const { labels } = notification.labels.reduce(
(acc, label) => {
// check if label is a single string
if (typeof label === "string") {
return {
labels: [],
otherLabels: [],
};
}

// check if label.name exists
if (!label.name) {
return {
labels: [],
otherLabels: [],
};
}

const match = label.name.match(/^(Price|Time|Priority): /);
const match = label.name.match(/^(Priority): /);
if (match) {
const name = label.name.replace(match[0], "");
const labelStr = `<label class="${match[1].toLowerCase().trim()}">${name}</label>`;
acc.labels.push({ order: labelOrder[match[0] as LabelKey], label: labelStr });
} else if (!label.name.startsWith("Partner: ") && !label.name.startsWith("id: ") && !label.name.startsWith("Unavailable")) {
acc.otherLabels.push(label.name);
}
return acc;
},
{ labels: [] as { order: number; label: string }[], otherLabels: [] as string[] }
{ labels: [] as { order: number; label: string }[] }
);

// Sort labels
labels.sort((a: { order: number }, b: { order: number }) => a.order - b.order);

// Log the other labels
if (otherLabels.length) {
const otherLabelName = otherLabels.shift() as string;
labels.unshift({ order: 0, label: `<label class="label full">${otherLabelName}</label>` });
}

return labels.map((label) => label.label);
}

Expand Down

0 comments on commit f55ab79

Please sign in to comment.