Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial release #1

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f8768f1
Adding dynamic fetching for .NET library dependencies.
CameronSWilliamson Jul 15, 2024
cc5cd34
Adding New-YTSession function that creates a session object.
CameronSWilliamson Jul 15, 2024
508ae23
Adding automated setup for YouTrack
CameronSWilliamson Jul 18, 2024
182bf56
Moving automation to python to make it easier on appveyor
CameronSWilliamson Jul 19, 2024
7095cbb
Providing zipped YouTrack instance for testing
CameronSWilliamson Jul 25, 2024
ae989f8
Ending Youtrack process on build servers
CameronSWilliamson Jul 26, 2024
90436aa
Adding support for Unix operating systems
CameronSWilliamson Jul 26, 2024
1ffe7c3
Removing all dll dependencies
CameronSWilliamson Jul 26, 2024
6318490
Updating init to use ytconfig.zip and download youtrack from the website
CameronSWilliamson Jul 26, 2024
ef6f213
Adding Invoke-YTRestMethod function
CameronSWilliamson Jul 26, 2024
a7d7e6d
Adding Get-YTIssue function
CameronSWilliamson Jul 29, 2024
b3e3aa1
Adding get project and new project functions
CameronSWilliamson Aug 1, 2024
0884e6c
Adding New-YTIssue function and unittests
CameronSWilliamson Aug 2, 2024
46dcf80
Fixing failing tests
CameronSWilliamson Aug 5, 2024
1866c5f
Ready for first release
CameronSWilliamson Aug 5, 2024
4a15b62
Adding Remove-YTProject function
CameronSWilliamson Jan 6, 2025
aea8cb2
Removing all projects before each test suite
CameronSWilliamson Jan 6, 2025
97110c4
Adding test that makes a real request
CameronSWilliamson Jan 6, 2025
ef243a3
Adding support for error descriptions when invoking youtrack rest met…
CameronSWilliamson Jan 7, 2025
c5ad7a8
Adding Remove-AllProjects helper function and updating documentation …
CameronSWilliamson Jan 7, 2025
5b5a418
Adding function to get IDs for custom fields and to get the state of …
CameronSWilliamson Jan 9, 2025
4cd3f22
Adding support for getting an issue's custom fields.
CameronSWilliamson Jan 14, 2025
0f1c7c3
Check in YouTrack config as loose files instead of a zip.
KhoiKy Jan 24, 2025
4532698
Rename test helper function to Clear-Project.
KhoiKy Jan 24, 2025
b43813d
Use EscapeDataString instead of EscapeUriString.
KhoiKy Jan 24, 2025
b25e25f
Parameter name should be singular.
KhoiKy Jan 24, 2025
f7ceb28
Update module's help.txt
KhoiKy Jan 24, 2025
b69a854
Update tests so that they don't mock invoking of rest methods.
KhoiKy Jan 24, 2025
3f058e7
Improve documentation on functions.
KhoiKy Jan 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
/YouTrackAutomation/LICENSE.txt
/YouTrackAutomation/NOTICE.txt
/YouTrackAutomation/README.md
/YouTrackAutomation/Bin
/packages
/youtrack-2024.2.37269
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Overview

The "YouTrackAutomation" module...
The "YouTrackAutomation" module is a PowerShell module built to interface with the YouTrack REST API.

# System Requirements

