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-GitlabProjectRepositoryFile.ps1
More file actions
65 lines (59 loc) · 2.32 KB
/
Copy pathGet-GitlabProjectRepositoryFile.ps1
File metadata and controls
65 lines (59 loc) · 2.32 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
function Get-GitLabProjectRepositoryFile
{
<#
.SYNOPSIS
Get a fileobject for specified file, reference and project
.DESCRIPTION
The Get-GitLabProjectRepositoryFile retrieves a file from the repository.
It returns a object containing all data and metadata of the file.
content of the file is base64 encoded by default.
.EXAMPLE
Get-GitLabProjectRepositoryFile -ProjectID 20 -SHA 5a411e1 -path README.md
---------------------------------------------------------------
gets from project 20 commit 5a411e1 the file README.md
.EXAMPLE
Get-GitLabProjectRepositoryFile -ProjectID 20 -SHA master -path README.md
---------------------------------------------------------------
gets from project 20 branch master the file README.md
.EXAMPLE
$FileObj = Get-GitLabProjectRepositoryFile -ProjectID 20 -SHA 5a411e1 -path README.md
PS C:\>[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($FileObj.content))
---------------------------------------------------------------
gets from project 20 commit 5a411e1 the file README.md and saves it to $FileObj.
converts the base64 encoded content to UTF8 string.
#>
[CmdletBinding(defaultParameterSetName='')]
[Alias()]
[OutputType()]
Param
(
# The ID of the project
[Parameter(HelpMessage = 'ProjectID',
Mandatory = $true)]
[Alias('ID')]
[String]$ProjectID,
# The commit SHA, Tag or Branch name
[Parameter(HelpMessage = 'Commit SHA or branch name',
Mandatory = $true)]
[Alias('RefName','ref')]
[string]$ReferenceName,
# The path of the file inside the projects repository.
[Parameter(ParameterSetName = 'ByCommit',
Helpmessage = 'The path of the file',
Mandatory = $true)]
[alias('file_path')]
[String]$FilePath,
# 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/files"
$Parameters = @{
'file_path'=$FilePath
'ref' =$ReferenceName
}
$GitlabConnect.callapi($apiurl,$httpmethod,$Parameters)
}