@@ -39,55 +39,62 @@ public async Task InitializeAsync()
3939 {
4040 return ;
4141 }
42-
43- await using var scope = _serviceProvider . CreateAsyncScope ( ) ;
44- var git = scope . ServiceProvider . GetRequiredService < IGit > ( ) ;
4542
46- var options = new GitRemoteOptions
43+ try
4744 {
48- Arguments = [ "get-url" , "origin" ] ,
49- ThrowOnNonZeroExitCode = false ,
50- CommandLogging = scope . ServiceProvider
51- . GetRequiredService < IOptions < LoggerFilterOptions > > ( )
52- . Value
53- . MinLevel == LogLevel . Debug
54- ? CommandLogging . Default
55- : CommandLogging . None ,
56- } ;
45+ await using var scope = _serviceProvider . CreateAsyncScope ( ) ;
46+ var git = scope . ServiceProvider . GetRequiredService < IGit > ( ) ;
47+
48+ var options = new GitRemoteOptions
49+ {
50+ Arguments = [ "get-url" , "origin" ] ,
51+ ThrowOnNonZeroExitCode = false ,
52+ CommandLogging = scope . ServiceProvider
53+ . GetRequiredService < IOptions < LoggerFilterOptions > > ( )
54+ . Value
55+ . MinLevel == LogLevel . Debug
56+ ? CommandLogging . Default
57+ : CommandLogging . None ,
58+ } ;
5759
58- var remote = await git . Commands . Remote ( options ) ;
59- var remoteUrl = remote . StandardOutput ;
60+ var remote = await git . Commands . Remote ( options ) ;
61+ var remoteUrl = remote . StandardOutput ;
6062
61- if ( string . IsNullOrEmpty ( remoteUrl ) )
62- {
63- _logger . LogWarning ( "Error when detecting GitHub git repository: {Error}" , remote . StandardError ) ;
63+ if ( string . IsNullOrEmpty ( remoteUrl ) )
64+ {
65+ _logger . LogWarning ( "Error when detecting GitHub git repository: {Error}" , remote . StandardError ) ;
6466
65- // Will not initialize as git repo is not setup
66- return ;
67- }
67+ // Will not initialize as git repo is not setup
68+ return ;
69+ }
6870
69- // Parse owner and repository name from the remote URL
70- var endpoint = "github" ;
71- var sshPattern = $@ "git@{ endpoint } \.com:(?<owner>.+)/(?<name>.+)\.git";
72- var httpsPattern = $@ "https://(.*@)?{ endpoint } \.com/(?<owner>.+)/(?<name>.+)(\.git)?";
71+ // Parse owner and repository name from the remote URL
72+ var endpoint = "github" ;
73+ var sshPattern = $@ "git@{ endpoint } \.com:(?<owner>.+)/(?<name>.+)\.git";
74+ var httpsPattern = $@ "https://(.*@)?{ endpoint } \.com/(?<owner>.+)/(?<name>.+)(\.git)?";
7375
74- var match = Regex . Match ( remoteUrl , sshPattern ) ;
75- if ( ! match . Success )
76- {
77- match = Regex . Match ( remoteUrl , httpsPattern ) ;
78- }
76+ var match = Regex . Match ( remoteUrl , sshPattern ) ;
77+ if ( ! match . Success )
78+ {
79+ match = Regex . Match ( remoteUrl , httpsPattern ) ;
80+ }
7981
80- if ( ! match . Success )
81- {
82- // Will not initialize as git repo is not setup
83- return ;
84- }
82+ if ( ! match . Success )
83+ {
84+ // Will not initialize as git repo is not setup
85+ return ;
86+ }
8587
86- Url = remoteUrl ;
87- Endpoint = endpoint ;
88- Owner = match . Groups [ "owner" ] . Value ;
89- RepositoryName = match . Groups [ "name" ] . Value ;
88+ Url = remoteUrl ;
89+ Endpoint = endpoint ;
90+ Owner = match . Groups [ "owner" ] . Value ;
91+ RepositoryName = match . Groups [ "name" ] . Value ;
9092
91- IsInitialized = true ;
93+ IsInitialized = true ;
94+ }
95+ catch ( Exception e )
96+ {
97+ Console . WriteLine ( e ) ;
98+ }
9299 }
93100}
0 commit comments