Skip to content

Commit ae6f1ea

Browse files
Jason-Abbottchrisgrieser
authored andcommitted
feat: include issues on private repos when using github token (#17)
1 parent 30ed562 commit ae6f1ea

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Helpful GitHub assistant for Alfred.
3333
- Open recent GitHub issues you are involved in with `ghi`.
3434
+ <kbd>⏎</kbd>: Open the issue in the browser.
3535
+ <kbd>⌥⏎</kbd>: Copy the issue URL.
36+
+ To include issues in private repos, requires [GitHub
37+
Token](https://github.com/settings/tokens).
3638
- Access PRs you have opened with the keyword `gpr`.
3739
+ <kbd>⏎</kbd>: Open the PR in the browser.
3840
+ <kbd>⌥⏎</kbd>: Copy the link to the PR.

info.plist

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

scripts/my-github-issues.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,40 @@ function alfredMatcher(str) {
1111
return [clean, camelCaseSeparated, str].join(" ");
1212
}
1313

14-
/** @param {string} url @return {string} */
15-
function httpRequest(url) {
16-
const queryUrl = $.NSURL.URLWithString(url);
17-
const data = $.NSData.dataWithContentsOfURL(queryUrl);
18-
return $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding).js;
14+
/**
15+
* @param {string} url
16+
* @param {string[]} header
17+
* @return {string} response
18+
*/
19+
function httpRequestWithHeaders(url, header) {
20+
let allHeaders = "";
21+
for (const line of header) {
22+
allHeaders += ` -H "${line}"`;
23+
}
24+
const curlRequest = `curl --silent --location ${allHeaders} "${url}" || true`;
25+
console.log("curl command:", curlRequest);
26+
return app.doShellScript(curlRequest);
1927
}
2028

2129
//──────────────────────────────────────────────────────────────────────────────
2230

2331
// biome-ignore lint/correctness/noUnusedVariables: alfred_run
2432
function run() {
33+
// get GITHUB_TOKEN
34+
const tokenShellCmd = $.getenv("github_token_shell_cmd").trim();
35+
const tokenFromZshenvCmd = "test -e $HOME/.zshenv && source $HOME/.zshenv ; echo $GITHUB_TOKEN";
36+
let githubToken = $.getenv("github_token_from_alfred_prefs").trim();
37+
if (!githubToken && tokenShellCmd) githubToken = app.doShellScript(tokenShellCmd).trim();
38+
if (!githubToken) githubToken = app.doShellScript(tokenFromZshenvCmd);
39+
2540
const username = $.getenv("github_username");
2641

2742
// DOCS https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-issues-assigned-to-the-authenticated-user--parameters
2843
const apiUrl = `https://api.github.com/search/issues?q=involves:${username}&sort=updated&per_page=100`;
29-
const response = httpRequest(apiUrl);
44+
const headers = ["Accept: application/vnd.github.json", "X-GitHub-Api-Version: 2022-11-28"];
45+
if (githubToken) headers.push(`Authorization: BEARER ${githubToken}`);
46+
47+
const response = httpRequestWithHeaders(apiUrl, headers);
3048
if (!response) {
3149
return JSON.stringify({
3250
items: [{ title: "No response from GitHub.", subtitle: "Try again later.", valid: false }],

0 commit comments

Comments
 (0)