<commit_before>'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var GitHubLB=function(){function GitHubLB(){_classCallCheck(this,GitHubLB);var handle=Action.preferences.viewerHandle||'';this.defaultMenuItems=[{title:'My Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:handle,actionReturnsItems:true},{title:'My Open Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:handle,actionReturnsItems:true},{title:'My Open Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:handle,actionReturnsItems:true},{title:'My Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:handle,actionReturnsItems:true},{title:'Settings',icon:'gearTemplate.png',action:'openSettingsMenu',actionReturnsItems:true}];}_createClass(GitHubLB,[{key:'run',value:function run(input,options){if(input.length>0){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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^([\w-\.]+)\/([\w-\.]+)#(\d+)?\s*([\w-]+)?$/;var REPOSITORY_FORMAT=/^([\w-\.]+)\/([\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
// rails/rails/issues/123
// rails/rails/pull/123
else if(match=input.match(ISSUE_OR_PR_FORMAT)){var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);var issue=new Issue(repository,match[3]);return this.openIssueMenu(issue,match[4]);}// Matching:
// rails/rails
else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);return this.openRepositoriesMenu(_owner,match[2]);}// Matching:
// 911a93ac
// 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){if(LaunchBar.options.commandKey==1){var repository=new Repository(account,selection);LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{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;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Account=function(){function Account(login){_classCallCheck(this,Account);this.login=login;}_createClass(Account,[{key:'repositories',value:function repositories(){var _this=this;var cacheKey='account-repositories-for-'+this.login;var repositoryEdges=Cache.fetch(cacheKey,3600,function(){return _this._fetchRepositories();});return repositoryEdges.map(function(edge){var repo=edge.node;var owner=new Account(repo.owner.login);var parent=void 0;if(repo.parent){parent=new Repository(repo.parent.owner,repo.parent.name,repo.parent.description);}return new Repository(owner,repo.name,repo.description,parent);});}},{key:'pullRequests',value:function pullRequests(){var _this2=this;var cacheKey='account-pull-requests-for-'+this.login;var pullRequestEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            pullRequests(first: 100, states: [OPEN], orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  title\n                  number\n                  repository {\n                    name\n                    owner {\n                      login\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this2.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.pullRequests.edges;}else{return[];}}else{return[];}});return pullRequestEdges.map(function(edge){var pullRequest=edge.node;var number=pullRequest.number;var title=pullRequest.title;var owner=new Account(pullRequest.repository.owner.login);var repo=new Repository(owner,pullRequest.repository.name);return new PullRequest(repo,number,title);});}},{key:'issues',value:function issues(){var _this3=this;var cacheKey='account-issues-for-'+this.login;var issueEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            issues(first: 100, states: [OPEN], orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  title\n                  number\n                  repository {\n                    name\n                    owner {\n                      login\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this3.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.issues.edges;}else{return[];}}else{return[];}});return issueEdges.map(function(edge){var issue=edge.node;var number=issue.number;var title=issue.title;var owner=new Account(issue.repository.owner.login);var repo=new Repository(owner,issue.repository.name);return new Issue(repo,number,title);});}},{key:'gists',value:function gists(){var _this4=this;var cacheKey='account-gists-for-'+this.login;var gistEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            gists(first: 100, privacy: ALL, orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  name\n                  description\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this4.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.gists.edges;}else{return[];}}else{return[];}});return gistEdges.map(function(edge){var gist=edge.node;var name=gist.name;var description=gist.description;return new Gist(name,description);});}},{key:'_fetchRepositories',value:function _fetchRepositories(cursor,allEdges){allEdges=allEdges||[];var query='\n      query($login: String!, $cursor: String) {\n        repositoryOwner(login: $login) {\n          repositories(first: 100, after: $cursor, affiliations: [OWNER], orderBy: {field: PUSHED_AT, direction: DESC}) {\n            edges {\n              cursor\n              node {\n                ...RepositoryInfo\n                parent {\n                  ...RepositoryInfo\n                }\n              }\n            }\n          }\n        }\n      }\n\n      fragment RepositoryInfo on Repository {\n        name\n        description\n        owner {\n          login\n        }\n      }\n    ';var variables={login:this.login,cursor:cursor};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.repositoryOwner){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[];}}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(currentTime<cacheData.expiresAt){LaunchBar.debugLog('action=launchbar-github cache=hit cachePath='+path);return cacheData.results;}else{LaunchBar.debugLog('action=launchbar-github cache=stale expiresAt='+cacheData.expiresAt+' currentTime='+currentTime);return false;}}else{LaunchBar.debugLog('action=launchbar-github cache=miss');return false;}};Cache.write=function(key,ttl,func){var path=Cache.filePath(key);var currentTime=Math.floor(new Date()/1000);var expiresAt=currentTime+ttl;var results=func();function writeFile(){var cacheData={expiresAt:expiresAt,results:results};File.writeJSON(cacheData,path,{'prettyPrint':Action.debugLogEnabled});}// Only write to the file if the array or object is not empty
if(results instanceof Array&&results.length>0){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;}
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Commit=function(){function Commit(sha){_classCallCheck(this,Commit);this.sha=sha;}_createClass(Commit,[{key:'pullRequests',value:function pullRequests(){var _this=this;var cacheKey='commit-pull-requests-for-'+this.sha;var pullRequestEdges=Cache.fetch(cacheKey,604800,function(){return _this._fetchPullRequests();});return pullRequestEdges.map(function(edge){var pr=edge.node;var owner=new Account(pr.repository.owner.login);var repository=new Repository(owner,pr.repository.name);return new PullRequest(repository,pr.number,pr.title);},this);}},{key:'_fetchPullRequests',value:function _fetchPullRequests(){var query='\n      query($sha: String!) {\n        search(query:$sha, type:ISSUE, last:100) {\n          edges {\n            node {\n              ... on PullRequest {\n                title\n                number\n                repository {\n                  name\n                  owner {\n                    login\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    ';var variables={sha:this.sha};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.search){return result.data.search.edges;}else{return[];}}else{return[];}}},{key:'searchURL',get:function get(){return'https://github.com/search?q='+this.sha+'&type=Commits&utf8=%E2%9C%93';}}]);return Commit;}();if(typeof module!=='undefined'){module.exports.Commit=Commit;}
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var GitHubLB=function(){function GitHubLB(){_classCallCheck(this,GitHubLB);var handle=Action.preferences.viewerHandle||'';this.defaultMenuItems=[{title:'My Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:handle,actionReturnsItems:true},{title:'My Open Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:handle,actionReturnsItems:true},{title:'My Open Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:handle,actionReturnsItems:true},{title:'My Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:handle,actionReturnsItems:true},{title:'Settings',icon:'gearTemplate.png',action:'openSettingsMenu',actionReturnsItems:true}];}_createClass(GitHubLB,[{key:'run',value:function run(input,options){if(input.length>0){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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^([\w-\.]+)\/([\w-\.]+)#(\d+)?\s*([\w-]+)?$/;var REPOSITORY_FORMAT=/^([\w-\.]+)\/([\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
// rails/rails/issues/123
// rails/rails/pull/123
else if(match=input.match(ISSUE_OR_PR_FORMAT)){var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);var issue=new Issue(repository,match[3]);return this.openIssueMenu(issue,match[4]);}// Matching:
// rails/rails
else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);return this.openRepositoriesMenu(_owner,match[2]);}// Matching:
// 911a93ac
// 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){if(LaunchBar.options.commandKey==1){var repository=new Repository(account,selection);LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{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<commit_msg>Regenerate bundle.min.js with latest Babel<commit_after>'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var GitHubLB=function(){function GitHubLB(){_classCallCheck(this,GitHubLB);var handle=Action.preferences.viewerHandle||'';this.defaultMenuItems=[{title:'My Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:handle,actionReturnsItems:true},{title:'My Open Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:handle,actionReturnsItems:true},{title:'My Open Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:handle,actionReturnsItems:true},{title:'My Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:handle,actionReturnsItems:true},{title:'Settings',icon:'gearTemplate.png',action:'openSettingsMenu',actionReturnsItems:true}];}_createClass(GitHubLB,[{key:'run',value:function run(input,options){if(input.length>0){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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^([\w-\.]+)\/([\w-\.]+)#(\d+)?\s*([\w-]+)?$/;var REPOSITORY_FORMAT=/^([\w-\.]+)\/([\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
// rails/rails/issues/123
// rails/rails/pull/123
else if(match=input.match(ISSUE_OR_PR_FORMAT)){var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);var issue=new Issue(repository,match[3]);return this.openIssueMenu(issue,match[4]);}// Matching:
// rails/rails
else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);return this.openRepositoriesMenu(_owner,match[2]);}// Matching:
// 911a93ac
// 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){if(LaunchBar.options.commandKey==1){var repository=new Repository(account,selection);LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{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'//TODO
}];}}},{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;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Account=function(){function Account(login){_classCallCheck(this,Account);this.login=login;}_createClass(Account,[{key:'repositories',value:function repositories(){var _this=this;var cacheKey='account-repositories-for-'+this.login;var repositoryEdges=Cache.fetch(cacheKey,3600,function(){return _this._fetchRepositories();});return repositoryEdges.map(function(edge){var repo=edge.node;var owner=new Account(repo.owner.login);var parent=void 0;if(repo.parent){parent=new Repository(repo.parent.owner,repo.parent.name,repo.parent.description);}return new Repository(owner,repo.name,repo.description,parent);});}},{key:'pullRequests',value:function pullRequests(){var _this2=this;var cacheKey='account-pull-requests-for-'+this.login;var pullRequestEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            pullRequests(first: 100, states: [OPEN], orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  title\n                  number\n                  repository {\n                    name\n                    owner {\n                      login\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this2.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.pullRequests.edges;}else{return[];}}else{return[];}});return pullRequestEdges.map(function(edge){var pullRequest=edge.node;var number=pullRequest.number;var title=pullRequest.title;var owner=new Account(pullRequest.repository.owner.login);var repo=new Repository(owner,pullRequest.repository.name);return new PullRequest(repo,number,title);});}},{key:'issues',value:function issues(){var _this3=this;var cacheKey='account-issues-for-'+this.login;var issueEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            issues(first: 100, states: [OPEN], orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  title\n                  number\n                  repository {\n                    name\n                    owner {\n                      login\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this3.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.issues.edges;}else{return[];}}else{return[];}});return issueEdges.map(function(edge){var issue=edge.node;var number=issue.number;var title=issue.title;var owner=new Account(issue.repository.owner.login);var repo=new Repository(owner,issue.repository.name);return new Issue(repo,number,title);});}},{key:'gists',value:function gists(){var _this4=this;var cacheKey='account-gists-for-'+this.login;var gistEdges=Cache.fetch(cacheKey,600,function(){var query='\n        query($login: String!) {\n          user(login: $login) {\n            gists(first: 100, privacy: ALL, orderBy: {field: UPDATED_AT, direction: DESC}) {\n              edges {\n                node {\n                  name\n                  description\n                }\n              }\n            }\n          }\n        }\n      ';var variables={login:_this4.login};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.user){return result.data.user.gists.edges;}else{return[];}}else{return[];}});return gistEdges.map(function(edge){var gist=edge.node;var name=gist.name;var description=gist.description;return new Gist(name,description);});}},{key:'_fetchRepositories',value:function _fetchRepositories(cursor,allEdges){allEdges=allEdges||[];var query='\n      query($login: String!, $cursor: String) {\n        repositoryOwner(login: $login) {\n          repositories(first: 100, after: $cursor, affiliations: [OWNER], orderBy: {field: PUSHED_AT, direction: DESC}) {\n            edges {\n              cursor\n              node {\n                ...RepositoryInfo\n                parent {\n                  ...RepositoryInfo\n                }\n              }\n            }\n          }\n        }\n      }\n\n      fragment RepositoryInfo on Repository {\n        name\n        description\n        owner {\n          login\n        }\n      }\n    ';var variables={login:this.login,cursor:cursor};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.repositoryOwner){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[];}}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(currentTime<cacheData.expiresAt){LaunchBar.debugLog('action=launchbar-github cache=hit cachePath='+path);return cacheData.results;}else{LaunchBar.debugLog('action=launchbar-github cache=stale expiresAt='+cacheData.expiresAt+' currentTime='+currentTime);return false;}}else{LaunchBar.debugLog('action=launchbar-github cache=miss');return false;}};Cache.write=function(key,ttl,func){var path=Cache.filePath(key);var currentTime=Math.floor(new Date()/1000);var expiresAt=currentTime+ttl;var results=func();function writeFile(){var cacheData={expiresAt:expiresAt,results:results};File.writeJSON(cacheData,path,{'prettyPrint':Action.debugLogEnabled});}// Only write to the file if the array or object is not empty
if(results instanceof Array&&results.length>0){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;}
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var Commit=function(){function Commit(sha){_classCallCheck(this,Commit);this.sha=sha;}_createClass(Commit,[{key:'pullRequests',value:function pullRequests(){var _this=this;var cacheKey='commit-pull-requests-for-'+this.sha;var pullRequestEdges=Cache.fetch(cacheKey,604800,function(){return _this._fetchPullRequests();});return pullRequestEdges.map(function(edge){var pr=edge.node;var owner=new Account(pr.repository.owner.login);var repository=new Repository(owner,pr.repository.name);return new PullRequest(repository,pr.number,pr.title);},this);}},{key:'_fetchPullRequests',value:function _fetchPullRequests(){var query='\n      query($sha: String!) {\n        search(query:$sha, type:ISSUE, last:100) {\n          edges {\n            node {\n              ... on PullRequest {\n                title\n                number\n                repository {\n                  name\n                  owner {\n                    login\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    ';var variables={sha:this.sha};var result=GraphQL.execute(query,variables);if(result){if(result.data&&result.data.search){return result.data.search.edges;}else{return[];}}else{return[];}}},{key:'searchURL',get:function get(){return'https://github.com/search?q='+this.sha+'&type=Commits&utf8=%E2%9C%93';}}]);return Commit;}();if(typeof module!=='undefined'){module.exports.Commit=Commit;}
'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var GitHubLB=function(){function GitHubLB(){_classCallCheck(this,GitHubLB);var handle=Action.preferences.viewerHandle||'';this.defaultMenuItems=[{title:'My Repositories',icon:'repoTemplate.png',action:'openAccountRepositories',actionArgument:handle,actionReturnsItems:true},{title:'My Open Issues',icon:'issueTemplate.png',action:'openAccountIssues',actionArgument:handle,actionReturnsItems:true},{title:'My Open Pull Requests',icon:'pullRequestTemplate.png',action:'openAccountPullRequests',actionArgument:handle,actionReturnsItems:true},{title:'My Gists',icon:'gistTemplate.png',action:'openAccountGists',actionArgument:handle,actionReturnsItems:true},{title:'Settings',icon:'gearTemplate.png',action:'openSettingsMenu',actionReturnsItems:true}];}_createClass(GitHubLB,[{key:'run',value:function run(input,options){if(input.length>0){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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^([\w-\.]+)\/([\w-\.]+)#(\d+)?\s*([\w-]+)?$/;var REPOSITORY_FORMAT=/^([\w-\.]+)\/([\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
// rails/rails/issues/123
// rails/rails/pull/123
else if(match=input.match(ISSUE_OR_PR_FORMAT)){var owner=new Account(match[1]);var repository=new Repository(owner,match[2]);var issue=new Issue(repository,match[3]);return this.openIssueMenu(issue,match[4]);}// Matching:
// rails/rails
else if(match=input.match(REPOSITORY_FORMAT)){var _owner=new Account(match[1]);return this.openRepositoriesMenu(_owner,match[2]);}// Matching:
// 911a93ac
// 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){if(LaunchBar.options.commandKey==1){var repository=new Repository(account,selection);LaunchBar.openURL(repository.url);LaunchBar.executeAppleScript('tell application "LaunchBar" to hide');}else{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'//TODO
}];}}},{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
{'fraction_non_alphanumeric': 0.1661334316255068, 'fraction_numerical': 0.006310357537781054, 'mean_word_length': 9.642711438882786, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 42, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3284438', 'n_tokens_mistral': 19704, 'n_tokens_neox': 19053, 'n_words': 2037}