Expand All @@ -24,3 +24,17 @@ Import-Module -Name '.\YouTrackAutomation'
```

# Commands

## Creating a new session

All commands require a `session` object in order to call them. Create a new session object using the `New-YTSession`
command.

## Interacting With API

* `Get-YTIssue`
* `Get-YTProject`
* `Invoke-YTRestMethod`
* `New-YTIssue`
* `New-YTProject`
* `New-YTSession`
36 changes: 0 additions & 36 deletions TODO.md

This file was deleted.

66 changes: 66 additions & 0 deletions Tests/Get-YTIssue.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Set-StrictMode -Version 'Latest'

BeforeAll {
Set-StrictMode -Version 'Latest'

& (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-Test.ps1' -Resolve)

function WhenGettingIssue
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[String] $IssueId,
[String] $AdditionalFields
)

$script:result = Get-YTIssue -Session $session @PSBoundParameters
}

function ThenIssueHasValue
{
[CmdletBinding()]
param(
[String] $Field,
[String] $Value
)

$script:result.$Field | Should -Be $Value
}

function ThenIssueHasField
{
[CmdletBinding()]
param(
[String] $Field
)

$script:result.$Field | Should -Not -BeNullOrEmpty
}
}

Describe 'Get-YTIssue' {
BeforeEach {
$script:session = New-YTSession -Url $apiUrl -ApiToken $apiToken
}

It 'should return an issue using the ''jira id''' {
WhenGettingIssue -IssueId '3-4'
ThenIssueHasValue -Field 'idReadable' -Value 'DEMO-5'
ThenIssueHasValue -Field 'id' -Value '3-4'
ThenIssueHasValue -Field 'summary' -Value 'First steps for project administrators'
}

It 'should return an issue using the ''issue key''' {
WhenGettingIssue -IssueId 'DEMO-1'
ThenIssueHasValue -Field 'id' -Value '3-0'
ThenIssueHasValue -Field 'idReadable' -Value 'DEMO-1'
ThenIssueHasValue -Field 'summary' -Value 'Launch YouTrack'
}

It 'should support additional fields' {
$additionalFields = 'comments(id,author(name),text,created,updated)'
WhenGettingIssue -IssueId 'DEMO-1' -AdditionalFields $additionalFields
ThenIssueHasField -Field 'comments'
}
}
99 changes: 99 additions & 0 deletions Tests/Get-YTProject.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Set-StrictMode -Version 'Latest'

BeforeAll {
Set-StrictMode -Version 'Latest'

& (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-Test.ps1' -Resolve)

function GivenProject
{
[CmdletBinding()]
param(
[String] $ShortName = 'GYTP1',
[String] $Name = 'Get-YTProject Test Project',
[String] $Leader = 'admin'
)

New-YTProject -Session $script:session -ShortName $ShortName -Name $Name -Leader $Leader -Description 'This is a test project.'
}

function WhenGettingProject
{
[CmdletBinding()]
param(
[String] $ProjectShortName,
[String] $AdditionalFields
)

$script:result = Get-YTProject -Session $script:session @PSBoundParameters
}

function ThenProjectHasField
{
[CmdletBinding()]
param(
[String] $Field
)

$script:result.$Field | Should -Not -BeNullOrEmpty
}

function ThenProjectsReturned
{
[CmdletBinding()]
param(
[Int] $GreaterThanEqual = 1

)
$script:result | Should -Not -BeNullOrEmpty
if (Get-Member -Name Length -InputObject $script:result -ErrorAction SilentlyContinue)
{
$script:result.Length | Should -BeGreaterOrEqual $GreaterThanEqual
}
$idCount =
$script:result |
ForEach-Object { $_.id } |
Select-Object -Unique |
Measure-Object |
Select-Object -ExpandProperty Count
$script:result | Should -HaveCount $idCount
}

function ThenProjectWithShortName
{
[CmdletBinding()]
param(
[String] $ShortName
)

$script:result |
ForEach-Object { $_.shortName} |
Where-Object { $_ -eq $ShortName } |
Should -Not -BeNullOrEmpty
}
}

Describe 'Get-YTIssue' {
BeforeEach {
$script:session = New-YTSession -Url $apiUrl -ApiToken $apiToken
}

It 'returns one project' {
GivenProject -ShortName 'GYTP1' -Name 'Get-YTProject Test Project' -Leader 'admin'
WhenGettingProject -ProjectShortName 'DEMO'
ThenProjectsReturned -GreaterThanEqual 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would combine the two ThenProject* functions into a single ThenReturns function:

ThenReturns -Count 2
ThenReturns -ProjectWithShortName 'DEMO'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use GreaterThanEqual. Use an exact count. If you use greater than or equal to, if the API returns more than expected, tests will still pass.

ThenProjectWithShortName -ShortName 'DEMO'
}

It 'return all projects' {
WhenGettingProject
ThenProjectsReturned -GreaterThanEqual 2
ThenProjectWithShortName -ShortName 'DEMO'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert both projects that get returned.

}

It 'should support additional fields' {
WhenGettingProject -AdditionalFields 'description'
ThenProjectsReturned -GreaterThanEqual 2
$script:result | Where-Object {$_.shortName -eq 'GYTP1'} | ForEach-Object { $_.description } | Should -Not -BeNullOrEmpty
}
}
75 changes: 75 additions & 0 deletions Tests/Invoke-YTRestMethod.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Set-StrictMode -Version 'Latest'

BeforeAll {
Set-StrictMode -Version 'Latest'

& (Join-Path -Path $PSScriptRoot -ChildPath 'Initialize-Test.ps1' -Resolve)

function MockIrm
{
param(
[Object] $MockWith,
[scriptblock] $ParameterFilter
)

$splat = @{}
if ($ParameterFilter)
{
$splat['ParameterFilter'] = $ParameterFilter
}

if ($MockWith)
{
$splat['MockWith'] = $MockWith
}


Mock -CommandName 'Invoke-RestMethod' -ModuleName 'YouTrackAutomation' @splat
}

function ThenRestMethodInvoked
{
param(
[int] $Times = 1,
[scriptblock] $ParameterFilter
)

$splat = @{}
if ($ParameterFilter)
{
$splat['ParameterFilter'] = $ParameterFilter
}

Should -Invoke 'Invoke-RestMethod' -ModuleName 'YouTrackAutomation' -Times $Times @splat
}

function ThenRestMethodNotInvoked
{
Should -Not -Invoke 'Invoke-RestMethod' -ModuleName 'YouTrackAutomation'
}
}

Describe 'Invoke-YTRestMethod' {
splatteredbits marked this conversation as resolved.
Show resolved Hide resolved
BeforeEach {
$script:session = New-YTSession -Url $apiUrl -ApiToken $apiToken
}

It 'should always make GET requests' {
splatteredbits marked this conversation as resolved.
Show resolved Hide resolved
MockIrm -MockWith { 'get-request' }
$res = Invoke-YTRestMethod -Session $script:session -Name 'wikis' -Method Get
$res | Should -Be 'get-request'
$res = Invoke-YTRestMethod -Session $script:session -Name 'wikis' -Method Get -WhatIf
$res | Should -Be 'get-request'
ThenRestMethodInvoked -Times 2

}

It 'should not make PUT requests with WhatIf' {
MockIrm -MockWith { 'put-request' }
$res = Invoke-YTRestMethod -Session $script:session -Name 'wikis' -Method Put
$res | Should -Be 'put-request'
$res = Invoke-YTRestMethod -Session $script:session -Name 'wikis' -Method Put -WhatIf
$res | Should -BeNullOrEmpty
ThenRestMethodInvoked -Times 1
}
}
Loading