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-GitLabProjectRepositoryCommit.ps1
More file actions
93 lines (82 loc) · 2.9 KB
/
Copy pathGet-GitLabProjectRepositoryCommit.ps1
File metadata and controls
93 lines (82 loc) · 2.9 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function Get-GitLabProjectRepositoryCommit
{
<#
.SYNOPSIS
Get project commit history.
.DESCRIPTION
Get project commit history. returns full history for deafult branch by default.
using -ReferenceName a different branch, tag or commit can be specified.
to retrieve commits for a speceific timeframe use -StartTime and -EndTime.
to retrieve a single commit specify the commit with -SHA
.EXAMPLE
Get-GitLabProjectRepositoryCommit -ProjectID 20
---------------------------------------------------------------
retrieves all commits composing the default branch.
.EXAMPLE
Get-GitLabProjectRepositoryCommit -StartTime (Get-Date).addDays(-2) -Endtime (Get-Date)
---------------------------------------------------------------
retrieves all commits composing the default branch between now and 2 days ago.
#>
[CmdletBinding(defaultParameterSetName = 'AllCommits')]
[Alias()]
[OutputType()]
Param
(
# The ID of a project
[Parameter(HelpMessage = 'The ID of a project',
Mandatory = $true)]
[Alias('ID')]
[String]$ProjectID,
# The name of a repository branch or tag or if not given the default branch
[Parameter(ParameterSetName = 'AllCommits',
HelpMessage = 'name of a repository branch or tag',
Mandatory = $false)]
[Alias('ref_name')]
[String]$ReferenceName,
# Only commits after or in this date will be returned
[Parameter(ParameterSetName = 'AllCommits',
HelpMessage = 'return commits after:',
Mandatory = $false)]
[Alias('since')]
[datetime]$StartTime,
# Only commits before or in this date will be returned
[Parameter(ParameterSetName = 'AllCommits',
HelpMessage = 'return commits before:',
Mandatory = $false)]
[Alias('until')]
[datetime]$EndTime,
# The commit hash or name of a repository branch or tag
[Parameter(ParameterSetName = 'SingleCommit',
HelpMessage = 'Commit Reference(hash|branchname|tagname)',
Mandatory = $true)]
[String]$sha,
# 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/commits"
$parameters = @{}
if($PSCmdlet.ParameterSetName -eq 'AllCommits')
{
if($ReferenceName)
{
$parameters.'ref_name' = $ReferenceName
}
if($StartTime)
{
$parameters.since = $StartTime.ToUniversalTime().tostring('s') +'Z'
}
if($EndTime)
{
$parameters.until = $EndTime.ToUniversalTime().tostring('s') +'Z'
}
}
if($PSCmdlet.ParameterSetName -eq 'SingleCommit')
{
$apiurl += "/$sha"
}
$GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
}