Public/Get-JiraRemoteLink.ps1

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
function Get-JiraRemoteLink {
    <#
    .Synopsis
       Returns a remote link from a Jira issue
    .DESCRIPTION
       This function returns information on remote links from a JIRA issue.
    .EXAMPLE
       Get-JiraRemoteLink -Issue Project1-1000 -Credential $cred
       Returns information about all remote links from the issue "Project1-1000"
    .EXAMPLE
       Get-JiraRemoteLink -Issue Project1-1000 -LinkId 100000 -Credential $cred
       Returns information about a specific remote link from the issue "Project1-1000"
    .INPUTS
       [Object[]] The issue to look up in JIRA. This can be a String or a JiraPS.Issue object.
    .OUTPUTS
       [JiraPS.Link]
    #>

    [CmdletBinding()]
    param(
        # The Issue Object or ID to link.
        [Parameter(
            Position = 0,
            Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true
        )]
        [Alias("Key")]
        [String[]]$Issue,

        # Get a single link by it's id.
        [Int]$LinkId,

        # Credentials to use to connect to JIRA.
        # If not specified, this function will use anonymous access.
        [Parameter(Mandatory = $false)]
        [PSCredential] $Credential
    )

    Begin {
        Write-Debug "[Get-JiraRemoteLink] Reading server from config file"
        $server = Get-JiraConfigServer -ConfigFile $ConfigFile -ErrorAction Stop

        Write-Debug "[Get-JiraRemoteLink] ParameterSetName=$($PSCmdlet.ParameterSetName)"

        Write-Debug "[Get-JiraRemoteLink] Building URI for REST call"
        $linkUrl = "$server/rest/api/latest/issue/{0}/remotelink"
    }

    Process {
        foreach ($k in $Issue) {
            Write-Debug "[Get-JiraRemoteLink] Processing issue key [$k]"
            $thisUrl = $linkUrl -f $k

            if ($linkId) {
                $thisUrl += "/$l"
            }

            Write-Debug "[Get-JiraRemoteLink] Preparing for blastoff!"
            $result = Invoke-JiraMethod -Method Get -URI $thisUrl -Credential $Credential

            if ($result) {
                Write-Debug "[Get-JiraRemoteLink] Converting results to JiraPS.Group"
                $obj = ConvertTo-JiraLink -InputObject $result

                Write-Debug "[Get-JiraRemoteLink] Outputting results"
                Write-Output $obj
            }
            else {
                Write-Debug "[Get-JiraRemoteLink] No results were returned from JIRA"
                Write-Verbose "No results were returned from JIRA."
            }
        }
    }

    End {
        Write-Debug "[Get-JiraRemoteLink] Complete"
    }
}