Skip to content

Commit 7047c6a

Browse files
committed
feat: public repo search gh supports searching for forks
1 parent c5dbd43 commit 7047c6a

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Helpful GitHub assistant for Alfred.
1515

1616
## Usage
1717
- Search all public GitHub repositories via the keyword `gh`.
18+
* Uses the [GitHub search query
19+
syntax](https://docs.github.com/en/search-github/searching-on-github/searching-for-repositories),
20+
for example `alfred user:chrisgrieser` to search for repositories with the
21+
name `alfred` by the user `chrisgrieser`.
1822
* <kbd>⏎</kbd>: Open the repo's GitHub page.
1923
* <kbd>⌘⏎</kbd>: Open the repo's homepage. If it has none, opens the
2024
releases page instead.
@@ -49,8 +53,8 @@ Helpful GitHub assistant for Alfred.
4953
* <kbd>⌥⏎</kbd>: Copy the URL of the notification target.
5054
* <kbd>⌃⏎</kbd>: Mark the notification as done.
5155
- Additionally, you can press the
52-
[hotkey](https://www.alfredapp.com/help/workflows/triggers/hotkey/) to clone a
53-
GitHub repo from the current browser tab. ([Note that Firefox is not
56+
[hotkey](https://www.alfredapp.com/help/workflows/triggers/hotkey/) to clone
57+
a GitHub repo from the current browser tab. ([Note that Firefox is not
5458
supported.](https://www.alfredforum.com/topic/16748-how-to-do-x-in-firefox-from-alfred/))
5559

5660
## GitHub Token

info.plist

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/public-github-repo-search.js

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function run(argv) {
6666
}
6767

6868
// DOCS https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-repositories
69-
const apiUrl = `https://api.github.com/search/repositories?q=${encodeURIComponent(query)}`;
69+
const apiUrl = "https://api.github.com/search/repositories?q=" + encodeURIComponent(query);
7070
const response = httpRequest(apiUrl);
7171
if (!response) {
7272
return JSON.stringify({
@@ -81,45 +81,50 @@ function run(argv) {
8181
const shallowClone = cloneDepth > 0;
8282

8383
/** @type {AlfredItem[]} */
84-
const repos = JSON.parse(response)
85-
.items.filter((/** @type {GithubRepo} */ repo) => !(repo.fork || repo.archived))
86-
.map((/** @type {GithubRepo} */ repo) => {
87-
// calculate relative date
88-
// INFO pushed_at refers to commits only https://github.com/orgs/community/discussions/24442
89-
// CAVEAT pushed_at apparently also includes pushes via PR :(
90-
const lastUpdated = repo.pushed_at ? humanRelativeDate(repo.pushed_at) : "";
91-
92-
const subtitle = [
93-
repo.owner.login,
94-
"★ " + shortNumber(repo.stargazers_count),
95-
lastUpdated,
96-
repo.description,
97-
]
98-
.filter(Boolean)
99-
.join(" · ");
100-
101-
let cloneSubtitle = shallowClone ? `⌃: Shallow Clone (depth ${cloneDepth})` : "⌃: Clone";
102-
if (forkOnClone) cloneSubtitle += " & Fork";
103-
104-
const secondUrl = repo.homepage || repo.html_url + "/releases";
105-
106-
return {
107-
title: repo.name,
108-
subtitle: subtitle,
109-
match: alfredMatcher(repo.name),
110-
arg: repo.html_url,
111-
quicklookurl: repo.html_url,
112-
mods: {
113-
cmd: {
114-
arg: secondUrl,
115-
subtitle: `⌘: Open "${secondUrl}"`,
116-
},
117-
ctrl: {
118-
subtitle: cloneSubtitle,
119-
},
84+
const repos = JSON.parse(response).items.map((/** @type {GithubRepo} */ repo) => {
85+
// calculate relative date
86+
// INFO pushed_at refers to commits only https://github.com/orgs/community/discussions/24442
87+
// CAVEAT pushed_at apparently also includes pushes via PR :(
88+
const lastUpdated = repo.pushed_at ? humanRelativeDate(repo.pushed_at) : "";
89+
90+
let matcher = alfredMatcher(repo.name);
91+
let type = "";
92+
if (repo.fork) type += "🍴 ";
93+
if (repo.fork) matcher += "fork ";
94+
if (repo.archived) type += "🗄️ ";
95+
if (repo.archived) matcher += "archived ";
96+
97+
const subtitle = [
98+
repo.owner.login,
99+
"★ " + shortNumber(repo.stargazers_count),
100+
lastUpdated,
101+
repo.description,
102+
]
103+
.filter(Boolean)
104+
.join(" · ");
105+
106+
let cloneSubtitle = shallowClone ? `⌃: Shallow Clone (depth ${cloneDepth})` : "⌃: Clone";
107+
if (forkOnClone) cloneSubtitle += " & Fork";
108+
109+
const secondUrl = repo.homepage || repo.html_url + "/releases";
110+
111+
return {
112+
title: type + repo.name,
113+
subtitle: subtitle,
114+
match: matcher,
115+
arg: repo.html_url,
116+
quicklookurl: repo.html_url,
117+
mods: {
118+
cmd: {
119+
arg: secondUrl,
120+
subtitle: `⌘: Open "${secondUrl}"`,
120121
},
121-
};
122-
});
122+
ctrl: {
123+
subtitle: cloneSubtitle,
124+
},
125+
},
126+
};
127+
});
123128

124129
// GUARD no results
125130
if (repos.length === 0) {

0 commit comments

Comments
 (0)