This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet-GitLabProjectRepositoryFileRaw.ps1
79 lines (68 loc) · 2.53 KB
/
Get-GitLabProjectRepositoryFileRaw.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-GitLabProjectRepositoryFileRaw
{
<#
.SYNOPSIS
Get a file and save the raw content to disk.
.DESCRIPTION
The Get-GitLabProjectRepositoryFileRaw retrieves the raw file contents for a file by blob SHA or by commit SHA/branche name and path.
It saves it to the path specified. Container must exists beforehand.
.EXAMPLE
Get-GitLabProjectRepositoryFileRaw -ProjectID 20 -SHA 5a411e1 -path README.md -OutFile README.md
---------------------------------------------------------------
gets from project 20 commit 5a411e1 the file README.md and saves it locally to README.md
.EXAMPLE
Get-GitLabProjectRepositoryFileRaw -ProjectID 20 -SHA master -path README.md -Outfile C:\README.md
---------------------------------------------------------------
gets from project 20 branch master the file README.md and saves it locally to README.md
#>
[CmdletBinding(DefaultParameterSetName = 'ByCommit')]
[Alias()]
[OutputType()]
Param
(
# The ID of a project
[Parameter(HelpMessage = 'ProjectID',
Mandatory = $true)]
[Alias('ID')]
[String]$ProjectID,
#the commit SHA or Branch name
[Parameter(ParameterSetName = 'ByCommit',
HelpMessage = 'Commit SHA or branch name',
Mandatory = $true)]
[Alias('RefName')]
[string]$ReferenceName,
#The path of the file inside the projects repository.
[Parameter( ParameterSetName = 'ByCommit',
Helpmessage = 'The path of the file',
Mandatory = $true)]
[String]$FilePath,
#The blob SHA for a blob from the projects repository
[Parameter( ParameterSetName = 'ByBlobSHA',
Helpmessage = 'Blob SHA',
Mandatory = $true)]
[Alias('sha')]
[String]$BlobSha,
#path for the new created file
[Parameter(HelpMessage = 'filepath for file',
Mandatory = $true)]
[String]$OutFile,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitlabConnect)
)
$httpmethod = 'get'
$apiurl = "/projects/$([System.Web.HttpUtility]::UrlEncode($projectId))/repository/"
$Parameters = @{}
if($PSCmdlet.ParameterSetName -eq 'ByCommit')
{
$apiurl += "blobs/$ReferenceName"
$Parameters.filepath = $FilePath
}
if($PSCmdlet.ParameterSetName -eq 'ByBlobSHA')
{
$apiurl += "raw_blobs/$BlobSha"
}
$GitlabConnect.callapi($apiurl,$httpmethod,$Parameters,$OutFile)
}