This repository was 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
Expand file tree
/
Copy pathGet-GitLabProjectRepositoryArchive.ps1
More file actions
72 lines (62 loc) · 2.41 KB
/
Copy pathGet-GitLabProjectRepositoryArchive.ps1
File metadata and controls
72 lines (62 loc) · 2.41 KB
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
function Get-GitLabProjectRepositoryArchive
{
<#
.SYNOPSIS
Get an archive of the repository of the specified project.
.DESCRIPTION
Get an archive of the repository of the specified project. Can be retrieved as [zip], [tar], [tar.gz] & [tar.bz2]
.EXAMPLE
Get-GitLabProjectRepositoryArchive -ProjectID 20 -SHA 5a411e1 -OutFile 5a411e1.zip
---------------------------------------------------------------
Saves the commit 5a411e1 to the file 5a411e1.zip
.EXAMPLE
Get-GitLabProjectRepositoryArchive -ProjectID 20 -SHA master -OutFile msater.zip
---------------------------------------------------------------
Saves the commit master to the file master.zip
#>
[CmdletBinding()]
[Alias()]
[OutputType()]
Param
(
# The ID of a project
[Parameter(HelpMessage = 'ProjectID',
Mandatory = $true)]
[Alias('ID')]
[String]$ProjectID,
#the commit SHA or Branch name
[Parameter(HelpMessage = 'Commit SHA or branch name',
Mandatory=$false)]
[Alias('RefName','ReferenceName')]
[string]$SHA,
#type of archive to download defaults to [zip]
[Parameter(HelpMessage='type of archive to download (zip|tar|tar.gz|tar.bz2)',
Mandatory = $false)]
[ValidateSet('zip','tar','tar.gz','tar.bz2')]
[string]$ArchiveType='zip',
#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)
)
#warn if outfile has different extention then archiveType
$regexExtention = $ArchiveType -replace '\.','\.'
$regexfilter = "^.*\.$regexExtention$"
$extentionmatches = $OutFile -match $regexfilter
if(-not $extentionmatches){
$warningmessage = "OutFile [$OutFile] does not match ArchiveType [$ArchiveType]. Archive downloaded as specified but content does not match extention."
Write-Warning -Message $warningmessage
}
$httpmethod = 'get'
$apiurl = "/projects/$([System.Web.HttpUtility]::UrlEncode($projectId))/repository/archive.$ArchiveType"
$Parameters = @{}
if($sha){
$Parameters.sha = $sha
}
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters,$OutFile)
}