diff --git a/Main.cs b/Main.cs index e8bd2fd..2f805d0 100644 --- a/Main.cs +++ b/Main.cs @@ -61,6 +61,10 @@ public List Query(Query query) { return Ember.Query(query, settings, context); } + else if (query.ActionKeyword.Equals("c")) + { + return VSCode.Query(query, settings, context); + } else if (String.IsNullOrEmpty(settings.apiToken)) { list.Add(new Result @@ -79,10 +83,6 @@ public List Query(Query query) { return Github.Query(query, settings, context); } - else if (query.ActionKeyword.Equals("c")) - { - return VSCode.Query(query, settings, context); - } else { return Settings.Query(query, settings, context, storage); diff --git a/Models/GithubApi.cs b/Models/GithubApi.cs index 9dde5b5..e847def 100644 --- a/Models/GithubApi.cs +++ b/Models/GithubApi.cs @@ -10,7 +10,13 @@ static class GithubApi { public static ApiResult QueryGithub(Query query, SettingsModel settings) { - String url = $"http://api.github.com/search/repositories?sort=updated&access_token={settings.apiToken}&q={query.Search}"; + ServicePointManager.Expect100Continue = true; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls + | SecurityProtocolType.Tls11 + | SecurityProtocolType.Tls12 + | SecurityProtocolType.Ssl3; + + String url = $"https://api.github.com/search/repositories?access_token={settings.apiToken}&q={query.Search}"; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version10; request.Method = "GET"; diff --git a/Plugins/VSCode.cs b/Plugins/VSCode.cs index 039d032..32cad86 100644 --- a/Plugins/VSCode.cs +++ b/Plugins/VSCode.cs @@ -10,9 +10,9 @@ static class VSCode { private static readonly string ico = "Prompt.png"; - public static void openResultInVSCode(ApiResultRepo result, SettingsModel settings) + public static void openResultInVSCode(string result) { - openVSCode($"{settings.gitFolder}\\{result.name}"); + openVSCode(result); } public static void openVSCode(String folder) @@ -32,29 +32,6 @@ public static void openVSCode(String folder) Process.Start(info); } - public static void cloneRepo(ApiResultRepo result, SettingsModel settings) - { - if (Directory.Exists($"{settings.gitFolder}\\{result.name}")) - { - return; - } - var cloneUrl = $"git@github.com:{result.owner.login}/{result.name}.git"; - var command = $"git clone {cloneUrl}"; - - ProcessStartInfo info; - var arguments = $"/c \"{command}\""; - info = new ProcessStartInfo - { - FileName = "cmd.exe", - Arguments = arguments, - UseShellExecute = true, - WindowStyle = ProcessWindowStyle.Hidden, - WorkingDirectory = settings.gitFolder - }; - - Process.Start(info); - } - public static List Query(Query query, SettingsModel settings, PluginInitContext context) { List list = new List(); @@ -75,21 +52,19 @@ public static List Query(Query query, SettingsModel settings, PluginInit return list; } - ApiResult results = GithubApi.QueryGithub(query, settings); + string[] results = Directory.GetDirectories(settings.gitFolder, $"*{query.Search}*", SearchOption.TopDirectoryOnly); - if (results.total_count > 0) + if (results.Length > 0) { - foreach (ApiResultRepo result in results.items) + foreach (string result in results) { list.Add(new Result { - Title = result.full_name, - SubTitle = result.description, + Title = Path.GetFileName(result), IcoPath = ico, Action = (e) => { - cloneRepo(result, settings); - openResultInVSCode(result, settings); + openResultInVSCode(result); return true; } });