Skip to content

Commit 10e6b1f

Browse files
committed
Finish tests and clean up docs
1 parent 45049f3 commit 10e6b1f

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

GitHubComments.ps1

+14-14
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function Get-GitHubRepositoryComment
137137
.EXAMPLE
138138
Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub
139139
140-
Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project.
140+
Get the comments for the PowerShell\PowerShellForGitHub project.
141141
#>
142142
[CmdletBinding(
143143
SupportsShouldProcess,
@@ -206,7 +206,7 @@ function Get-GitHubComment
206206
{
207207
<#
208208
.DESCRIPTION
209-
Get the issues for a given repository in Github.
209+
Get a single comment for a given repository in Github.
210210
211211
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
212212
@@ -224,7 +224,7 @@ function Get-GitHubComment
224224
them individually.
225225
226226
.PARAMETER CommentID
227-
How to sort the results, either created or updated. Default: created
227+
The ID of the comment to get.
228228
229229
.PARAMETER AccessToken
230230
If provided, this will be used as the AccessToken for authentication with the
@@ -237,9 +237,9 @@ function Get-GitHubComment
237237
If not supplied here, the DefaultNoStatus configuration property value will be used.
238238
239239
.EXAMPLE
240-
Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub
240+
Get-GitHubComment -OwnerName Powershell -RepositoryName PowerShellForGitHub -CommentID 1
241241
242-
Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project.
242+
Get a single comment from the PowerShell\PowerShellForGitHub project.
243243
#>
244244
[CmdletBinding(
245245
SupportsShouldProcess,
@@ -328,7 +328,7 @@ function New-GitHubComment
328328
If not supplied here, the DefaultNoStatus configuration property value will be used.
329329
330330
.EXAMPLE
331-
Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub
331+
New-GitHubComment -OwnerName Powershell -RepositoryName PowerShellForGitHub -IssueNumber 1 -Body "Testing this API"
332332
333333
Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project.
334334
#>
@@ -379,7 +379,7 @@ function New-GitHubComment
379379
'UriFragment' = "repos/$OwnerName/$RepositoryName/issues/$IssueNumber/comments"
380380
'Body' = ($hashBody | ConvertTo-Json)
381381
'Method' = 'Post'
382-
'Description' = "Getting comment $CommentID for $RepositoryName"
382+
'Description' = "Creating comment under issue $IssueNumber for $RepositoryName"
383383
'AccessToken' = $AccessToken
384384
'TelemetryEventName' = $MyInvocation.MyCommand.Name
385385
'TelemetryProperties' = $telemetryProperties
@@ -393,7 +393,7 @@ function Edit-GitHubComment
393393
{
394394
<#
395395
.DESCRIPTION
396-
Creates a new Github comment in an issue for the given repository
396+
Edits an existing comment in an issue for the given repository
397397
398398
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
399399
@@ -411,10 +411,10 @@ function Edit-GitHubComment
411411
them individually.
412412
413413
.PARAMETER CommentID
414-
The number for the issue that the comment will be filed under.
414+
The comment ID of the comment to edit.
415415
416416
.PARAMETER body
417-
The contents of the comment.
417+
The new contents of the comment.
418418
419419
.PARAMETER AccessToken
420420
If provided, this will be used as the AccessToken for authentication with the
@@ -427,7 +427,7 @@ function Edit-GitHubComment
427427
If not supplied here, the DefaultNoStatus configuration property value will be used.
428428
429429
.EXAMPLE
430-
Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub
430+
Edit-GitHubComment -OwnerName Powershell -RepositoryName PowerShellForGitHub -CommentID 1 -Body "Testing this API"
431431
432432
Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project.
433433
#>
@@ -510,7 +510,7 @@ function Remove-GitHubComment
510510
them individually.
511511
512512
.PARAMETER CommentID
513-
The number for the issue that the comment will be filed under.
513+
The id of the comment to delete.
514514
515515
.PARAMETER AccessToken
516516
If provided, this will be used as the AccessToken for authentication with the
@@ -523,9 +523,9 @@ function Remove-GitHubComment
523523
If not supplied here, the DefaultNoStatus configuration property value will be used.
524524
525525
.EXAMPLE
526-
Get-GitHubReferrerTraffic -OwnerName Powershell -RepositoryName PowerShellForGitHub
526+
Remove-GitHubComment -OwnerName Powershell -RepositoryName PowerShellForGitHub -CommentID 1
527527
528-
Get the top 10 referrers over the last 14 days from the PowerShell\PowerShellForGitHub project.
528+
Deletes a Github comment from the PowerShell\PowerShellForGitHub project.
529529
#>
530530
[CmdletBinding(
531531
SupportsShouldProcess,

Tests/GitHubComments.tests.ps1

+28-10
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ Reset-GitHubConfiguration
7777

7878
@{
7979
defaultIssueTitle = "Test Title"
80-
defaultCommentBody = "Test Body"
80+
defaultCommentBody = "This is a test body."
81+
defaultEditedCommentBody = "This is an edited test body."
8182
}.GetEnumerator() | ForEach-Object {
8283
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
8384
}
@@ -88,17 +89,16 @@ Describe 'Creating a new comment' {
8889
$issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle
8990

9091
Context 'For creating a new comment' {
91-
$newComment = New-GitHubComment -Uri $repo.svn_url -IssueNumber $issue.id -Body $defaultCommentBody
92+
$newComment = New-GitHubComment -Uri $repo.svn_url -IssueNumber $issue.number -Body $defaultCommentBody
9293
$existingComment = Get-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id
9394

9495
It "Should have the expected body text" {
9596
$existingComment.body | Should be $defaultCommentBody
9697
}
9798
}
9899

99-
Context 'For getting comments from an issue'
100-
{
101-
$existingComments = @(Get-GitHubIssueComment -Uri $repo.svn_url -IssueNumber $issue.id)
100+
Context 'For getting comments from an issue' {
101+
$existingComments = @(Get-GitHubIssueComment -Uri $repo.svn_url -IssueNumber $issue.number)
102102

103103
It 'Should have the expected number of comments' {
104104
$existingComments.Count | Should be 1
@@ -109,16 +109,34 @@ Describe 'Creating a new comment' {
109109
}
110110
}
111111

112-
Context 'For getting comments from a repository'
113-
{
112+
Context 'For editing a comment' {
113+
$newComment = New-GitHubComment -Uri $repo.svn_url -IssueNumber $issue.number -Body $defaultCommentBody
114+
$editedComment = Edit-GitHubComment -Uri $repo.svn_url -CommentID $newComment.id -Body $defaultEditedCommentBody
115+
116+
It 'Should have a body that is not equal to the original body' {
117+
$editedComment.body | Should not be $newComment.Body
118+
}
119+
120+
It 'Should have the edited content' {
121+
$editedComment.body | Should be $defaultEditedCommentBody
122+
}
123+
}
124+
125+
Context 'For getting comments from a repository and deleting them' {
114126
$existingComments = @(Get-GitHubRepositoryComment -Uri $repo.svn_url)
115127

116128
It 'Should have the expected number of comments' {
117-
$existingComments.Count | Should be 1
129+
$existingComments.Count | Should be 2
118130
}
119131

120-
It 'Should have the expected body text on the first comment' {
121-
$existingComments[0].body | Should be $defaultCommentBody
132+
foreach($comment in $existingComments) {
133+
Remove-GitHubComment -Uri $repo.svn_url -CommentID $comment.id
134+
}
135+
136+
$existingComments = @(Get-GitHubRepositoryComment -Uri $repo.svn_url)
137+
138+
It 'Should have no comments' {
139+
$existingComments.Count | Should be 0
122140
}
123141
}
124142

0 commit comments

Comments
 (0)