From c2e474f853f2f50365594e5e638b85fcbf1479d3 Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Wed, 26 Jul 2017 18:58:15 -0400 Subject: [PATCH] Add support for viewing Gists of other users As well as fix a bug with Gist support pointing to `viewer` and not `user`. --- Contents/Scripts/account.js | 4 ++-- Contents/Scripts/bundle.min.js | 6 +++--- Contents/Scripts/default.js | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Contents/Scripts/account.js b/Contents/Scripts/account.js index e0d288a..7a5ac55 100644 --- a/Contents/Scripts/account.js +++ b/Contents/Scripts/account.js @@ -172,8 +172,8 @@ class Account { let result = GraphQL.execute(query, variables); if (result) { - if (result.data && result.data.viewer) { - return result.data.viewer.gists.edges; + if (result.data && result.data.user) { + return result.data.user.gists.edges; } else { return []; } diff --git a/Contents/Scripts/bundle.min.js b/Contents/Scripts/bundle.min.js index e5faf43..9350967 100644 --- a/Contents/Scripts/bundle.min.js +++ b/Contents/Scripts/bundle.min.js @@ -11,13 +11,13 @@ else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);r // 911a93ac26c4f5919d1ebdf67a9e3db31c5b9dce else if(match=input.match(COMMIT_SHA_FORMAT)){var commit=new Commit(match[0]);return this.openCommitPullRequestsMenu(commit);}// Matching: // rails -else if(match=input.match(ACCOUNT_FORMAT)){var account=new Account(match[1]);return this.openAccountMenu(account,match[2]);}}},{key:'openSettingsMenu',value:function openSettingsMenu(input){return[{title:'Set GitHub access token from clipboard',icon:'keyTemplate.png',action:'setToken',actionArgument:LaunchBar.getClipboardString()}];}},{key:'openLinkShortnerMenu',value:function openLinkShortnerMenu(link,options){if(LaunchBar.options.commandKey==1){this.shortenLink(link);}else{return[{title:'Shorten link',icon:'linkTemplate.png',action:'shortenLink',actionArgument:link}];}}},{key:'openIssueMenu',value:function openIssueMenu(issue){if(issue.number){var fetchedIssue=Issue.fetch(issue.repository,issue.number);return[fetchedIssue.toMenuItem()];}else{return[];}}},{key:'openRepositoriesMenu',value:function openRepositoriesMenu(account,selection){var repositories=account.repositories();if(selection){repositories=repositories.filter(function(repository){var regex=new RegExp(selection,'i');return repository.name.match(regex);});}return repositories.map(function(repository){var menuItem=repository.toMenuItem();delete menuItem.url;menuItem.action='openRepositoryMenu';menuItem.actionArgument=repository.nameWithOwner;menuItem.actionReturnsItems=true;return menuItem;});}},{key:'openRepositoryMenu',value:function openRepositoryMenu(repository,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var repositoryMenuItems=[{title:'View Repository',subtitle:repository.nameWithOwner,alwaysShowsSubtitle:true,icon:'repoTemplate.png',url:repository.url},{title:'View Issues',icon:'issueTemplate.png',action:'openRepositoryIssues',actionArgument:repository.nameWithOwner,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openRepositoryPullRequests',actionArgument:repository.nameWithOwner,actionReturnsItems:true}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{key:'openRepositoryPullRequests',value:function openRepositoryPullRequests(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.pullRequestsURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}].concat(repository.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openRepositoryIssues',value:function openRepositoryIssues(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.issuesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:repository.issuesURL}].concat(repository.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openCommitPullRequestsMenu',value:function openCommitPullRequestsMenu(commit){var pullRequests=commit.pullRequests();if(pullRequests.length>1){return pullRequests.map(function(pr){return pr.toMenuItem();});}else if(pullRequests.length===1){return[pullRequests[0].toMenuItem()];}else{return[{title:'Search for commit: '+commit.sha,url:commit.searchURL,icon:'commitTemplate.png'}];}}},{key:'openAccountMenu',value:function openAccountMenu(account,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.profileURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var accountMenuItems=[{title:'View Profile',subtitle:account.handle,alwaysShowsSubtitle:true,icon:'personTemplate.png',url:account.profileURL},{title:'View Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:account.login,actionReturnsItems:true},{title:'View Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:account.login,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:account.login,actionReturnsItems:true},{title:'View Gists',icon:'gistTemplate.png',url:account.gistsURL}];if(secondarySelection){return accountMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return accountMenuItems;}}}},{key:'openAccountRepositoriesMenu',value:function openAccountRepositoriesMenu(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.repositoriesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Repositories',icon:'reposTemplate.png',url:account.repositoriesURL}].concat(account.repositories().map(function(repository){return repository.toMenuItem();}));}}},{key:'openAccountPullRequests',value:function openAccountPullRequests(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/pulls');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:'https://github.com/pulls'}].concat(account.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openAccountIssues',value:function openAccountIssues(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/issues');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:'https://github.com/issues'}].concat(account.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openAccountGists',value:function openAccountGists(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://gist.github.com');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Gists',icon:'gistTemplate.png',url:'https://gist.github.com'}].concat(account.gists().map(function(gist){return gist.toMenuItem();}));}}},{key:'shortenLink',value:function shortenLink(link){var linkShortener=new LinkShortener(link);var shortLink=linkShortener.run();LaunchBar.setClipboardString(shortLink);LaunchBar.displayNotification({title:'Copied '+shortLink+' to your clipboard'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}},{key:'setToken',value:function setToken(token){Action.preferences.token=token;var result=GraphQL.execute('query { viewer { login } }');if(result.data){var handle=result.data.viewer.login;Action.preferences.viewerHandle=handle;LaunchBar.displayNotification({title:'👋 Hi @'+handle,string:'Your access token was set successfully.'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{LaunchBar.displayNotification({title:'That looks like an invalid token',string:'Please try again by going back to settings.'});}}}]);return GitHubLB;}();GitHubLB.VERSION='v'+Action.version+'-'+LaunchBar.version;var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){if(details.path.endsWith('setToken')){return app.setToken(details.queryParameters.token);}else{return app.run(url,details);}}// Unfortunately when the script output uses an action argument (like +else if(match=input.match(ACCOUNT_FORMAT)){var account=new Account(match[1]);return this.openAccountMenu(account,match[2]);}}},{key:'openSettingsMenu',value:function openSettingsMenu(input){return[{title:'Set GitHub access token from clipboard',icon:'keyTemplate.png',action:'setToken',actionArgument:LaunchBar.getClipboardString()}];}},{key:'openLinkShortnerMenu',value:function openLinkShortnerMenu(link,options){if(LaunchBar.options.commandKey==1){this.shortenLink(link);}else{return[{title:'Shorten link',icon:'linkTemplate.png',action:'shortenLink',actionArgument:link}];}}},{key:'openIssueMenu',value:function openIssueMenu(issue){if(issue.number){var fetchedIssue=Issue.fetch(issue.repository,issue.number);return[fetchedIssue.toMenuItem()];}else{return[];}}},{key:'openRepositoriesMenu',value:function openRepositoriesMenu(account,selection){var repositories=account.repositories();if(selection){repositories=repositories.filter(function(repository){var regex=new RegExp(selection,'i');return repository.name.match(regex);});}return repositories.map(function(repository){var menuItem=repository.toMenuItem();delete menuItem.url;menuItem.action='openRepositoryMenu';menuItem.actionArgument=repository.nameWithOwner;menuItem.actionReturnsItems=true;return menuItem;});}},{key:'openRepositoryMenu',value:function openRepositoryMenu(repository,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var repositoryMenuItems=[{title:'View Repository',subtitle:repository.nameWithOwner,alwaysShowsSubtitle:true,icon:'repoTemplate.png',url:repository.url},{title:'View Issues',icon:'issueTemplate.png',action:'openRepositoryIssues',actionArgument:repository.nameWithOwner,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openRepositoryPullRequests',actionArgument:repository.nameWithOwner,actionReturnsItems:true}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{key:'openRepositoryPullRequests',value:function openRepositoryPullRequests(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.pullRequestsURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}].concat(repository.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openRepositoryIssues',value:function openRepositoryIssues(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.issuesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:repository.issuesURL}].concat(repository.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openCommitPullRequestsMenu',value:function openCommitPullRequestsMenu(commit){var pullRequests=commit.pullRequests();if(pullRequests.length>1){return pullRequests.map(function(pr){return pr.toMenuItem();});}else if(pullRequests.length===1){return[pullRequests[0].toMenuItem()];}else{return[{title:'Search for commit: '+commit.sha,url:commit.searchURL,icon:'commitTemplate.png'}];}}},{key:'openAccountMenu',value:function openAccountMenu(account,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.profileURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var accountMenuItems=[{title:'View Profile',subtitle:account.handle,alwaysShowsSubtitle:true,icon:'personTemplate.png',url:account.profileURL},{title:'View Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:account.login,actionReturnsItems:true},{title:'View Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:account.login,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:account.login,actionReturnsItems:true},{title:'View Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:account.login,actionReturnsItems:true}];if(secondarySelection){return accountMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return accountMenuItems;}}}},{key:'openAccountRepositoriesMenu',value:function openAccountRepositoriesMenu(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.repositoriesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Repositories',icon:'reposTemplate.png',url:account.repositoriesURL}].concat(account.repositories().map(function(repository){return repository.toMenuItem();}));}}},{key:'openAccountPullRequests',value:function openAccountPullRequests(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/pulls');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:'https://github.com/pulls'}].concat(account.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openAccountIssues',value:function openAccountIssues(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/issues');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:'https://github.com/issues'}].concat(account.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openAccountGists',value:function openAccountGists(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://gist.github.com');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Gists',icon:'gistTemplate.png',url:'https://gist.github.com'}].concat(account.gists().map(function(gist){return gist.toMenuItem();}));}}},{key:'shortenLink',value:function shortenLink(link){var linkShortener=new LinkShortener(link);var shortLink=linkShortener.run();LaunchBar.setClipboardString(shortLink);LaunchBar.displayNotification({title:'Copied '+shortLink+' to your clipboard'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}},{key:'setToken',value:function setToken(token){Action.preferences.token=token;var result=GraphQL.execute('query { viewer { login } }');if(result.data){var handle=result.data.viewer.login;Action.preferences.viewerHandle=handle;LaunchBar.displayNotification({title:'👋 Hi @'+handle,string:'Your access token was set successfully.'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{LaunchBar.displayNotification({title:'That looks like an invalid token',string:'Please try again by going back to settings.'});}}}]);return GitHubLB;}();GitHubLB.VERSION='v'+Action.version+'-'+LaunchBar.version;var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){if(details.path.endsWith('setToken')){return app.setToken(details.queryParameters.token);}else{return app.run(url,details);}}// Unfortunately when the script output uses an action argument (like // openAccount does), it needs to be able to find the function from the global // scope. The following functions are workarounds to the appropriate actions. // // https://developer.obdev.at/launchbar-developer-documentation/#/script-output. function openAccountRepositories(string){return app.openAccountRepositoriesMenu(string);}function openAccountPullRequests(string){return app.openAccountPullRequests(string);}function openAccountIssues(string){return app.openAccountIssues(string);}function openAccountGists(string){return app.openAccountGists(string);}function openAccountMenu(string){return app.openAccountMenu(string);}function shortenLink(link,details){return app.shortenLink(link);}function openSettingsMenu(){return app.openSettingsMenu();}function setToken(token){return app.setToken(token);}function openRepositoryMenu(nameWithOwner){var match=nameWithOwner.match(/^(.*)\/(.*)$/);var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);return app.openRepositoryMenu(repository);}function openRepositoryPullRequests(nameWithOwner){var match=nameWithOwner.match(/^(.*)\/(.*)$/);var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);return app.openRepositoryPullRequests(repository);}function openRepositoryIssues(nameWithOwner){var match=nameWithOwner.match(/^(.*)\/(.*)$/);var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);return app.openRepositoryIssues(repository);} -'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){allEdges=allEdges.concat(repositoryEdges);var lastEdge=repositoryEdges[repositoryEdges.length-1];return this._fetchRepositories(lastEdge.cursor,allEdges);}}else{return[];}}else{return[];}return allEdges;}},{key:'handle',get:function get(){return'@'+this.login;}},{key:'profileURL',get:function get(){return'https://github.com/'+this.login;}},{key:'repositoriesURL',get:function get(){return'https://github.com/'+this.login+'?tab=repositories';}},{key:'issuesURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Aissue&ref=simplesearch';}},{key:'pullRequestsURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Apr&ref=simplesearch';}},{key:'gistsURL',get:function get(){return'https://gist.github.com/'+this.login;}}]);return Account;}();if(typeof module!=='undefined'){module.exports.Account=Account;} +'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){allEdges=allEdges.concat(repositoryEdges);var lastEdge=repositoryEdges[repositoryEdges.length-1];return this._fetchRepositories(lastEdge.cursor,allEdges);}}else{return[];}}else{return[];}return allEdges;}},{key:'handle',get:function get(){return'@'+this.login;}},{key:'profileURL',get:function get(){return'https://github.com/'+this.login;}},{key:'repositoriesURL',get:function get(){return'https://github.com/'+this.login+'?tab=repositories';}},{key:'issuesURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Aissue&ref=simplesearch';}},{key:'pullRequestsURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Apr&ref=simplesearch';}},{key:'gistsURL',get:function get(){return'https://gist.github.com/'+this.login;}}]);return Account;}();if(typeof module!=='undefined'){module.exports.Account=Account;} 'use strict';function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}// The cache lives at ~/Library/Caches/at.obdev.LaunchBar/Actions/ var Cache=function Cache(){_classCallCheck(this,Cache);};Cache.fetch=function(key,ttl,func){var results=Cache.read(key);if(results){return results;}else{return Cache.write(key,ttl,func);}};Cache.read=function(key){var path=Cache.filePath(key);if(File.exists(path)){var cacheData=File.readJSON(path);var currentTime=Math.floor(new Date()/1000);if(currentTime0){writeFile.call(this);}else if(Object.keys(results).length>0&&results.constructor===Object){writeFile.call(this);}return results;};Cache.filePath=function(key){return Action.cachePath+'/'+Action.version+'-'+key+'.json';};if(typeof module!=='undefined'){module.exports.Cache=Cache;} @@ -35,7 +35,7 @@ else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);r // 911a93ac26c4f5919d1ebdf67a9e3db31c5b9dce else if(match=input.match(COMMIT_SHA_FORMAT)){var commit=new Commit(match[0]);return this.openCommitPullRequestsMenu(commit);}// Matching: // rails -else if(match=input.match(ACCOUNT_FORMAT)){var account=new Account(match[1]);return this.openAccountMenu(account,match[2]);}}},{key:'openSettingsMenu',value:function openSettingsMenu(input){return[{title:'Set GitHub access token from clipboard',icon:'keyTemplate.png',action:'setToken',actionArgument:LaunchBar.getClipboardString()}];}},{key:'openLinkShortnerMenu',value:function openLinkShortnerMenu(link,options){if(LaunchBar.options.commandKey==1){this.shortenLink(link);}else{return[{title:'Shorten link',icon:'linkTemplate.png',action:'shortenLink',actionArgument:link}];}}},{key:'openIssueMenu',value:function openIssueMenu(issue){if(issue.number){var fetchedIssue=Issue.fetch(issue.repository,issue.number);return[fetchedIssue.toMenuItem()];}else{return[];}}},{key:'openRepositoriesMenu',value:function openRepositoriesMenu(account,selection){var repositories=account.repositories();if(selection){repositories=repositories.filter(function(repository){var regex=new RegExp(selection,'i');return repository.name.match(regex);});}return repositories.map(function(repository){var menuItem=repository.toMenuItem();delete menuItem.url;menuItem.action='openRepositoryMenu';menuItem.actionArgument=repository.nameWithOwner;menuItem.actionReturnsItems=true;return menuItem;});}},{key:'openRepositoryMenu',value:function openRepositoryMenu(repository,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var repositoryMenuItems=[{title:'View Repository',subtitle:repository.nameWithOwner,alwaysShowsSubtitle:true,icon:'repoTemplate.png',url:repository.url},{title:'View Issues',icon:'issueTemplate.png',action:'openRepositoryIssues',actionArgument:repository.nameWithOwner,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openRepositoryPullRequests',actionArgument:repository.nameWithOwner,actionReturnsItems:true}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{key:'openRepositoryPullRequests',value:function openRepositoryPullRequests(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.pullRequestsURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}].concat(repository.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openRepositoryIssues',value:function openRepositoryIssues(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.issuesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:repository.issuesURL}].concat(repository.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openCommitPullRequestsMenu',value:function openCommitPullRequestsMenu(commit){var pullRequests=commit.pullRequests();if(pullRequests.length>1){return pullRequests.map(function(pr){return pr.toMenuItem();});}else if(pullRequests.length===1){return[pullRequests[0].toMenuItem()];}else{return[{title:'Search for commit: '+commit.sha,url:commit.searchURL,icon:'commitTemplate.png'}];}}},{key:'openAccountMenu',value:function openAccountMenu(account,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.profileURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var accountMenuItems=[{title:'View Profile',subtitle:account.handle,alwaysShowsSubtitle:true,icon:'personTemplate.png',url:account.profileURL},{title:'View Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:account.login,actionReturnsItems:true},{title:'View Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:account.login,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:account.login,actionReturnsItems:true},{title:'View Gists',icon:'gistTemplate.png',url:account.gistsURL}];if(secondarySelection){return accountMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return accountMenuItems;}}}},{key:'openAccountRepositoriesMenu',value:function openAccountRepositoriesMenu(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.repositoriesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Repositories',icon:'reposTemplate.png',url:account.repositoriesURL}].concat(account.repositories().map(function(repository){return repository.toMenuItem();}));}}},{key:'openAccountPullRequests',value:function openAccountPullRequests(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/pulls');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:'https://github.com/pulls'}].concat(account.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openAccountIssues',value:function openAccountIssues(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/issues');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:'https://github.com/issues'}].concat(account.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openAccountGists',value:function openAccountGists(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://gist.github.com');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Gists',icon:'gistTemplate.png',url:'https://gist.github.com'}].concat(account.gists().map(function(gist){return gist.toMenuItem();}));}}},{key:'shortenLink',value:function shortenLink(link){var linkShortener=new LinkShortener(link);var shortLink=linkShortener.run();LaunchBar.setClipboardString(shortLink);LaunchBar.displayNotification({title:'Copied '+shortLink+' to your clipboard'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}},{key:'setToken',value:function setToken(token){Action.preferences.token=token;var result=GraphQL.execute('query { viewer { login } }');if(result.data){var handle=result.data.viewer.login;Action.preferences.viewerHandle=handle;LaunchBar.displayNotification({title:'👋 Hi @'+handle,string:'Your access token was set successfully.'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{LaunchBar.displayNotification({title:'That looks like an invalid token',string:'Please try again by going back to settings.'});}}}]);return GitHubLB;}();GitHubLB.VERSION='v'+Action.version+'-'+LaunchBar.version;var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){if(details.path.endsWith('setToken')){return app.setToken(details.queryParameters.token);}else{return app.run(url,details);}}// Unfortunately when the script output uses an action argument (like +else if(match=input.match(ACCOUNT_FORMAT)){var account=new Account(match[1]);return this.openAccountMenu(account,match[2]);}}},{key:'openSettingsMenu',value:function openSettingsMenu(input){return[{title:'Set GitHub access token from clipboard',icon:'keyTemplate.png',action:'setToken',actionArgument:LaunchBar.getClipboardString()}];}},{key:'openLinkShortnerMenu',value:function openLinkShortnerMenu(link,options){if(LaunchBar.options.commandKey==1){this.shortenLink(link);}else{return[{title:'Shorten link',icon:'linkTemplate.png',action:'shortenLink',actionArgument:link}];}}},{key:'openIssueMenu',value:function openIssueMenu(issue){if(issue.number){var fetchedIssue=Issue.fetch(issue.repository,issue.number);return[fetchedIssue.toMenuItem()];}else{return[];}}},{key:'openRepositoriesMenu',value:function openRepositoriesMenu(account,selection){var repositories=account.repositories();if(selection){repositories=repositories.filter(function(repository){var regex=new RegExp(selection,'i');return repository.name.match(regex);});}return repositories.map(function(repository){var menuItem=repository.toMenuItem();delete menuItem.url;menuItem.action='openRepositoryMenu';menuItem.actionArgument=repository.nameWithOwner;menuItem.actionReturnsItems=true;return menuItem;});}},{key:'openRepositoryMenu',value:function openRepositoryMenu(repository,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var repositoryMenuItems=[{title:'View Repository',subtitle:repository.nameWithOwner,alwaysShowsSubtitle:true,icon:'repoTemplate.png',url:repository.url},{title:'View Issues',icon:'issueTemplate.png',action:'openRepositoryIssues',actionArgument:repository.nameWithOwner,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openRepositoryPullRequests',actionArgument:repository.nameWithOwner,actionReturnsItems:true}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{key:'openRepositoryPullRequests',value:function openRepositoryPullRequests(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.pullRequestsURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}].concat(repository.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openRepositoryIssues',value:function openRepositoryIssues(repository){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(repository.issuesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:repository.issuesURL}].concat(repository.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openCommitPullRequestsMenu',value:function openCommitPullRequestsMenu(commit){var pullRequests=commit.pullRequests();if(pullRequests.length>1){return pullRequests.map(function(pr){return pr.toMenuItem();});}else if(pullRequests.length===1){return[pullRequests[0].toMenuItem()];}else{return[{title:'Search for commit: '+commit.sha,url:commit.searchURL,icon:'commitTemplate.png'}];}}},{key:'openAccountMenu',value:function openAccountMenu(account,secondarySelection){if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.profileURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{var accountMenuItems=[{title:'View Profile',subtitle:account.handle,alwaysShowsSubtitle:true,icon:'personTemplate.png',url:account.profileURL},{title:'View Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:account.login,actionReturnsItems:true},{title:'View Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:account.login,actionReturnsItems:true},{title:'View Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:account.login,actionReturnsItems:true},{title:'View Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:account.login,actionReturnsItems:true}];if(secondarySelection){return accountMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return accountMenuItems;}}}},{key:'openAccountRepositoriesMenu',value:function openAccountRepositoriesMenu(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL(account.repositoriesURL);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Repositories',icon:'reposTemplate.png',url:account.repositoriesURL}].concat(account.repositories().map(function(repository){return repository.toMenuItem();}));}}},{key:'openAccountPullRequests',value:function openAccountPullRequests(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/pulls');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Pull Requests',icon:'pullRequestTemplate.png',url:'https://github.com/pulls'}].concat(account.pullRequests().map(function(pullRequest){return pullRequest.toMenuItem();}));}}},{key:'openAccountIssues',value:function openAccountIssues(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://github.com/issues');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Issues',icon:'issueTemplate.png',url:'https://github.com/issues'}].concat(account.issues().map(function(issue){return issue.toMenuItem();}));}}},{key:'openAccountGists',value:function openAccountGists(login){var account=new Account(login);if(LaunchBar.options.commandKey==1){LaunchBar.openURL('https://gist.github.com');LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{return[{title:'View All Gists',icon:'gistTemplate.png',url:'https://gist.github.com'}].concat(account.gists().map(function(gist){return gist.toMenuItem();}));}}},{key:'shortenLink',value:function shortenLink(link){var linkShortener=new LinkShortener(link);var shortLink=linkShortener.run();LaunchBar.setClipboardString(shortLink);LaunchBar.displayNotification({title:'Copied '+shortLink+' to your clipboard'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}},{key:'setToken',value:function setToken(token){Action.preferences.token=token;var result=GraphQL.execute('query { viewer { login } }');if(result.data){var handle=result.data.viewer.login;Action.preferences.viewerHandle=handle;LaunchBar.displayNotification({title:'👋 Hi @'+handle,string:'Your access token was set successfully.'});LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{LaunchBar.displayNotification({title:'That looks like an invalid token',string:'Please try again by going back to settings.'});}}}]);return GitHubLB;}();GitHubLB.VERSION='v'+Action.version+'-'+LaunchBar.version;var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){if(details.path.endsWith('setToken')){return app.setToken(details.queryParameters.token);}else{return app.run(url,details);}}// Unfortunately when the script output uses an action argument (like // openAccount does), it needs to be able to find the function from the global // scope. The following functions are workarounds to the appropriate actions. // diff --git a/Contents/Scripts/default.js b/Contents/Scripts/default.js index 50bfcc6..d0c3471 100644 --- a/Contents/Scripts/default.js +++ b/Contents/Scripts/default.js @@ -305,7 +305,9 @@ class GitHubLB { { title: 'View Gists', icon: 'gistTemplate.png', - url: account.gistsURL, + action: 'openAccountGists', + actionArgument: account.login, + actionReturnsItems: true, } ];