Skip to content

Commit 140b374

Browse files
authored
Merge pull request #15 from jcansdale/fixes/11-cross-platform
Don't throw if we can't open browser
2 parents 3b7fc10 + 84afe6e commit 140b374

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

GitPullRequest/Program.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using System.Diagnostics;
5+
using System.ComponentModel;
46
using LibGit2Sharp;
57
using GitPullRequest.Services;
68
using McMaster.Extensions.CommandLineUtils;
7-
using System.Linq;
89

910
namespace GitPullRequest
1011
{
@@ -84,7 +85,9 @@ void BrowsePullRequest(GitPullRequestService service, Repository repo)
8485
{
8586
foreach (var pr in prs)
8687
{
87-
Browse(pr.Repository.GetPullRequestUrl(pr.Number));
88+
var url = pr.Repository.GetPullRequestUrl(pr.Number);
89+
Console.WriteLine(url);
90+
TryBrowse(url);
8891
}
8992

9093
return;
@@ -99,7 +102,8 @@ void BrowsePullRequest(GitPullRequestService service, Repository repo)
99102
var compareUrl = service.FindCompareUrl(gitRepositories, repo);
100103
if (compareUrl != null)
101104
{
102-
Browse(compareUrl);
105+
Console.WriteLine(compareUrl);
106+
TryBrowse(compareUrl);
103107
return;
104108
}
105109

@@ -175,13 +179,22 @@ void PruneBranches(GitPullRequestService service, Repository repo)
175179
}
176180
}
177181

178-
void Browse(string pullUrl)
182+
bool TryBrowse(string url)
179183
{
180-
Process.Start(new ProcessStartInfo
184+
try
181185
{
182-
FileName = pullUrl,
183-
UseShellExecute = true
184-
});
186+
Process.Start(new ProcessStartInfo
187+
{
188+
FileName = url,
189+
UseShellExecute = true
190+
});
191+
192+
return false;
193+
}
194+
catch (Win32Exception)
195+
{
196+
return false;
197+
}
185198
}
186199
}
187200
}

0 commit comments

Comments
 (0)