From 4c99d1ce395ee29342d6d6932b80a89c62f57f18 Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Wed, 26 Jul 2017 18:33:00 -0400 Subject: [PATCH 1/2] Update regex to support secondary search Early on in the development of GitHub for LaunchBar, the action supported "secondary searches" where if you added a space after your primary search, you could filter down the menu even more. For example, with something like: `bswinnerton issues` You would see only the issues menu item available. This appears to have broken in 42ef128, and unfortunately no tests caught this. This commit resolves the problem by reverting back to word-based regex support. --- Contents/Scripts/bundle.min.js | 4 ++-- Contents/Scripts/default.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Contents/Scripts/bundle.min.js b/Contents/Scripts/bundle.min.js index c6ce3b8..4ea70b9 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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(.*)\/(.*)#(\d+)?\s*(.*)?$/;var REPOSITORY_FORMAT=/^(.*)\/(.*)?\s*(.*)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(.*)?\s*(.*)?$/;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|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 @@ -22,7 +22,7 @@ function openAccountRepositories(string){return app.openAccountRepositoriesMenu( var Cache=function Cache(){_classCallCheck(this,Cache);};Cache.fetch=function(key,ttl,func){var results=Cache.read(key);if(results){return results;}else{return Cache.write(key,ttl,func);}};Cache.read=function(key){var path=Cache.filePath(key);if(File.exists(path)){var cacheData=File.readJSON(path);var currentTime=Math.floor(new Date()/1000);if(currentTime0){writeFile.call(this);}else if(Object.keys(results).length>0&&results.constructor===Object){writeFile.call(this);}return results;};Cache.filePath=function(key){return Action.cachePath+'/'+Action.version+'-'+key+'.json';};if(typeof module!=='undefined'){module.exports.Cache=Cache;} '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|developer)\.)?github\.(io|com)/;var ISSUE_OR_PR_FORMAT=/^(.*)\/(.*)#(\d+)?\s*(.*)?$/;var REPOSITORY_FORMAT=/^(.*)\/(.*)?\s*(.*)?$/;var COMMIT_SHA_FORMAT=/^\b[0-9a-f]{5,40}\b$/;var ACCOUNT_FORMAT=/^(.*)?\s*(.*)?$/;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|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 diff --git a/Contents/Scripts/default.js b/Contents/Scripts/default.js index fb213af..f6ad626 100644 --- a/Contents/Scripts/default.js +++ b/Contents/Scripts/default.js @@ -74,10 +74,10 @@ class GitHubLB { displayMenuItemFor(input) { const GITHUB_LINK_FORMAT = /^https?:\/\/((www|gist|raw|developer)\.)?github\.(io|com)/; - const ISSUE_OR_PR_FORMAT = /^(.*)\/(.*)#(\d+)?\s*(.*)?$/; - const REPOSITORY_FORMAT = /^(.*)\/(.*)?\s*(.*)?$/; + const ISSUE_OR_PR_FORMAT = /^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/; + const REPOSITORY_FORMAT = /^(\w+)\/(\w+)?\s*(\w+)?$/; const COMMIT_SHA_FORMAT = /^\b[0-9a-f]{5,40}\b$/; - const ACCOUNT_FORMAT = /^(.*)?\s*(.*)?$/; + const ACCOUNT_FORMAT = /^(\w+)\s*(\w+)?$/; let match; From 72a8d50a81fe87bb97adddf33781c264a2f3baff Mon Sep 17 00:00:00 2001 From: Brooks Swinnerton Date: Wed, 26 Jul 2017 18:48:33 -0400 Subject: [PATCH 2/2] Allow logins to have hyphens --- Contents/Scripts/bundle.min.js | 4 ++-- Contents/Scripts/default.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Contents/Scripts/bundle.min.js b/Contents/Scripts/bundle.min.js index 4ea70b9..e5faf43 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|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: +'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|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 @@ -22,7 +22,7 @@ function openAccountRepositories(string){return app.openAccountRepositoriesMenu( var Cache=function Cache(){_classCallCheck(this,Cache);};Cache.fetch=function(key,ttl,func){var results=Cache.read(key);if(results){return results;}else{return Cache.write(key,ttl,func);}};Cache.read=function(key){var path=Cache.filePath(key);if(File.exists(path)){var cacheData=File.readJSON(path);var currentTime=Math.floor(new Date()/1000);if(currentTime0){writeFile.call(this);}else if(Object.keys(results).length>0&&results.constructor===Object){writeFile.call(this);}return results;};Cache.filePath=function(key){return Action.cachePath+'/'+Action.version+'-'+key+'.json';};if(typeof module!=='undefined'){module.exports.Cache=Cache;} '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|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: +'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|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 diff --git a/Contents/Scripts/default.js b/Contents/Scripts/default.js index f6ad626..50bfcc6 100644 --- a/Contents/Scripts/default.js +++ b/Contents/Scripts/default.js @@ -74,10 +74,10 @@ class GitHubLB { displayMenuItemFor(input) { const GITHUB_LINK_FORMAT = /^https?:\/\/((www|gist|raw|developer)\.)?github\.(io|com)/; - const ISSUE_OR_PR_FORMAT = /^(\w+)\/(\w+)#(\d+)?\s*(\w+)?$/; - const REPOSITORY_FORMAT = /^(\w+)\/(\w+)?\s*(\w+)?$/; + const ISSUE_OR_PR_FORMAT = /^([\w-]+)\/([\w-]+)#(\d+)?\s*([\w-]+)?$/; + const REPOSITORY_FORMAT = /^([\w-]+)\/([\w-]+)?\s*([\w-]+)?$/; const COMMIT_SHA_FORMAT = /^\b[0-9a-f]{5,40}\b$/; - const ACCOUNT_FORMAT = /^(\w+)\s*(\w+)?$/; + const ACCOUNT_FORMAT = /^([\w-]+)\s*([\w-]+)?$/; let match;