Skip to content

Commit 186be15

Browse files
committed
improv: appearance and sorting of issue search
1 parent 48d4939 commit 186be15

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

β€Žgithub-api.d.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ declare class GithubNotif {
2323
declare class GithubIssue {
2424
title: string;
2525
user: { login: string };
26-
state: string;
26+
state: "open" | "closed";
27+
// biome-ignore lint/style/useNamingConvention: not_by_me
28+
state_reason?: "not_planned" | "completed";
2729
comments: number;
2830
draft: boolean;
2931
// biome-ignore lint/style/useNamingConvention: not_by_me
@@ -41,6 +43,7 @@ declare class GithubIssue {
4143
created_at: string;
4244
// biome-ignore lint/style/useNamingConvention: not_by_me
4345
updated_at: string;
46+
labels: { name: string }[];
4447
}
4548

4649
declare class GithubRepo {

β€Žscripts/my-github-issues.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,43 @@ function alfredMatcher(str) {
1717
function run() {
1818
const resultsNumber = 50; // api allows up to 100
1919
const username = $.getenv("github_username");
20-
const apiURL = `https://api.github.com/search/issues?q=involves:${username}&per_page=${resultsNumber}`;
20+
21+
// DOCS https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-issues-assigned-to-the-authenticated-user--parameters
22+
const apiURL = `https://api.github.com/search/issues?q=involves:${username}&sort=updated&per_page=${resultsNumber}`;
2123

2224
const issues = JSON.parse(app.doShellScript(`curl -sL "${apiURL}"`)).items.map(
2325
(/** @type {GithubIssue} */ item) => {
2426
const issueAuthor = item.user.login;
25-
const authoredByMe = issueAuthor === username;
26-
2727
const isPR = Boolean(item.pull_request);
2828
const merged = Boolean(item.pull_request?.merged_at);
2929
const title = item.title;
3030
const repo = (item.repository_url.match(/[^/]+$/) || "")[0];
3131
const comments = item.comments > 0 ? "πŸ’¬ " + item.comments.toString() : "";
32+
const open = item.state === "open";
33+
const closed = item.state === "closed";
34+
const reason = item.state_reason;
35+
const labels = item.labels.map((label) => `[${label.name}]`).join(" ");
36+
37+
const subtitle = [`#${item.number}`, repo, comments.toString(), labels]
38+
.filter(Boolean)
39+
.join(" ");
3240

33-
let icon = authoredByMe ? "🚩 " : "";
34-
if (item.state === "open" && isPR) icon += "🟩 ";
35-
else if (item.state === "closed" && isPR && merged) icon += "πŸŸͺ ";
36-
else if (item.state === "closed" && isPR && !merged) icon += "πŸŸ₯ ";
37-
else if (item.state === "closed" && !isPR) icon += "🟣 ";
38-
else if (item.state === "open" && !isPR) icon += "🟒 ";
39-
if (title.toLowerCase().includes("request") || title.includes("FR")) icon += "πŸ™ ";
40-
if (title.toLowerCase().includes("bug")) icon += "πŸͺ² ";
41+
// icon
42+
let icon = issueAuthor === username ? "✏️ " : "";
43+
if (open && isPR) icon += "🟩 ";
44+
else if (closed && isPR && merged) icon += "πŸŸͺ ";
45+
else if (closed && isPR && !merged) icon += "πŸŸ₯ ";
46+
else if (open && !isPR) icon += "🟒 ";
47+
else if (closed && reason === "not_planned") icon += "βšͺ ";
48+
else if (closed && reason === "completed") icon += "🟣 ";
4149

4250
let matcher = alfredMatcher(item.title) + " " + alfredMatcher(repo) + " " + item.state;
4351
if (isPR) matcher += " pr";
4452
else matcher += " issue";
4553

4654
return {
4755
title: icon + title,
48-
subtitle: `#${item.number} ${repo} ${comments}`,
56+
subtitle: subtitle,
4957
match: matcher,
5058
arg: item.html_url,
5159
quicklookurl: item.html_url,

0 commit comments

Comments
Β (0)