Skip to content
This repository was archived by the owner on Aug 22, 2022. It is now read-only.

Commit ddf19bb

Browse files
robinmalikngetchell
authored andcommitted
Addition: GitLab Issues (#175)
* Added Get-GitlabIssue code * Corrected parametersets and wrote documentation. * Changed to Pascal case for Scope variables and added 'all' option.
1 parent a67ae10 commit ddf19bb

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

PSGitLab/PSGitLab.Format.ps1xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,5 +606,37 @@
606606
</ListEntries>
607607
</ListControl>
608608
</View>
609+
<View>
610+
<Name>PSGitLab</Name>
611+
<ViewSelectedBy>
612+
<TypeName>GitLab.Issue</TypeName>
613+
</ViewSelectedBy>
614+
<ListControl>
615+
<ListEntries>
616+
<ListEntry>
617+
<ListItems>
618+
<ListItem>
619+
<PropertyName>title</PropertyName>
620+
</ListItem>
621+
<ListItem>
622+
<PropertyName>state</PropertyName>
623+
</ListItem>
624+
<ListItem>
625+
<PropertyName>id</PropertyName>
626+
</ListItem>
627+
<ListItem>
628+
<PropertyName>assignee</PropertyName>
629+
</ListItem>
630+
<ListItem>
631+
<PropertyName>created_at</PropertyName>
632+
</ListItem>
633+
<ListItem>
634+
<PropertyName>updated_at</PropertyName>
635+
</ListItem>
636+
</ListItems>
637+
</ListEntry>
638+
</ListEntries>
639+
</ListControl>
640+
</View>
609641
</ViewDefinitions>
610642
</Configuration>

PSGitLab/PSGitLab.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ FunctionsToExport = @(
7272
'Close-GitLabMergeRequest',
7373
'Close-GitLabMilestone',
7474
'Get-GitLabCommitStats',
75+
'Get-GitLabIssue',
7576
'Get-GitLabMergeRequest',
7677
'Get-GitLabMilestone',
7778
'Get-GitLabNamespace',
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Function Get-GitLabIssue {
2+
[cmdletbinding(DefaultParameterSetName='User')]
3+
[OutputType('GitLab.Issue')]
4+
param(
5+
[Parameter(ParameterSetName='GroupID')]
6+
[Int]$GroupID,
7+
8+
[Parameter(ParameterSetName='User')]
9+
[Parameter(ParameterSetName='GroupID')]
10+
[ValidateSet('All','CreatedByMe','AssignedToMe')]
11+
[String]$Scope,
12+
13+
[Parameter(ParameterSetName='User')]
14+
[Parameter(ParameterSetName='GroupID')]
15+
[ValidateSet("opened", "closed")]
16+
[String]$State
17+
)
18+
19+
$Request = @{
20+
URI = '/issues'
21+
Method = 'GET'
22+
}
23+
24+
# https://docs.gitlab.com/ee/api/issues.html
25+
26+
$GetUrlParameters = @()
27+
28+
if($State)
29+
{
30+
$GetUrlParameters += @{state=$State}
31+
}
32+
33+
if($Scope)
34+
{
35+
# Set the expected API value for the scope. Kebab case will change in Gitlab 11.
36+
if($Scope -eq 'CreatedByMe') {
37+
$GetUrlParameters += @{scope='created-by-me'}
38+
}
39+
elseif($Scope -eq 'AssignedToMe') {
40+
$GetUrlParameters += @{scope='assigned-to-me'}
41+
}
42+
elseif($Scope -eq 'all') {
43+
$GetUrlParameters += @{scope='all'}
44+
}
45+
else {
46+
}
47+
}
48+
else {
49+
# Defaults to issues 'created' by the user.
50+
}
51+
52+
$URLParameters = GetMethodParameters -GetURLParameters $GetUrlParameters
53+
54+
switch($PSCmdlet.ParameterSetName) {
55+
'GroupID' { $Request.URI = "/groups/$GroupID/issues$URLParameters"; break; }
56+
'User' { $Request.URI = "/issues$URLParameters"; break; }
57+
}
58+
59+
QueryGitLabAPI -Request $Request -ObjectType 'GitLab.Issue'
60+
}

docs/Get-GitLabIssue.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
external help file: PSGitLab-help.xml
3+
Module Name: PSGitLab
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-GitLabIssue
9+
10+
## SYNOPSIS
11+
Get issues from the GitLab instance.
12+
13+
## SYNTAX
14+
15+
### User (Default)
16+
```
17+
Get-GitLabIssue [-Scope <String>] [-State <String>] [<CommonParameters>]
18+
```
19+
20+
### GroupID
21+
```
22+
Get-GitLabIssue [-GroupID <Int32>] [-Scope <String>] [-State <String>] [<CommonParameters>]
23+
```
24+
25+
## DESCRIPTION
26+
Get issues from the GitLab instance.
27+
28+
## EXAMPLES
29+
30+
### EXAMPLE 1
31+
```
32+
Get-GitLabIssue
33+
```
34+
35+
Returns all issues created by the current user.
36+
37+
### EXAMPLE 2
38+
```
39+
Get-GitLabIssue -Scope all
40+
```
41+
42+
Returns all issues the current user has access to.
43+
44+
### EXAMPLE 3
45+
```
46+
Get-GitLabIssue -State closed
47+
```
48+
49+
Returns all issues created by the current user that are closed.
50+
51+
### EXAMPLE 4
52+
```
53+
Get-GitLabIssue -GroupID 2
54+
```
55+
56+
Returns all issues in the group with an ID of 2.
57+
58+
### EXAMPLE 5
59+
```
60+
Get-GitLabIssue -GroupID 2 -Scope AssignedToMe
61+
```
62+
63+
Returns all issues in the group with an ID of 2, that are assigned to me.
64+
65+
## PARAMETERS
66+
67+
### -GroupID
68+
A group ID.
69+
70+
```yaml
71+
Type: Int32
72+
Parameter Sets: GroupID
73+
Aliases:
74+
75+
Required: False
76+
Position: Named
77+
Default value: None
78+
Accept pipeline input: False
79+
Accept wildcard characters: False
80+
```
81+
82+
### -Scope
83+
Scope for the request. All returns all issues the current user can access. CreatedByMe are issues created by the current user, and AssignedToMe are issues that have been assigned to the current user.
84+
85+
```yaml
86+
Type: String
87+
Parameter Sets: (All)
88+
Aliases:
89+
Accepted values: All, CreatedByMe, AssignedToMe
90+
91+
Required: False
92+
Position: Named
93+
Default value: False
94+
Accept pipeline input: False
95+
Accept wildcard characters: False
96+
```
97+
98+
### -State
99+
Filter by issues that are closed or opened only.
100+
101+
```yaml
102+
Type: String
103+
Parameter Sets: (All)
104+
Aliases:
105+
Accepted values: opened, closed
106+
107+
Required: False
108+
Position: Named
109+
Default value: None
110+
Accept pipeline input: False
111+
Accept wildcard characters: False
112+
```
113+
114+
### CommonParameters
115+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
116+
117+
## INPUTS
118+
119+
## OUTPUTS
120+
121+
### GitLab.Issue
122+
123+
## NOTES
124+
125+
## RELATED LINKS

0 commit comments

Comments
 (0)