From 6098121c94457a1237009908f265bb924d6d1884 Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Fri, 10 Mar 2017 18:51:34 -0500 Subject: [PATCH 1/2] Use repository affiliation GraphQL argument The GitHub GraphQL API now includes a mechanism to choose which affiliations of the viewer's repositories that you'd like back. This means that we can remove some logic from the client and instead lean on the server to do that filtering for us - saving on requests and bandwidth. --- Contents/Scripts/account.js | 18 ++++++------------ Contents/Scripts/bundle.min.js | 3 +-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Contents/Scripts/account.js b/Contents/Scripts/account.js index d981239..766f114 100644 --- a/Contents/Scripts/account.js +++ b/Contents/Scripts/account.js @@ -34,18 +34,12 @@ class Account { return this._fetchRepositories(); }); - return repositoryEdges.reduce(function(repositories, edge) { - let repo = edge.node; - let owner = new Account(repo.owner.login); - - // Only return repositories that the account directly owns - if (owner.login === this.login) { - let repository = new Repository(owner, repo.name, repo.description); - repositories.push(repository); - } + return repositoryEdges.map(function(edge) { + let repo = edge.node; + let owner = new Account(repo.owner.login); - return repositories; - }.bind(this), []); + return new Repository(owner, repo.name, repo.description); + }); } _fetchRepositories(cursor, allEdges) { @@ -54,7 +48,7 @@ class Account { const query = ` query($login: String!, $cursor: String) { repositoryOwner(login: $login) { - repositories(first: 30, after: $cursor, orderBy: {field: PUSHED_AT, direction: DESC}) { + repositories(first: 30, after: $cursor, affiliation:[OWNER], orderBy: {field: PUSHED_AT, direction: DESC}) { edges { cursor node { diff --git a/Contents/Scripts/bundle.min.js b/Contents/Scripts/bundle.min.js index fa8f71e..06ea472 100644 --- a/Contents/Scripts/bundle.min.js +++ b/Contents/Scripts/bundle.min.js @@ -17,8 +17,7 @@ else if(match=input.match(ACCOUNT_FORMAT)){var account=new Account(match[1]);ret // // https://developer.obdev.at/launchbar-developer-documentation/#/script-output. function openAccountRepositories(string){return app.openAccountRepositoriesMenu(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);} -'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){allEdges=allEdges.concat(repositoryEdges);var lastEdge=repositoryEdges[repositoryEdges.length-1];return this._fetchRepositories(lastEdge.cursor,allEdges);}}else{return[];}return allEdges;}},{key:'handle',get:function get(){return'@'+this.login;}},{key:'profileURL',get:function get(){return'https://github.com/'+this.login;}},{key:'repositoriesURL',get:function get(){return'https://github.com/'+this.login+'?tab=repositories';}},{key:'issuesURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Aissue&ref=simplesearch';}},{key:'pullRequestsURL',get:function get(){return'https://github.com/search?utf8=%E2%9C%93&q=author%3A'+this.login+'+is%3Apr&ref=simplesearch';}},{key:'gistsURL',get:function get(){return'https://gist.github.com/'+this.login;}}]);return Account;}();if(typeof module!=='undefined'){module.exports.Account=Account;} +'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i0){allEdges=allEdges.concat(repositoryEdges);var lastEdge=repositoryEdges[repositoryEdges.length-1];return this._fetchRepositories(lastEdge.cursor,allEdges);}}else{return[];}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: From bf07115161f600fdc3f30b593cb4ffecd00009e5 Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Fri, 10 Mar 2017 18:53:42 -0500 Subject: [PATCH 2/2] Update indentation --- Contents/Scripts/account.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contents/Scripts/account.js b/Contents/Scripts/account.js index 766f114..3193395 100644 --- a/Contents/Scripts/account.js +++ b/Contents/Scripts/account.js @@ -35,8 +35,8 @@ class Account { }); return repositoryEdges.map(function(edge) { - let repo = edge.node; - let owner = new Account(repo.owner.login); + let repo = edge.node; + let owner = new Account(repo.owner.login); return new Repository(owner, repo.name, repo.description); });