@@ -16,7 +16,7 @@ public class GithubPlugin : IBotPlugin
1616 private readonly GitHubClient _client ;
1717 private readonly int _order ;
1818
19- static Regex _exIssueParsing = new Regex ( @"\s*(?'type'\w+)\s*(?'topic'.*)" ) ;
19+ static readonly Regex _exIssueParsing = new ( @"\s*(?'type'\w+)\s*(?'topic'.*)" ) ;
2020
2121 // private readonly bool _isAuthenticated;
2222 public GithubPlugin ( ILoggerFactory loggerFactory , int order , string ? githubToken = null )
@@ -32,20 +32,19 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
3232 if ( string . IsNullOrEmpty ( token ) == false )
3333 {
3434 _client . Credentials = new Credentials ( token ) ;
35- // _isAuthenticated = true;
3635 }
3736 }
3837
3938 public int Order => _order ;
4039
4140 public IEnumerable < ( string , string ? ) > ? GetCommandsAndDecriptions ( )
4241 {
43- return new List < ( string , string ? ) >
44- {
42+ return
43+ [
4544 ( "latest" , "get latest release notes" ) ,
4645 ( "issues" , "get latest (max 10) reported issues" ) ,
4746 ( "issue" , "adds issues fast, enter command `issue` for additional options" ) ,
48- } ;
47+ ] ;
4948 }
5049
5150 public async Task < BotResult ? > HandleMessage ( IMessage message )
@@ -67,7 +66,7 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
6766 return await AddIssueInRepo ( message ) ;
6867 }
6968 }
70- catch ( System . Exception e )
69+ catch ( Exception e )
7170 {
7271 _logger . LogError ( e , "Failed to handle message" ) ;
7372 }
@@ -92,11 +91,11 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
9291 }
9392
9493 Match ? match = _exIssueParsing . Matches ( message . CommandArgs ) . FirstOrDefault ( ) ;
95- if ( match is object )
94+ if ( match is not null )
9695 {
9796 string ? command = null , title = null ;
9897
99- foreach ( Group ? group in match . Groups )
98+ foreach ( Group ? group in match . Groups . Cast < Group ? > ( ) )
10099 {
101100 if ( group ? . Name == "type" )
102101 command = string . IsNullOrEmpty ( group . Value ) ? null : group . Value . ToLowerInvariant ( ) ;
@@ -109,18 +108,13 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
109108 return GetIssueMissingTitleHelpMessage ( ) ;
110109 }
111110
112- switch ( command )
111+ return command switch
113112 {
114- case "docs" :
115- return await AddDocsIssue ( title , message . User ) ;
116- case "feature" :
117- return await AddDaemonIssue ( "feature" , title , message . User ) ;
118- case "bug" :
119- return await AddDaemonIssue ( "bug" , title , message . User ) ;
120- default :
121- return UnKnownIssueCommand ( ) ;
122- }
123-
113+ "docs" => await AddDocsIssue ( title , message . User ) ,
114+ "feature" => await AddDaemonIssue ( "feature" , title , message . User ) ,
115+ "bug" => await AddDaemonIssue ( "bug" , title , message . User ) ,
116+ _ => UnKnownIssueCommand ( ) ,
117+ } ;
124118 ;
125119
126120 }
@@ -145,7 +139,7 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
145139 _ => null
146140 } ;
147141
148- if ( label is object )
142+ if ( label is not null )
149143 createIssue . Labels . Add ( label ) ;
150144
151145 var body = type switch
@@ -155,7 +149,7 @@ public GithubPlugin(ILoggerFactory loggerFactory, int order, string? githubToken
155149 _ => null
156150 } ;
157151
158- if ( body is object )
152+ if ( body is not null )
159153 createIssue . Body = body ;
160154
161155 var issue = await _client . Issue . Create ( "net-daemon" , "netdaemon" , createIssue ) ;
@@ -244,7 +238,7 @@ private BotResult GetIssueHelpMessage()
244238 if ( releases . Count == 0 )
245239 return null ;
246240
247- var release = releases . First ( ) ;
241+ var release = releases [ 0 ] ;
248242
249243 var result = new BotResult ( ) { Title = $ "Latest release version { release . TagName } ", Text = release . Body } ;
250244
@@ -292,7 +286,7 @@ private BotResult GetIssueHelpMessage()
292286 return result ;
293287 }
294288
295- private string featureTemplate = @"
289+ private readonly string featureTemplate = @"
296290<!--
297291 Please describe the feature you want from a usage perspective.
298292-->
@@ -312,7 +306,7 @@ Please describe the feature you want from a usage perspective.
312306
313307" ;
314308
315- private string docsTemplate = @"
309+ private readonly string docsTemplate = @"
316310<!--
317311 Please describe what suggestions or issues you have for the docs.
318312-->
@@ -323,7 +317,7 @@ Please describe the feature you want from a usage perspective.
323317
324318" ;
325319
326- private string issueTemplate = @"
320+ private readonly string issueTemplate = @"
327321<!-- READ THIS FIRST:
328322 - If you need additional help with this template, please refer to https://netdaemon.xtz/help/reporting_issues/
329323 - Make sure you are running the latest version of NetDaemon before reporting an issue: https://github.com/net-daemon/netdaemon/releases
0 commit comments