@@ -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
2432function 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