Skip to content

Commit

Permalink
feat: Use file system for code
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithClinard committed Sep 14, 2019
1 parent e4ac1ec commit 93496f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public List<Result> 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
Expand All @@ -79,10 +83,6 @@ public List<Result> 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);
Expand Down
8 changes: 7 additions & 1 deletion Models/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
39 changes: 7 additions & 32 deletions Plugins/VSCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = $"[email protected]:{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<Result> Query(Query query, SettingsModel settings, PluginInitContext context)
{
List<Result> list = new List<Result>();
Expand All @@ -75,21 +52,19 @@ public static List<Result> 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;
}
});
Expand Down

0 comments on commit 93496f5

Please sign in to comment.