88using Discord . Commands ;
99using Discord . WebSocket ;
1010using Octokit ;
11+ using TabletBot . Discord . Commands . Attributes ;
1112using TabletBot . Discord . Embeds ;
1213
1314namespace TabletBot . Discord . Commands
1415{
16+ [ Module ]
1517 public class GitHubCommands : CommandModule
1618 {
17- private GitHubClient _gitHubClient ;
19+ private readonly GitHubClient _gitHubClient ;
1820 private readonly DiscordSocketClient _discordSocketClient ;
1921
2022 public GitHubCommands ( GitHubClient gitHubClient , DiscordSocketClient discordSocketClient )
@@ -23,16 +25,16 @@ public GitHubCommands(GitHubClient gitHubClient, DiscordSocketClient discordSock
2325 _discordSocketClient = discordSocketClient ;
2426 }
2527
26- private const string RepositoryOwner = "InfinityGhost" ;
27- private const string RepositoryName = "OpenTabletDriver" ;
28+ private const string REPOSITORY_OWNER = "InfinityGhost" ;
29+ private const string REPOSITORY_NAME = "OpenTabletDriver" ;
2830 private static readonly Regex ArtifactRegex = new Regex ( "<.+?href=\" /InfinityGhost/OpenTabletDriver/suites/(?<Suite>.+?)/artifacts/(?<Artifact>.+?)\" >(?<Name>.+?)</.+?>" ) ;
2931 private static readonly Regex CommitRegex = new Regex ( "href=\" .+?commit/(?<SHA>.+?)/.+?/.+?\" " ) ;
3032
3133 [ Command ( "overview" , RunMode = RunMode . Async ) , Name ( "Overview" ) , Alias ( "info" ) , Summary ( "Shows an overview of the repository." ) ]
3234 public async Task GetRepositoryOverview ( )
3335 {
34- var message = await ReplyAsync ( $ "Getting overview for { RepositoryOwner } /{ RepositoryName } ...") ;
35- var repo = await _gitHubClient . Repository . Get ( RepositoryOwner , RepositoryName ) ;
36+ var message = await ReplyAsync ( $ "Getting overview for { REPOSITORY_OWNER } /{ REPOSITORY_NAME } ...") ;
37+ var repo = await _gitHubClient . Repository . Get ( REPOSITORY_OWNER , REPOSITORY_NAME ) ;
3638
3739 IEnumerable < Issue > issues =
3840 from issue in await _gitHubClient . Issue . GetAllForRepository ( repo . Id )
@@ -46,7 +48,7 @@ from pr in await _gitHubClient.PullRequest.GetAllForRepository(repo.Id)
4648
4749 var embed = new EmbedBuilder
4850 {
49- Title = $ "{ RepositoryOwner } /{ RepositoryName } ",
51+ Title = $ "{ REPOSITORY_OWNER } /{ REPOSITORY_NAME } ",
5052 Timestamp = repo . PushedAt ,
5153 Url = repo . HtmlUrl ,
5254 ThumbnailUrl = _discordSocketClient . CurrentUser . GetAvatarUrl ( ) ,
@@ -64,43 +66,40 @@ from pr in await _gitHubClient.PullRequest.GetAllForRepository(repo.Id)
6466 [ Command ( "getpr" , RunMode = RunMode . Async ) , Name ( "Get Pull Request" ) , Alias ( "pr" ) , Summary ( "Fetches pull request information." ) ]
6567 public async Task GetPullRequest ( [ Remainder ] int id )
6668 {
67- await Context . Message . DeleteAsync ( ) ;
6869 var message = await ReplyAsync ( $ "Fetching pull request #{ id } ") ;
69- var pr = await _gitHubClient . PullRequest . Get ( RepositoryOwner , RepositoryName , id ) ;
70+ var pr = await _gitHubClient . PullRequest . Get ( REPOSITORY_OWNER , REPOSITORY_NAME , id ) ;
7071 var embed = GitHubEmbeds . GetPullRequestEmbed ( pr ) ;
7172 await message . Update ( embed ) ;
7273 }
7374
7475 [ Command ( "getissue" , RunMode = RunMode . Async ) , Name ( "Get Issue" ) , Alias ( "issue" ) , Summary ( "Fetches issue information." ) ]
7576 public async Task GetIssue ( [ Remainder ] int id )
7677 {
77- await Context . Message . DeleteAsync ( ) ;
7878 var message = await ReplyAsync ( $ "Fetching issue #{ id } ") ;
79- var issue = await _gitHubClient . Issue . Get ( RepositoryOwner , RepositoryName , id ) ;
79+ var issue = await _gitHubClient . Issue . Get ( REPOSITORY_OWNER , REPOSITORY_NAME , id ) ;
8080 var embed = GitHubEmbeds . GetIssueEmbed ( issue ) ;
8181 await message . Update ( embed ) ;
8282 }
8383
8484 [ Command ( "getartifacts" , RunMode = RunMode . Async ) , Name ( "Get Artifacts" ) , Alias ( "artifacts" , "artifact" ) , Summary ( "Returns all artifacts for a workflow from its URL." ) ]
8585 public async Task GetArtifacts ( [ Remainder ] string url )
8686 {
87- await Context . Message . DeleteAsync ( ) ;
8887 var message = await ReplyAsync ( "Fetching artifacts..." ) ;
8988
9089 string html ;
9190 using ( var client = new HttpClient ( ) )
9291 html = await client . GetStringAsync ( url ) ;
9392
94- IEnumerable < Match > artifacts = await Task < MatchCollection > . Run ( ( ) => ArtifactRegex . Matches ( html ) ) ;
95- Match commitMatch = await Task < Match > . Run ( ( ) => CommitRegex . Match ( html ) ) ;
96- string sha = commitMatch . Groups [ "SHA" ] . Value ;
97- string hash = string . Concat ( sha . Take ( 7 ) ) ;
98- var commit = await _gitHubClient . Git . Commit . Get ( RepositoryOwner , RepositoryName , sha ) ;
93+ IEnumerable < Match > artifacts = await Task . Run ( ( ) => ArtifactRegex . Matches ( html ) ) ;
94+ var commitMatch = await Task . Run ( ( ) => CommitRegex . Match ( html ) ) ;
95+ var sha = commitMatch . Groups [ "SHA" ] . Value ;
96+ var hash = string . Concat ( sha . Take ( 7 ) ) ;
97+ var commit = await _gitHubClient . Git . Commit . Get ( REPOSITORY_OWNER , REPOSITORY_NAME , sha ) ;
9998 var title = commit . Message . Split ( Environment . NewLine ) . First ( ) ;
10099
101100 var embed = new EmbedBuilder
102101 {
103- Title = string . Format ( "{0 } ({1 })", title , hash ) ,
102+ Title = $ " { title } ({ hash } )",
104103 Url = url ,
105104 Color = Color . Green
106105 } ;
0 commit comments