Skip to content

Commit cdeabb2

Browse files
committed
improv: differentiate draft PRs
1 parent 92b3090 commit cdeabb2

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

scripts/my-github-issues.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ function run() {
2323
const issues = JSON.parse(app.doShellScript(`curl -sL "${apiURL}"`)).items.map(
2424
(/** @type {GithubIssue} */ item) => {
2525
const issueAuthor = item.user.login;
26-
const isPR = Boolean(item.pull_request);
27-
const merged = Boolean(item.pull_request?.merged_at);
28-
const title = item.title;
2926
const repo = (item.repository_url.match(/[^/]+$/) || "")[0];
3027
const comments = item.comments > 0 ? "💬 " + item.comments.toString() : "";
31-
const open = item.state === "open";
32-
const closed = item.state === "closed";
33-
const reason = item.state_reason;
3428
const labels = item.labels.map((label) => `[${label.name}]`).join(" ");
3529

3630
const subtitle = [`#${item.number}`, repo, comments.toString(), labels]
3731
.filter(Boolean)
3832
.join(" ");
3933

40-
// icon
34+
// ICON
4135
let icon = issueAuthor === username ? "✏️ " : "";
42-
if (open && isPR) icon += "🟩 ";
43-
else if (closed && isPR && merged) icon += "🟪 ";
44-
else if (closed && isPR && !merged) icon += "🟥 ";
45-
else if (open && !isPR) icon += "🟢 ";
46-
else if (closed && reason === "not_planned") icon += "⚪ ";
47-
else if (closed && reason === "completed") icon += "🟣 ";
36+
if (item.pull_request) {
37+
if (item.draft) icon += "⬜ ";
38+
else if (item.state === "open") icon += "🟩 ";
39+
else if (item.pull_request.merged_at) icon += "🟪 ";
40+
else icon += "🟥 ";
41+
} else {
42+
// biome-ignore lint/style/useCollapsedElseIf: here it's more readable this way
43+
if (item.state === "open") icon += "🟢 ";
44+
else if (item.state_reason === "not_planned") icon += "⚪ ";
45+
else if (item.state_reason === "completed") icon += "🟣 ";
46+
}
4847

4948
let matcher = alfredMatcher(item.title) + " " + alfredMatcher(repo) + " " + item.state;
50-
if (isPR) matcher += " pr";
49+
if (item.pull_request) matcher += " pr";
5150
else matcher += " issue";
51+
if (item.draft) matcher += " draft";
5252

5353
return {
54-
title: icon + title,
54+
title: icon + item.title,
5555
subtitle: subtitle,
5656
match: matcher,
5757
arg: item.html_url,

scripts/my-github-prs.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function alfredMatcher(str) {
1616
* @return {string} relative date
1717
*/
1818
function humanRelativeDate(isoDateStr) {
19-
const deltaSecs = (+new Date() - +new Date(isoDateStr)) / 1000;
19+
const deltaSecs = (Date.now() - +new Date(isoDateStr)) / 1000;
2020
/** @type {"year"|"month"|"week"|"day"|"hour"|"minute"|"second"} */
2121
let unit;
2222
let delta;
@@ -51,16 +51,15 @@ function humanRelativeDate(isoDateStr) {
5151

5252
// biome-ignore lint/correctness/noUnusedVariables: alfred_run
5353
function run() {
54-
const numberOfPrs = 100; // 100 is the maximum of API
5554
const username = $.getenv("github_username");
56-
const apiURL = `https://api.github.com/search/issues?q=author:${username}+is:pr+is:open&per_page=${numberOfPrs}`;
55+
const apiURL = `https://api.github.com/search/issues?q=author:${username}+is:pr+is:open&per_page=100`;
5756

5857
const openPrs = JSON.parse(app.doShellScript(`curl -sL "${apiURL}"`)).items.map(
5958
(/** @type {GithubIssue} */ item) => {
60-
const title = item.title;
6159
const repo = (item.repository_url.match(/[^/]+$/) || "")[0];
6260
const comments = item.comments > 0 ? "💬 " + item.comments.toString() : "";
63-
const draftIcon = item.draft ? "📝 " : "";
61+
const icon = item.draft ? "⬜" : "🟩 ";
62+
6463
const subtitle = [
6564
`#${item.number}`,
6665
repo,
@@ -71,9 +70,9 @@ function run() {
7170
.join(" ");
7271

7372
return {
74-
title: draftIcon + title,
73+
title: icon + item.title,
7574
subtitle: subtitle,
76-
match: alfredMatcher(title) + alfredMatcher(repo),
75+
match: alfredMatcher(item.title) + alfredMatcher(repo),
7776
arg: item.html_url,
7877
quicklookurl: item.html_url,
7978
};

0 commit comments

Comments
 (0)