diff --git a/Contents/Scripts/bundle.min.js b/Contents/Scripts/bundle.min.js index acfbb05..c29d170 100644 --- a/Contents/Scripts/bundle.min.js +++ b/Contents/Scripts/bundle.min.js @@ -1,4 +1,4 @@ -'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){var matchedDefaultMenuItems=this.matchingDefaultMenuItems(input);if(matchedDefaultMenuItems.length>0){return matchedDefaultMenuItems.concat(this.conflictingHandleMenuItem(input));}else{return this.displayMenuItemFor(input);}}else{return this.defaultMenuItems;}}},{key:'matchingDefaultMenuItems',value:function matchingDefaultMenuItems(input){return this.defaultMenuItems.filter(function(item){var regex=new RegExp(input,'i');return item.title.match(regex);});}},{key:'conflictingHandleMenuItem',value:function conflictingHandleMenuItem(handle){return[{title:'@'+handle,subtitle:'Looking for the user @'+handle+'?',alwaysShowsSubtitle:true,icon:'personTemplate.png',action:'openAccountMenu',actionArgument:handle}];}},{key:'displayMenuItemFor',value:function displayMenuItemFor(input){var GITHUB_LINK_FORMAT=/^https?:\/\/((www|gist|raw)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/;var REPOSITORY_FORMAT=/^(\w+)\/(.*)?\s*(\w+)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(\w+)?\s*(\w+)?$/;var match=void 0;// Matching: +'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){var matchedDefaultMenuItems=this.matchingDefaultMenuItems(input);if(matchedDefaultMenuItems.length>0){return matchedDefaultMenuItems.concat(this.conflictingHandleMenuItem(input));}else{return this.displayMenuItemFor(input);}}else{return this.defaultMenuItems;}}},{key:'matchingDefaultMenuItems',value:function matchingDefaultMenuItems(input){return this.defaultMenuItems.filter(function(item){var regex=new RegExp(input,'i');return item.title.match(regex);});}},{key:'conflictingHandleMenuItem',value:function conflictingHandleMenuItem(handle){return[{title:'@'+handle,subtitle:'Looking for the user @'+handle+'?',alwaysShowsSubtitle:true,icon:'personTemplate.png',action:'openAccountMenu',actionArgument:handle}];}},{key:'displayMenuItemFor',value:function displayMenuItemFor(input){var GITHUB_LINK_FORMAT=/^https?:\/\/((www|gist|raw)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/;var REPOSITORY_FORMAT=/^(\w+)\/(.*)?\s*(\w+)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(\w+)?\s*(\w+)?$/;var match=void 0;// Matching: // https://github.com/bswinnerton/dotfiles/blob/master/ack/ackrc.symlink#L6 if(input.match(GITHUB_LINK_FORMAT)){return this.openLinkShortnerMenu(input);}// Matching: // rails/rails#123 @@ -11,7 +11,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){return[{title:'Open the issue: '+issue.repository.nameWithOwner+'#'+issue.number,icon:'issueTemplate.png',url:issue.url}];}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;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',url:repository.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{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',url:account.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:account.pullRequestsURL},{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:'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;}();var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){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){return[{title:'Open the issue: '+issue.repository.nameWithOwner+'#'+issue.number,icon:'issueTemplate.png',url:issue.url}];}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',url:repository.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{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',url:account.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:account.pullRequestsURL},{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:'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;}();var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){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. // @@ -21,7 +21,7 @@ function openAccountRepositories(string){return app.openAccountRepositoriesMenu( if(owner.login===this.login){var repository=new Repository(owner,repo.name,repo.description);repositories.push(repository);}return repositories;}.bind(this),[]);}},{key:'_fetchRepositories',value:function _fetchRepositories(cursor,allEdges){allEdges=allEdges||[];var query='\n query($login: String!, $cursor: String) {\n repositoryOwner(login: $login) {\n repositories(first: 30, after: $cursor, orderBy: {field: PUSHED_AT, direction: DESC}) {\n edges {\n cursor\n node {\n name\n description\n owner {\n login\n }\n }\n }\n }\n }\n }\n ';var variables={login:this.login,cursor:cursor};var result=GraphQL.execute(query,variables);if(result){var repositoryEdges=result.data.repositoryOwner.repositories.edges;if(repositoryEdges.length>0){allEdges=allEdges.concat(repositoryEdges);var lastEdge=repositoryEdges[repositoryEdges.length-1];return this._fetchRepositories(lastEdge.cursor,allEdges);}}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");}}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){var cacheData={expiresAt:expiresAt,results:results};File.writeJSON(cacheData,path,{'prettyPrint':Action.debugLogEnabled});}return results;};Cache.filePath=function(key){return Action.cachePath+'/'+'v2-'+key+'.json';};if(typeof module!=='undefined'){module.exports.Cache=Cache;} 'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){var matchedDefaultMenuItems=this.matchingDefaultMenuItems(input);if(matchedDefaultMenuItems.length>0){return matchedDefaultMenuItems.concat(this.conflictingHandleMenuItem(input));}else{return this.displayMenuItemFor(input);}}else{return this.defaultMenuItems;}}},{key:'matchingDefaultMenuItems',value:function matchingDefaultMenuItems(input){return this.defaultMenuItems.filter(function(item){var regex=new RegExp(input,'i');return item.title.match(regex);});}},{key:'conflictingHandleMenuItem',value:function conflictingHandleMenuItem(handle){return[{title:'@'+handle,subtitle:'Looking for the user @'+handle+'?',alwaysShowsSubtitle:true,icon:'personTemplate.png',action:'openAccountMenu',actionArgument:handle}];}},{key:'displayMenuItemFor',value:function displayMenuItemFor(input){var GITHUB_LINK_FORMAT=/^https?:\/\/((www|gist|raw)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/;var REPOSITORY_FORMAT=/^(\w+)\/(.*)?\s*(\w+)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(\w+)?\s*(\w+)?$/;var match=void 0;// Matching: +'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){var matchedDefaultMenuItems=this.matchingDefaultMenuItems(input);if(matchedDefaultMenuItems.length>0){return matchedDefaultMenuItems.concat(this.conflictingHandleMenuItem(input));}else{return this.displayMenuItemFor(input);}}else{return this.defaultMenuItems;}}},{key:'matchingDefaultMenuItems',value:function matchingDefaultMenuItems(input){return this.defaultMenuItems.filter(function(item){var regex=new RegExp(input,'i');return item.title.match(regex);});}},{key:'conflictingHandleMenuItem',value:function conflictingHandleMenuItem(handle){return[{title:'@'+handle,subtitle:'Looking for the user @'+handle+'?',alwaysShowsSubtitle:true,icon:'personTemplate.png',action:'openAccountMenu',actionArgument:handle}];}},{key:'displayMenuItemFor',value:function displayMenuItemFor(input){var GITHUB_LINK_FORMAT=/^https?:\/\/((www|gist|raw)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/;var REPOSITORY_FORMAT=/^(\w+)\/(.*)?\s*(\w+)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(\w+)?\s*(\w+)?$/;var match=void 0;// Matching: // https://github.com/bswinnerton/dotfiles/blob/master/ack/ackrc.symlink#L6 if(input.match(GITHUB_LINK_FORMAT)){return this.openLinkShortnerMenu(input);}// Matching: // rails/rails#123 @@ -34,7 +34,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){return[{title:'Open the issue: '+issue.repository.nameWithOwner+'#'+issue.number,icon:'issueTemplate.png',url:issue.url}];}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;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',url:repository.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{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',url:account.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:account.pullRequestsURL},{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:'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;}();var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){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){return[{title:'Open the issue: '+issue.repository.nameWithOwner+'#'+issue.number,icon:'issueTemplate.png',url:issue.url}];}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',url:repository.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:repository.pullRequestsURL}];if(secondarySelection){return repositoryMenuItems.filter(function(item){var regex=new RegExp(secondarySelection,'i');return item.title.match(regex);});}else{return repositoryMenuItems;}}}},{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',url:account.issuesURL},{title:'View Pull Requests',icon:'pullRequestTemplate.png',url:account.pullRequestsURL},{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:'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;}();var app=new GitHubLB();function run(argument){return app.run(argument);}function runWithString(string){return app.run(string);}function runWithURL(url,details){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 33db47b..a997d73 100644 --- a/Contents/Scripts/default.js +++ b/Contents/Scripts/default.js @@ -25,6 +25,7 @@ class GitHubLB { title: 'Settings', icon: 'gearTemplate.png', action: 'openSettingsMenu', + actionReturnsItems: true, } ]; } @@ -163,6 +164,7 @@ class GitHubLB { delete menuItem.url; menuItem.action = 'openRepositoryMenu'; menuItem.actionArgument = repository.nameWithOwner; + menuItem.actionReturnsItems = true; return menuItem; }); }