-
Notifications
You must be signed in to change notification settings - Fork 6
/
Atlassian.Bitbucket.PullRequest.Comment.psm1
117 lines (98 loc) · 4.02 KB
/
Atlassian.Bitbucket.PullRequest.Comment.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using module .\Atlassian.Bitbucket.Authentication.psm1
<#
.SYNOPSIS
Returns all the comments in a pull request.
.DESCRIPTION
Returns all the comments in a pull request.
.EXAMPLE
C:\PS> Get-BitbucketPullRequestComment -RepoSlug 'Repo' -PullRequestID 1
Returns all the comments on PR 1 in the `Repo` repository
.PARAMETER Workspace
Name of the workspace in Bitbucket. Defaults to selected workspace if not provided.
.PARAMETER RepoSlug
Name of the repo in Bitbucket.
.PARAMETER PullRequestID
The ID of the pull request in the repository.
#>
function Get-BitbucketPullRequestComment {
[CmdletBinding()]
param(
[Parameter( ValueFromPipelineByPropertyName = $true,
HelpMessage = 'Name of the workspace in Bitbucket. Defaults to selected workspace if not provided.')]
[Alias("Team")]
[string]$Workspace = (Get-BitbucketSelectedWorkspace),
[Parameter( Mandatory = $true,
Position = 0,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'The repository slug.')]
[Alias('Slug')]
[string]$RepoSlug,
[Parameter( Mandatory = $true,
Position = 1,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'The ID of the Pull Request')]
[Alias('ID')]
[string]$PullRequestID
)
Process {
$endpoint = "repositories/$Workspace/$RepoSlug/pullrequests/$PullRequestID/comments"
return Invoke-BitbucketAPI -Path $endpoint -Paginated
}
}
<#
.SYNOPSIS
Creates a new comment on a pull request.
.DESCRIPTION
Creates a new comment on a pull request and supports markdown.
.EXAMPLE
C:\PS> New-BitbucketPullRequestComment -RepoSlug 'Repo' -PullRequestID 1 -Comment 'Comment Text'
Creates a new comment against the PR as the authenticated user.
.EXAMPLE
C:\PS> New-BitbucketPullRequestComment -RepoSlug 'Repo' -PullRequestID 1 -Comment "# Heading1 `n * Item1 `n * Item2"
Creates a new comment with markdown against the PR as the authenticated user. Includes an h1 heading and bullet items.
.PARAMETER Workspace
Name of the workspace in Bitbucket. Defaults to selected workspace if not provided.
.PARAMETER RepoSlug
Name of the repo in Bitbucket.
.PARAMETER PullRequestID
The ID of the pull request in the repository.
.PARAMETER Comment
The text to use in the comment. Supports Markdown.
#>
function New-BitbucketPullRequestComment {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
param(
[Parameter( ValueFromPipelineByPropertyName = $true,
HelpMessage = 'Name of the workspace in Bitbucket. Defaults to selected workspace if not provided.')]
[Alias("Team")]
[string]$Workspace = (Get-BitbucketSelectedWorkspace),
[Parameter( Mandatory = $true,
Position = 0,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'The repository slug.')]
[Alias('Slug')]
[string]$RepoSlug,
[Parameter( Mandatory = $true,
Position = 1,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'The ID of the Pull Request')]
[Alias('ID')]
[string]$PullRequestID,
[Parameter( Mandatory = $true,
Position = 2,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'Comment to add to the Pull Request. Supports Markdown for formatting.')]
[string]$Comment
)
Process {
$endpoint = "repositories/$Workspace/$RepoSlug/pullrequests/$PullRequestID/comments"
$body = [ordered]@{
content = [ordered]@{
raw = $Comment
}
} | ConvertTo-Json -Depth 2 -Compress
if ($pscmdlet.ShouldProcess("PR $PullRequestID in $RepoSlug", 'create pull request comment')) {
return Invoke-BitbucketAPI -Path $endpoint -Body $body -Method Post
}
}
}