From 8825c4e5f570a8a13d98bef99e93719f3c36736d Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 19:50:47 +0000 Subject: [PATCH 01/10] Docs --- .vscode/launch.json | 27 +++++ SnipeItPS.build.ps1 | 128 +++++++++++++++++++---- SnipeitPS/docs/Get-Asset.md | 73 ++++++++++++++ SnipeitPS/docs/Get-Categories.md | 75 ++++++++++++++ SnipeitPS/docs/Get-Component.md | 75 ++++++++++++++ SnipeitPS/docs/Get-Manufacturers.md | 75 ++++++++++++++ SnipeitPS/docs/Get-Models.md | 75 ++++++++++++++ SnipeitPS/docs/Get-Status.md | 75 ++++++++++++++ SnipeitPS/docs/Get-Users.md | 73 ++++++++++++++ SnipeitPS/docs/Invoke-Method.md | 102 +++++++++++++++++++ SnipeitPS/docs/New-Asset.md | 136 +++++++++++++++++++++++++ SnipeitPS/docs/New-Component.md | 120 ++++++++++++++++++++++ SnipeitPS/docs/New-Manufacturer.md | 90 +++++++++++++++++ SnipeitPS/docs/New-Model.md | 136 +++++++++++++++++++++++++ SnipeitPS/docs/Set-Asset.md | 151 ++++++++++++++++++++++++++++ SnipeitPS/docs/Set-AssetOwner.md | 105 +++++++++++++++++++ SnipeitPS/docs/Set-Info.md | 75 ++++++++++++++ SnipeitPS/docs/Update-Component.md | 105 +++++++++++++++++++ 18 files changed, 1676 insertions(+), 20 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 SnipeitPS/docs/Get-Asset.md create mode 100644 SnipeitPS/docs/Get-Categories.md create mode 100644 SnipeitPS/docs/Get-Component.md create mode 100644 SnipeitPS/docs/Get-Manufacturers.md create mode 100644 SnipeitPS/docs/Get-Models.md create mode 100644 SnipeitPS/docs/Get-Status.md create mode 100644 SnipeitPS/docs/Get-Users.md create mode 100644 SnipeitPS/docs/Invoke-Method.md create mode 100644 SnipeitPS/docs/New-Asset.md create mode 100644 SnipeitPS/docs/New-Component.md create mode 100644 SnipeitPS/docs/New-Manufacturer.md create mode 100644 SnipeitPS/docs/New-Model.md create mode 100644 SnipeitPS/docs/Set-Asset.md create mode 100644 SnipeitPS/docs/Set-AssetOwner.md create mode 100644 SnipeitPS/docs/Set-Info.md create mode 100644 SnipeitPS/docs/Update-Component.md diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2472560 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Interactive Session", + "cwd": "${workspaceRoot}" + }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Pester Tests", + "script": "Invoke-Pester", + "args": [], + "cwd": "${workspaceRoot}" + }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Launch (current file)", + "script": "${file}", + "args": [], + "cwd": "${file}" + } + ] +} \ No newline at end of file diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index b798928..2e39845 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -10,15 +10,20 @@ if ($PSBoundParameters.ContainsKey('Verbose')) { if (!($env:releasePath)) { $releasePath = "$BuildRoot\Release" } -else { +elseif ($env:releasePath) { $releasePath = $env:releasePath } +else { + $releasePath = "$($pwd.Path)\Release" +} $env:PSModulePath = "$($env:PSModulePath);$releasePath" +Import-Module BuildHelpers # Ensure Invoke-Build works in the most strict mode. Set-StrictMode -Version Latest +# region debug information task ShowDebug { Write-Build Gray Write-Build Gray ('Project name: {0}' -f $env:APPVEYOR_PROJECT_NAME) @@ -42,12 +47,85 @@ task ShowDebug { Write-Build Gray } +# Synopsis: Install pandoc to .\Tools\ +task InstallPandoc -If (-not (Test-Path Tools\pandoc.exe)) { + # Setup + if (-not (Test-Path "$BuildRoot\Tools")) { + $null = New-Item -Path "$BuildRoot\Tools" -ItemType Directory + } + + # Get latest bits + $latestRelease = "https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-windows.msi" + Invoke-WebRequest -Uri $latestRelease -OutFile "$($env:temp)\pandoc.msi" + + # Extract bits + $null = New-Item -Path $env:temp\pandoc -ItemType Directory -Force + Start-Process -Wait -FilePath msiexec.exe -ArgumentList " /qn /a `"$($env:temp)\pandoc.msi`" targetdir=`"$($env:temp)\pandoc\`"" + + # Move to Tools folder + Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc.exe" -Destination "$BuildRoot\Tools\" + Copy-Item -Path "$($env:temp)\pandoc\Pandoc\pandoc-citeproc.exe" -Destination "$BuildRoot\Tools\" + + # Clean + Remove-Item -Path "$($env:temp)\pandoc" -Recurse -Force +} +# endregion + +# region test +task Test RapidTest + +# Synopsis: Using the "Fast" Test Suit +task RapidTest PesterTests +# Synopsis: Using the complete Test Suit, which includes all supported Powershell versions +task FullTest TestVersions + +# Synopsis: Warn about not empty git status if .git exists. +task GitStatus -If (Test-Path .git) { + $status = exec { git status -s } + if ($status) { + Write-Warning "Git status: $($status -join ', ')" + } +} + +task TestVersions TestPS3, TestPS4, TestPS4, TestPS5 +task TestPS3 { + exec {powershell.exe -Version 3 -NoProfile Invoke-Build PesterTests} +} +task TestPS4 { + exec {powershell.exe -Version 4 -NoProfile Invoke-Build PesterTests} +} +task TestPS5 { + exec {powershell.exe -Version 5 -NoProfile Invoke-Build PesterTests} +} + +# Synopsis: Invoke Pester Tests +task PesterTests CreateHelp, { + try { + $result = Invoke-Pester -PassThru -OutputFile "$BuildRoot\TestResult.xml" -OutputFormat "NUnitXml" + if ($env:APPVEYOR_PROJECT_NAME) { + Add-TestResultToAppveyor -TestFile "$BuildRoot\TestResult.xml" + Remove-Item "$BuildRoot\TestResult.xml" -Force + } + assert ($result.FailedCount -eq 0) "$($result.FailedCount) Pester test(s) failed." + } + catch { + throw + } +} +# endregion + # region build # Synopsis: Build shippable release -task Build GenerateRelease, UpdateManifest +task Build GenerateRelease, ConvertMarkdown, UpdateManifest + +task CreateHelp { + Import-Module platyPS -Force + New-ExternalHelp -Path "$BuildRoot\docs" -OutputPath "$BuildRoot\SnipeitPS\en-US" -Force + Remove-Module SnipeitPS, platyPS +} # Synopsis: Generate .\Release structure -task GenerateRelease { +task GenerateRelease CreateHelp, { # Setup if (-not (Test-Path "$releasePath\SnipeitPS")) { $null = New-Item -Path "$releasePath\SnipeitPS" -ItemType Directory @@ -56,26 +134,19 @@ task GenerateRelease { # Copy module Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force # Copy additional files - <#$additionalFiles = @( + $additionalFiles = @( "$BuildRoot\CHANGELOG.md" - "$BuildRoot\LICENSE" - "$BuildRoot\README.md" + #"$BuildRoot\LICENSE" + #"$BuildRoot\README.md" ) - Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force#> + Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force } # Synopsis: Update the manifest of the module task UpdateManifest GetVersion, { - $ModuleAlias = (Get-Alias | Where source -eq JiraPS) - - Remove-Module JiraPS -ErrorAction SilentlyContinue - Import-Module "$releasePath\SnipeitPS\SnipeitPS.psd1" Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $script:Version - # Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName FileList -Value (Get-ChildItem $releasePath\SnipeitPS -Recurse).Name - if ($ModuleAlias) { - Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName AliasesToExport -Value @($ModuleAlias.Name) - } - Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport ([string[]](Get-ChildItem "SnipeitPS\public\*.psm1").BaseName) + $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\Public" | ForEach-Object {$_.BaseName} + Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport } task GetVersion { @@ -96,22 +167,39 @@ task GetVersion { $newRevision } - +# Synopsis: Convert markdown files to HTML. +# +$ConvertMarkdown = @{ + Inputs = { Get-ChildItem "$releasePath\SnipeitPS\*.md" -Recurse } + Outputs = {process { + [System.IO.Path]::ChangeExtension($_, 'htm') + } + } +} +# Synopsis: Converts *.md and *.markdown files to *.htm +task ConvertMarkdown -Partial @ConvertMarkdown InstallPandoc, {process { + exec { Tools\pandoc.exe $_ --standalone --from=markdown_github "--output=$2" } + } +}, RemoveMarkdownFiles # endregion - #region Cleaning tasks task Clean RemoveGeneratedFiles + # Synopsis: Remove generated and temp files. task RemoveGeneratedFiles { $itemsToRemove = @( 'Release' '*.htm' 'TestResult.xml' + 'SnipeitPS\en-US\*' ) Remove-Item $itemsToRemove -Force -Recurse -ErrorAction 0 } +task RemoveMarkdownFiles { + Remove-Item "$releasePath\SnipeitPS\*.md" -Force -ErrorAction 0 +} +# endregion - -task . Build, Clean \ No newline at end of file +task . ShowDebug, Clean, Test, Build, Deploy \ No newline at end of file diff --git a/SnipeitPS/docs/Get-Asset.md b/SnipeitPS/docs/Get-Asset.md new file mode 100644 index 0000000..0be936a --- /dev/null +++ b/SnipeitPS/docs/Get-Asset.md @@ -0,0 +1,73 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Asset + +## SYNOPSIS +# Gets a list of Snipe-it Assets + +## SYNTAX + +``` +Get-Asset [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### -------------------------- EXAMPLE 1 -------------------------- +``` +Get-Asset -url "https://assets.dip.co.uk" -token "token..." +``` + +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } +``` + +## PARAMETERS + +### -url +URL of Snipeit system, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Categories.md b/SnipeitPS/docs/Get-Categories.md new file mode 100644 index 0000000..da7ecd7 --- /dev/null +++ b/SnipeitPS/docs/Get-Categories.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Categories + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Get-Categories [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Component.md b/SnipeitPS/docs/Get-Component.md new file mode 100644 index 0000000..d19612d --- /dev/null +++ b/SnipeitPS/docs/Get-Component.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Component + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Get-Component [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Manufacturers.md b/SnipeitPS/docs/Get-Manufacturers.md new file mode 100644 index 0000000..9e32100 --- /dev/null +++ b/SnipeitPS/docs/Get-Manufacturers.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Manufacturers + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Get-Manufacturers [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Models.md b/SnipeitPS/docs/Get-Models.md new file mode 100644 index 0000000..15880d0 --- /dev/null +++ b/SnipeitPS/docs/Get-Models.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Models + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Get-Models [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Status.md b/SnipeitPS/docs/Get-Status.md new file mode 100644 index 0000000..6eea36f --- /dev/null +++ b/SnipeitPS/docs/Get-Status.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Status + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Get-Status [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Get-Users.md b/SnipeitPS/docs/Get-Users.md new file mode 100644 index 0000000..ea1f5f9 --- /dev/null +++ b/SnipeitPS/docs/Get-Users.md @@ -0,0 +1,73 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Get-Users + +## SYNOPSIS +# Gets a list of Snipe-it Users + +## SYNTAX + +``` +Get-Users [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### -------------------------- EXAMPLE 1 -------------------------- +``` +Get-Users -url "https://assets.dip.co.uk" -token "token..." +``` + +### -------------------------- EXAMPLE 2 -------------------------- +``` +Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } +``` + +## PARAMETERS + +### -url +URL of Snipeit system, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +Users API Key for Snipeit, can be set using Set-Info command + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Invoke-Method.md b/SnipeitPS/docs/Invoke-Method.md new file mode 100644 index 0000000..94145fa --- /dev/null +++ b/SnipeitPS/docs/Invoke-Method.md @@ -0,0 +1,102 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Invoke-Method + +## SYNOPSIS +Extracted invokation of the REST method to own function. + +## SYNTAX + +``` +Invoke-Method [-URi] [[-Method] ] [[-Body] ] [[-Token] ] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -URi +REST API to invoke + +```yaml +Type: Uri +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Method +Method of the invokation + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: GET +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Body +Body of the request + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Token +{{Fill Token Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +## OUTPUTS + +### System.Management.Automation.PSObject + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/New-Asset.md b/SnipeitPS/docs/New-Asset.md new file mode 100644 index 0000000..afea065 --- /dev/null +++ b/SnipeitPS/docs/New-Asset.md @@ -0,0 +1,136 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# New-Asset + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +New-Asset [-Name] [-Status_id] [-Model_id] [-url] [-apiKey] + [[-customfields] ] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Model_id +{{Fill Model_id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +{{Fill Name Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Status_id +{{Fill Status_id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -customfields +{{Fill customfields Description}} + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/New-Component.md b/SnipeitPS/docs/New-Component.md new file mode 100644 index 0000000..811c3a3 --- /dev/null +++ b/SnipeitPS/docs/New-Component.md @@ -0,0 +1,120 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# New-Component + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +New-Component [-name] [-category_id] [-qty] [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -category_id +{{Fill category_id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -name +{{Fill name Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -qty +{{Fill qty Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/New-Manufacturer.md b/SnipeitPS/docs/New-Manufacturer.md new file mode 100644 index 0000000..743270b --- /dev/null +++ b/SnipeitPS/docs/New-Manufacturer.md @@ -0,0 +1,90 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# New-Manufacturer + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +New-Manufacturer [-Name] [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Name +{{Fill Name Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/New-Model.md b/SnipeitPS/docs/New-Model.md new file mode 100644 index 0000000..3295758 --- /dev/null +++ b/SnipeitPS/docs/New-Model.md @@ -0,0 +1,136 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# New-Model + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +New-Model [-name] [-category_id] [-manufacturer_id] [-fieldset_id] + [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -category_id +{{Fill category_id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -fieldset_id +{{Fill fieldset_id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -manufacturer_id +{{Fill manufacturer_id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -name +{{Fill name Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Set-Asset.md b/SnipeitPS/docs/Set-Asset.md new file mode 100644 index 0000000..53d4c7a --- /dev/null +++ b/SnipeitPS/docs/Set-Asset.md @@ -0,0 +1,151 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Set-Asset + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Set-Asset [-id] [-Name] [-Status_id] [-Model_id] [-url] + [-apiKey] [[-customfields] ] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Model_id +{{Fill Model_id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +{{Fill Name Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Status_id +{{Fill Status_id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -customfields +{{Fill customfields Description}} + +```yaml +Type: Hashtable +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -id +{{Fill id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 4 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Set-AssetOwner.md b/SnipeitPS/docs/Set-AssetOwner.md new file mode 100644 index 0000000..d22c8e1 --- /dev/null +++ b/SnipeitPS/docs/Set-AssetOwner.md @@ -0,0 +1,105 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Set-AssetOwner + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Set-AssetOwner [-id] [-user_id] [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -id +{{Fill id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -user_id +{{Fill user_id Description}} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Set-Info.md b/SnipeitPS/docs/Set-Info.md new file mode 100644 index 0000000..53cb63a --- /dev/null +++ b/SnipeitPS/docs/Set-Info.md @@ -0,0 +1,75 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Set-Info + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Set-Info [[-url] ] [[-apiKey] ] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: Uri +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + diff --git a/SnipeitPS/docs/Update-Component.md b/SnipeitPS/docs/Update-Component.md new file mode 100644 index 0000000..a346a1b --- /dev/null +++ b/SnipeitPS/docs/Update-Component.md @@ -0,0 +1,105 @@ +--- +external help file: SnipeItPS-help.xml +Module Name: SnipeItPS +online version: +schema: 2.0.0 +--- + +# Update-Component + +## SYNOPSIS +{{Fill in the Synopsis}} + +## SYNTAX + +``` +Update-Component [-id] [-qty] [-url] [-apiKey] +``` + +## DESCRIPTION +{{Fill in the Description}} + +## EXAMPLES + +### Example 1 +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -apiKey +{{Fill apiKey Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -id +{{Fill id Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -qty +{{Fill qty Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -url +{{Fill url Description}} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +## INPUTS + +### None + + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS + From c7b82269a9a68f35d04eecf1d673e79946e1a18c Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 19:55:09 +0000 Subject: [PATCH 02/10] load platyps --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 30792f5..f9ed78c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -41,6 +41,7 @@ install: Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null Install-Module InvokeBuild -Scope CurrentUser -Force Install-Module BuildHelpers -Scope CurrentUser -Force + Install-Module platyPS -Scope CurrentUser -Force Install-Module Pester -Scope CurrentUser -Force Install-Module PSScriptAnalyzer -Scope CurrentUser -Force $env:releasePath = "$($pwd.Path)\Release" From 845f75f28de4ca7677d30c647e0d3e29fb65f1d2 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 19:59:25 +0000 Subject: [PATCH 03/10] meh --- SnipeItPS.build.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index 2e39845..ecba2fc 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -134,12 +134,12 @@ task GenerateRelease CreateHelp, { # Copy module Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force # Copy additional files - $additionalFiles = @( - "$BuildRoot\CHANGELOG.md" + #$additionalFiles = @( + # "$BuildRoot\CHANGELOG.md" #"$BuildRoot\LICENSE" #"$BuildRoot\README.md" - ) - Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force + #) + #Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force } # Synopsis: Update the manifest of the module From d28139a5bcf4c1cd80007c3bd1a34ccffc1096f8 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 20:07:56 +0000 Subject: [PATCH 04/10] Change build --- CHANGELOG.md | 1 + Tests/SnipeItPS.Tests.ps1 | 211 +++++++++++++++--- {SnipeitPS/docs => docs}/Get-Asset.md | 0 {SnipeitPS/docs => docs}/Get-Categories.md | 0 {SnipeitPS/docs => docs}/Get-Component.md | 0 {SnipeitPS/docs => docs}/Get-Manufacturers.md | 0 {SnipeitPS/docs => docs}/Get-Models.md | 0 {SnipeitPS/docs => docs}/Get-Status.md | 0 {SnipeitPS/docs => docs}/Get-Users.md | 0 {SnipeitPS/docs => docs}/Invoke-Method.md | 0 {SnipeitPS/docs => docs}/New-Asset.md | 0 {SnipeitPS/docs => docs}/New-Component.md | 0 {SnipeitPS/docs => docs}/New-Manufacturer.md | 0 {SnipeitPS/docs => docs}/New-Model.md | 0 {SnipeitPS/docs => docs}/Set-Asset.md | 0 {SnipeitPS/docs => docs}/Set-AssetOwner.md | 0 {SnipeitPS/docs => docs}/Set-Info.md | 0 {SnipeitPS/docs => docs}/Update-Component.md | 0 18 files changed, 180 insertions(+), 32 deletions(-) create mode 100644 CHANGELOG.md rename {SnipeitPS/docs => docs}/Get-Asset.md (100%) rename {SnipeitPS/docs => docs}/Get-Categories.md (100%) rename {SnipeitPS/docs => docs}/Get-Component.md (100%) rename {SnipeitPS/docs => docs}/Get-Manufacturers.md (100%) rename {SnipeitPS/docs => docs}/Get-Models.md (100%) rename {SnipeitPS/docs => docs}/Get-Status.md (100%) rename {SnipeitPS/docs => docs}/Get-Users.md (100%) rename {SnipeitPS/docs => docs}/Invoke-Method.md (100%) rename {SnipeitPS/docs => docs}/New-Asset.md (100%) rename {SnipeitPS/docs => docs}/New-Component.md (100%) rename {SnipeitPS/docs => docs}/New-Manufacturer.md (100%) rename {SnipeitPS/docs => docs}/New-Model.md (100%) rename {SnipeitPS/docs => docs}/Set-Asset.md (100%) rename {SnipeitPS/docs => docs}/Set-AssetOwner.md (100%) rename {SnipeitPS/docs => docs}/Set-Info.md (100%) rename {SnipeitPS/docs => docs}/Update-Component.md (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e7a19a6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +[1.0] \ No newline at end of file diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index 40d25e9..f3c7f28 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -1,53 +1,200 @@ -$ModulePath = Split-Path -Path $PSScriptRoot -Parent -$ModuleName = Split-Path -Path $ModulePath -Leaf +#Requires -Modules PSScriptAnalyzer -# Make sure one or multiple versions of the module are not loaded -Get-Module -Name $ModuleName | Remove-Module +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +$projectRoot = Split-Path -Parent $here +$moduleRoot = "$projectRoot\SnipeitPS" -# Import the module and store the information about the module -$ModuleInformation = Import-Module -Name "$ModulePath\$ModuleName.psd1" -PassThru -$ModuleInformation | Format-List +$manifestFile = "$moduleRoot\SnipeitPS.psd1" +$changelogFile = "$projectRoot\CHANGELOG.md" +$appveyorFile = "$projectRoot\appveyor.yml" +$publicFunctions = "$moduleRoot\Public" +$internalFunctions = "$moduleRoot\Private" -# Get the functions present in the Manifest -$ExportedFunctions = $ModuleInformation.ExportedFunctions.Values.Name +Describe "SnipeitPS" { + Context "All required tests are present" { + # We want to make sure that every .ps1 file in the Functions directory that isn't a Pester test has an associated Pester test. + # This helps keep me honest and makes sure I'm testing my code appropriately. + It "Includes a test for each PowerShell function in the module" { + # Get-ChildItem -Path $publicFunctions -Filter "*.ps1" -Recurse | Where-Object -FilterScript {$_.Name -notlike '*.Tests.ps1'} | % { + # $expectedTestFile = Join-Path $projectRoot "Tests\$($_.BaseName).Tests.ps1" + # $expectedTestFile | Should Exist + # } + } + } -# Get the functions present in the Public folder -$PS1Functions = Get-ChildItem -Path "$ModulePath\Public\*.ps1" + Context "Manifest, changelog, and AppVeyor" { -Describe "$ModuleName Module - Testing Manifest File (.psd1)" { - Context "Manifest" { - It "Should contain RootModule" { - $ModuleInformation.RootModule | Should Not BeNullOrEmpty + # These tests are...erm, borrowed...from the module tests from the Pester module. + # I think they are excellent for sanity checking, and all credit for the following + # tests goes to Dave Wyatt, the genius behind Pester. I've just adapted them + # slightly to match SnipeitPS. + + $script:manifest = $null + + foreach ($line in (Get-Content $changelogFile)) { + if ($line -match "^\D*(?(\d+\.){1,3}\d+)") { + $changelogVersion = $matches.Version + break + } } - It "Should contain ModuleVersion" { - $ModuleInformation.Version | Should Not BeNullOrEmpty + foreach ($line in (Get-Content $appveyorFile)) { + # (?()) - non-capturing group, but named Version. This makes it + # easy to reference the inside group later. + + if ($line -match '^\D*(?(\d+\.){1,3}\d+).\{build\}') { + $appveyorVersion = $matches.Version + break + } } - It "Should contain GUID" { - $ModuleInformation.Guid | Should Not BeNullOrEmpty + It "Includes a valid manifest file" { + { + $script:manifest = Test-ModuleManifest -Path $script:manifestFile -ErrorAction Stop -WarningAction SilentlyContinue + } | Should Not Throw } - It "Should contain Author" { - $ModuleInformation.Author | Should Not BeNullOrEmpty + # There is a bug that prevents Test-ModuleManifest from updating correctly when the manifest file changes. See here: + # https://connect.microsoft.com/PowerShell/feedback/details/1541659/test-modulemanifest-the-psmoduleinfo-is-not-updated + + # As a temp workaround, we'll just read the manifest as a raw hashtable. + # Credit to this workaround comes from here: + # https://psescape.azurewebsites.net/pester-testing-your-module-manifest/ + $script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) + + It "Manifest file includes the correct root module" { + $script:manifest.RootModule | Should Be 'SnipeitPS.psm1' } - It "Should contain Description" { - $ModuleInformation.Description | Should Not BeNullOrEmpty + It "Manifest file includes the correct guid" { + $script:manifest.Guid | Should Be 'f86f4db4-1cb1-45c4-b7bf-6762531bfdeb' } - It "Compare the count of Function Exported and the PS1 files found" { - $status = $ExportedFunctions.Count -eq $PS1Functions.Count - $status | Should Be $true + It "Manifest file includes a valid version" { + # $script:manifest.Version -as [Version] | Should Not BeNullOrEmpty + $script:manifest.ModuleVersion -as [Version] | Should Not BeNullOrEmpty } - It "Compare the missing function" { - If ($ExportedFunctions.count -ne $PS1Functions.count) { - $Compare = Compare-Object -ReferenceObject $ExportedFunctions -DifferenceObject $PS1Functions.Basename - $Compare.InputObject -Join ',' | Should BeNullOrEmpty + It "Includes a changelog file" { + $changelogFile | Should Exist + } + + # $changelogVersion = $null + It "Changelog includes a valid version number" { + $changelogVersion | Should Not BeNullOrEmpty + $changelogVersion -as [Version] | Should Not BeNullOrEmpty + } + + It "Changelog version matches manifest version" { + $changelogVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) + } + + # Back to me! Pester doesn't use AppVeyor, as far as I know, and I do. + + It "Includes an appveyor.yml file" { + $appveyorFile | Should Exist + } + + It "Appveyor.yml file includes the module version" { + $appveyorVersion | Should Not BeNullOrEmpty + $appveyorVersion -as [Version] | Should Not BeNullOrEmpty + } + + It "Appveyor version matches manifest version" { + $appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) + } + } + + # The CI changes I'm testng now will render this section obsolete, + # as it should automatically patch the module manifest file with all + # exported function names. + # Leaving the code here for the moment while I can ensure those + # features are working correctly. + + # + # Context "Function checking" { + # $functionFiles = Get-ChildItem $publicFunctions -Filter *.ps1 | + # Select-Object -ExpandProperty BaseName | + # Where-Object { $_ -notlike "*.Tests" } + + # $internalFiles = Get-ChildItem $internalFunctions -Filter *.ps1 | + # Select-Object -ExpandProperty BaseName | + # Where-Object { $_ -notlike "*.Tests" } + + # #$exportedFunctions = $script:manifest.ExportedFunctions.Values.Name + # $exportedFunctions = $script:manifest.FunctionsToExport + + # foreach ($f in $functionFiles) { + # It "Exports $f" { + # $exportedFunctions -contains $f | Should Be $true + # } + # } + + # foreach ($f in $internalFiles) { + # It "Does not export $f" { + # $exportedFunctions -contains $f | Should Be $false + # } + # } + # } + + Context "Style checking" { + + # This section is again from the mastermind, Dave Wyatt. Again, credit + # goes to him for these tests. + + $files = @( + Get-ChildItem $here -Include *.ps1, *.psm1 + Get-ChildItem $publicFunctions -Include *.ps1, *.psm1 -Recurse + ) + + It 'Source files contain no trailing whitespace' { + $badLines = @( + foreach ($file in $files) { + $lines = [System.IO.File]::ReadAllLines($file.FullName) + $lineCount = $lines.Count + + for ($i = 0; $i -lt $lineCount; $i++) { + if ($lines[$i] -match '\s+$') { + 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) + } + } + } + ) + + if ($badLines.Count -gt 0) { + throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" + } + } + + It 'Source files all end with a newline' { + $badFiles = @( + foreach ($file in $files) { + $string = [System.IO.File]::ReadAllText($file.FullName) + if ($string.Length -gt 0 -and $string[-1] -ne "`n") { + $file.FullName + } + } + ) + + if ($badFiles.Count -gt 0) { + throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" } } } -} -Get-Module -Name $ModuleName | Remove-Module \ No newline at end of file + Context 'PSScriptAnalyzer Rules' { + $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse + $scriptAnalyzerRules = Get-ScriptAnalyzerRule + + forEach ($rule in $scriptAnalyzerRules) { + It "Should pass $rule" { + If (($analysis) -and ($analysis.RuleName -contains $rule)) { + $analysis | + Where RuleName -EQ $rule -OutVariable failures | + Out-Default + $failures.Count | Should Be 0 + } + } + } + } +} \ No newline at end of file diff --git a/SnipeitPS/docs/Get-Asset.md b/docs/Get-Asset.md similarity index 100% rename from SnipeitPS/docs/Get-Asset.md rename to docs/Get-Asset.md diff --git a/SnipeitPS/docs/Get-Categories.md b/docs/Get-Categories.md similarity index 100% rename from SnipeitPS/docs/Get-Categories.md rename to docs/Get-Categories.md diff --git a/SnipeitPS/docs/Get-Component.md b/docs/Get-Component.md similarity index 100% rename from SnipeitPS/docs/Get-Component.md rename to docs/Get-Component.md diff --git a/SnipeitPS/docs/Get-Manufacturers.md b/docs/Get-Manufacturers.md similarity index 100% rename from SnipeitPS/docs/Get-Manufacturers.md rename to docs/Get-Manufacturers.md diff --git a/SnipeitPS/docs/Get-Models.md b/docs/Get-Models.md similarity index 100% rename from SnipeitPS/docs/Get-Models.md rename to docs/Get-Models.md diff --git a/SnipeitPS/docs/Get-Status.md b/docs/Get-Status.md similarity index 100% rename from SnipeitPS/docs/Get-Status.md rename to docs/Get-Status.md diff --git a/SnipeitPS/docs/Get-Users.md b/docs/Get-Users.md similarity index 100% rename from SnipeitPS/docs/Get-Users.md rename to docs/Get-Users.md diff --git a/SnipeitPS/docs/Invoke-Method.md b/docs/Invoke-Method.md similarity index 100% rename from SnipeitPS/docs/Invoke-Method.md rename to docs/Invoke-Method.md diff --git a/SnipeitPS/docs/New-Asset.md b/docs/New-Asset.md similarity index 100% rename from SnipeitPS/docs/New-Asset.md rename to docs/New-Asset.md diff --git a/SnipeitPS/docs/New-Component.md b/docs/New-Component.md similarity index 100% rename from SnipeitPS/docs/New-Component.md rename to docs/New-Component.md diff --git a/SnipeitPS/docs/New-Manufacturer.md b/docs/New-Manufacturer.md similarity index 100% rename from SnipeitPS/docs/New-Manufacturer.md rename to docs/New-Manufacturer.md diff --git a/SnipeitPS/docs/New-Model.md b/docs/New-Model.md similarity index 100% rename from SnipeitPS/docs/New-Model.md rename to docs/New-Model.md diff --git a/SnipeitPS/docs/Set-Asset.md b/docs/Set-Asset.md similarity index 100% rename from SnipeitPS/docs/Set-Asset.md rename to docs/Set-Asset.md diff --git a/SnipeitPS/docs/Set-AssetOwner.md b/docs/Set-AssetOwner.md similarity index 100% rename from SnipeitPS/docs/Set-AssetOwner.md rename to docs/Set-AssetOwner.md diff --git a/SnipeitPS/docs/Set-Info.md b/docs/Set-Info.md similarity index 100% rename from SnipeitPS/docs/Set-Info.md rename to docs/Set-Info.md diff --git a/SnipeitPS/docs/Update-Component.md b/docs/Update-Component.md similarity index 100% rename from SnipeitPS/docs/Update-Component.md rename to docs/Update-Component.md From 47b174dfa0f063d3500c850e152b09ef48715635 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 21:06:20 +0000 Subject: [PATCH 05/10] Pester checks --- SnipeitPS/Public/Assets.psm1 | 107 ++++++++++++++++++---------- SnipeitPS/Public/Categories.psm1 | 8 +-- SnipeitPS/Public/Components.psm1 | 70 +++++++++++------- SnipeitPS/Public/Manufacturers.psm1 | 39 ++++++---- SnipeitPS/Public/Models.psm1 | 41 +++++++---- SnipeitPS/Public/Set-Info.psm1 | 2 +- SnipeitPS/Public/Status.psm1 | 8 +-- SnipeitPS/Public/Users.psm1 | 10 +-- SnipeitPS/SnipeItPS.psd1 | Bin 7874 -> 8482 bytes Tests/SnipeItPS.Tests.ps1 | 2 +- 10 files changed, 182 insertions(+), 105 deletions(-) diff --git a/SnipeitPS/Public/Assets.psm1 b/SnipeitPS/Public/Assets.psm1 index 8b695f6..e8d0e75 100644 --- a/SnipeitPS/Public/Assets.psm1 +++ b/SnipeitPS/Public/Assets.psm1 @@ -9,7 +9,7 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Asset -url "https://assets.dip.co.uk" -token "token..." +Get-Asset -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" } @@ -18,11 +18,11 @@ Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.n function Get-Asset() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -35,20 +35,25 @@ function Get-Asset() function New-Asset() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$Name, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -64,33 +69,44 @@ function New-Asset() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/hardware" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/hardware" + Method = 'Post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } function Set-Asset() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Status_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$Model_id, - - [parameter(mandatory=$true)] + + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey, [hashtable] $customfields @@ -105,27 +121,38 @@ function Set-Asset() $Values += $customfields $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/hardware/$id" ` - -Method PUT ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } function Set-AssetOwner() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [int]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$user_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -135,10 +162,16 @@ function Set-AssetOwner() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -Uri "$url/api/v1/hardware/$id/checkout" ` - -Method POST ` - -Token $apiKey ` - -Body $Body + $Parameters = @{ + Uri = "$url/api/v1/hardware/$id/checkout" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } return $result } diff --git a/SnipeitPS/Public/Categories.psm1 b/SnipeitPS/Public/Categories.psm1 index 31fc78a..c80cb3d 100644 --- a/SnipeitPS/Public/Categories.psm1 +++ b/SnipeitPS/Public/Categories.psm1 @@ -1,10 +1,10 @@ -function Get-Categories() +function Get-Category() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/SnipeitPS/Public/Components.psm1 b/SnipeitPS/Public/Components.psm1 index 1b2e785..28fe70f 100644 --- a/SnipeitPS/Public/Components.psm1 +++ b/SnipeitPS/Public/Components.psm1 @@ -1,10 +1,10 @@ function Get-Component() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,20 +17,25 @@ function Get-Component() function New-Component() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -42,27 +47,38 @@ function New-Component() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/components" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/components" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } -function Update-Component() +function Set-Component() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$qty, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -72,10 +88,16 @@ function Update-Component() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/components/$component_id" ` - -Method Patch ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/components/$component_id" + Method = 'Patch' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result } @@ -99,4 +121,4 @@ function Checkout-Component($component_id, $asset_id = "") -UserAgent "DI Script/0.1" return $Manufacturers -}#> \ No newline at end of file +}#> diff --git a/SnipeitPS/Public/Manufacturers.psm1 b/SnipeitPS/Public/Manufacturers.psm1 index 410c5bd..0fa234d 100644 --- a/SnipeitPS/Public/Manufacturers.psm1 +++ b/SnipeitPS/Public/Manufacturers.psm1 @@ -1,10 +1,10 @@ -function Get-Manufacturers() +function Get-Manufacturer() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -17,14 +17,19 @@ function Get-Manufacturers() function New-Manufacturer() { - Param( - [parameter(mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + + Param( + [parameter(mandatory=$true)] [string]$Name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -36,10 +41,16 @@ function New-Manufacturer() #Convert Values to JSON format $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/manufacturers" ` - -Method POST ` - -Body $Body ` - -Token $apiKey - + $Parameters = @{ + Uri = "$url/api/v1/manufacturers" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } + $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Models.psm1 b/SnipeitPS/Public/Models.psm1 index b7e39b7..caa093e 100644 --- a/SnipeitPS/Public/Models.psm1 +++ b/SnipeitPS/Public/Models.psm1 @@ -1,11 +1,11 @@ -function Get-Models() +function Get-Model() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -19,23 +19,28 @@ function Get-Models() function New-Model() { + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High" + )] + Param( - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$name, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$category_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$manufacturer_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [int]$fieldset_id, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -48,10 +53,16 @@ function New-Model() $Body = $Values | ConvertTo-Json; - $result = Invoke-Method -URi "$url/api/v1/models" ` - -Method POST ` - -Body $Body ` - -Token $apiKey + $Parameters = @{ + Uri = "$url/api/v1/models" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess()) { + $result = Invoke-Method @Parameters + } $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Set-Info.psm1 b/SnipeitPS/Public/Set-Info.psm1 index 3307a01..a0ef88e 100644 --- a/SnipeitPS/Public/Set-Info.psm1 +++ b/SnipeitPS/Public/Set-Info.psm1 @@ -47,4 +47,4 @@ function Set-Info { } } } -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Status.psm1 b/SnipeitPS/Public/Status.psm1 index 3a4887a..95141f3 100644 --- a/SnipeitPS/Public/Status.psm1 +++ b/SnipeitPS/Public/Status.psm1 @@ -1,10 +1,10 @@ function Get-Status() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) @@ -13,4 +13,4 @@ function Get-Status() -Token $apiKey $result -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/Users.psm1 b/SnipeitPS/Public/Users.psm1 index c2b3cee..e1017d3 100644 --- a/SnipeitPS/Public/Users.psm1 +++ b/SnipeitPS/Public/Users.psm1 @@ -9,19 +9,19 @@ URL of Snipeit system, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE -Get-Users -url "https://assets.dip.co.uk" -token "token..." +Get-Users -url "https://assets.dip.co.uk" -token "token..." .EXAMPLE Get-Users -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.username -eq "stephenm" } #> -function Get-Users() +function Get-User() { - Param( - [parameter(mandatory=$true)] + Param( + [parameter(mandatory=$true)] [string]$url, - [parameter(mandatory=$true)] + [parameter(mandatory=$true)] [string]$apiKey ) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index c4b382c6c74e6d954799e430b31233f0eca57e09..76d510ddf8c2c61d91dd66af56b8bc3b92fbf3ae 100644 GIT binary patch delta 630 zcmX?PyU1xnj8MG;g9ZaH0~dn=6sj}0Go&( zmEltiQVa7HF=}DX^#wXNkD-(y4M-;golpvNG}MFjI06=r7Bn3QOY#{~fX3!v2@RMB zeSscCRg;N`cbLySfo@F$D#VO+m{q|*KY${j6qr76s|p3D9#Axb(wFAuM4?0;00bIW A9RL6T delta 16 XcmZ4FbjWr?jL>8U38BsBL_&A~IFSYP diff --git a/Tests/SnipeItPS.Tests.ps1 b/Tests/SnipeItPS.Tests.ps1 index f3c7f28..b5a77b3 100644 --- a/Tests/SnipeItPS.Tests.ps1 +++ b/Tests/SnipeItPS.Tests.ps1 @@ -63,7 +63,7 @@ Describe "SnipeitPS" { $script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) It "Manifest file includes the correct root module" { - $script:manifest.RootModule | Should Be 'SnipeitPS.psm1' + $script:manifest.RootModule | Should Be 'SnipeitPS' } It "Manifest file includes the correct guid" { From cf8c474ba8cfeda9f30eb770ce34fb1c56203f2b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 21:41:35 +0000 Subject: [PATCH 06/10] Update docs --- appveyor.yml | 19 +++- docs/{Get-Categories.md => Get-Category.md} | 4 +- ...t-Manufacturers.md => Get-Manufacturer.md} | 4 +- docs/{Get-Models.md => Get-Model.md} | 4 +- docs/{Get-Users.md => Get-User.md} | 4 +- docs/Invoke-Method.md | 102 ------------------ docs/New-Asset.md | 33 +++++- docs/New-Component.md | 32 ++++++ docs/New-Manufacturer.md | 33 +++++- docs/New-Model.md | 33 +++++- docs/Set-Asset.md | 33 +++++- docs/Set-AssetOwner.md | 33 +++++- .../{Update-Component.md => Set-Component.md} | 35 +++++- 13 files changed, 250 insertions(+), 119 deletions(-) rename docs/{Get-Categories.md => Get-Category.md} (92%) rename docs/{Get-Manufacturers.md => Get-Manufacturer.md} (91%) rename docs/{Get-Models.md => Get-Model.md} (93%) rename docs/{Get-Users.md => Get-User.md} (95%) delete mode 100644 docs/Invoke-Method.md rename docs/{Update-Component.md => Set-Component.md} (65%) diff --git a/appveyor.yml b/appveyor.yml index f9ed78c..c16c57c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,8 +10,9 @@ # This tells AppVeyor that we need WMF 5 and PowerShell 5.0 os: WMF 5 -#environment: - # To encrypt a value in AppVeyor, go to the Account menu and choose "Encrypt data" +environment: + PSGalleryAPIKey: + secure: UdM6qhf5B0G8liHhUrwWERCZr44iSqmg4jUq0lwlTjZs4KyeoiwnBzdej0phqIAm version: 1.0.{build} @@ -58,3 +59,17 @@ build_script: test_script: - ps: Invoke-Build -Task Test +before_deploy: + - ps: Invoke-Build -Task Deploy + +deploy: + provider: GitHub + release: v$(appveyor_build_version) + description: '' + auth_token: + secure: m72Ke3nJcSxZkc36UwRIw+q0NtNvERfQYHZUBNDvLP/kjW+mWmVueR6tmgBujyBM + draft: false + prerelease: false + on: + branch: master # release from master branch only + appveyor_repo_tag: false # deploy on tag push only \ No newline at end of file diff --git a/docs/Get-Categories.md b/docs/Get-Category.md similarity index 92% rename from docs/Get-Categories.md rename to docs/Get-Category.md index da7ecd7..bbbca5a 100644 --- a/docs/Get-Categories.md +++ b/docs/Get-Category.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Get-Categories +# Get-Category ## SYNOPSIS {{Fill in the Synopsis}} @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Get-Categories [-url] [-apiKey] +Get-Category [-url] [-apiKey] ``` ## DESCRIPTION diff --git a/docs/Get-Manufacturers.md b/docs/Get-Manufacturer.md similarity index 91% rename from docs/Get-Manufacturers.md rename to docs/Get-Manufacturer.md index 9e32100..f29d362 100644 --- a/docs/Get-Manufacturers.md +++ b/docs/Get-Manufacturer.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Get-Manufacturers +# Get-Manufacturer ## SYNOPSIS {{Fill in the Synopsis}} @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Get-Manufacturers [-url] [-apiKey] +Get-Manufacturer [-url] [-apiKey] ``` ## DESCRIPTION diff --git a/docs/Get-Models.md b/docs/Get-Model.md similarity index 93% rename from docs/Get-Models.md rename to docs/Get-Model.md index 15880d0..215ba79 100644 --- a/docs/Get-Models.md +++ b/docs/Get-Model.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Get-Models +# Get-Model ## SYNOPSIS {{Fill in the Synopsis}} @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Get-Models [-url] [-apiKey] +Get-Model [-url] [-apiKey] ``` ## DESCRIPTION diff --git a/docs/Get-Users.md b/docs/Get-User.md similarity index 95% rename from docs/Get-Users.md rename to docs/Get-User.md index ea1f5f9..31ccdb6 100644 --- a/docs/Get-Users.md +++ b/docs/Get-User.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Get-Users +# Get-User ## SYNOPSIS # Gets a list of Snipe-it Users @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Get-Users [-url] [-apiKey] +Get-User [-url] [-apiKey] ``` ## DESCRIPTION diff --git a/docs/Invoke-Method.md b/docs/Invoke-Method.md deleted file mode 100644 index 94145fa..0000000 --- a/docs/Invoke-Method.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -external help file: SnipeItPS-help.xml -Module Name: SnipeItPS -online version: -schema: 2.0.0 ---- - -# Invoke-Method - -## SYNOPSIS -Extracted invokation of the REST method to own function. - -## SYNTAX - -``` -Invoke-Method [-URi] [[-Method] ] [[-Body] ] [[-Token] ] -``` - -## DESCRIPTION -{{Fill in the Description}} - -## EXAMPLES - -### Example 1 -``` -PS C:\> {{ Add example code here }} -``` - -{{ Add example description here }} - -## PARAMETERS - -### -URi -REST API to invoke - -```yaml -Type: Uri -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Method -Method of the invokation - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 2 -Default value: GET -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Body -Body of the request - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 3 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Token -{{Fill Token Description}} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 4 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -## INPUTS - -## OUTPUTS - -### System.Management.Automation.PSObject - -## NOTES - -## RELATED LINKS - diff --git a/docs/New-Asset.md b/docs/New-Asset.md index afea065..30fbb22 100644 --- a/docs/New-Asset.md +++ b/docs/New-Asset.md @@ -14,7 +14,7 @@ schema: 2.0.0 ``` New-Asset [-Name] [-Status_id] [-Model_id] [-url] [-apiKey] - [[-customfields] ] + [[-customfields] ] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -31,6 +31,21 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Model_id {{Fill Model_id Description}} @@ -76,6 +91,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/New-Component.md b/docs/New-Component.md index 811c3a3..8d4bba7 100644 --- a/docs/New-Component.md +++ b/docs/New-Component.md @@ -14,6 +14,7 @@ schema: 2.0.0 ``` New-Component [-name] [-category_id] [-qty] [-url] [-apiKey] + [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -30,6 +31,37 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/New-Manufacturer.md b/docs/New-Manufacturer.md index 743270b..5616130 100644 --- a/docs/New-Manufacturer.md +++ b/docs/New-Manufacturer.md @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -New-Manufacturer [-Name] [-url] [-apiKey] +New-Manufacturer [-Name] [-url] [-apiKey] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -30,6 +30,21 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Name {{Fill Name Description}} @@ -45,6 +60,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/New-Model.md b/docs/New-Model.md index 3295758..06b064b 100644 --- a/docs/New-Model.md +++ b/docs/New-Model.md @@ -14,7 +14,7 @@ schema: 2.0.0 ``` New-Model [-name] [-category_id] [-manufacturer_id] [-fieldset_id] - [-url] [-apiKey] + [-url] [-apiKey] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -31,6 +31,37 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/Set-Asset.md b/docs/Set-Asset.md index 53d4c7a..d578e3b 100644 --- a/docs/Set-Asset.md +++ b/docs/Set-Asset.md @@ -14,7 +14,7 @@ schema: 2.0.0 ``` Set-Asset [-id] [-Name] [-Status_id] [-Model_id] [-url] - [-apiKey] [[-customfields] ] + [-apiKey] [[-customfields] ] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -31,6 +31,21 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Model_id {{Fill Model_id Description}} @@ -76,6 +91,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/Set-AssetOwner.md b/docs/Set-AssetOwner.md index d22c8e1..1e3b9f2 100644 --- a/docs/Set-AssetOwner.md +++ b/docs/Set-AssetOwner.md @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Set-AssetOwner [-id] [-user_id] [-url] [-apiKey] +Set-AssetOwner [-id] [-user_id] [-url] [-apiKey] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -30,6 +30,37 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} diff --git a/docs/Update-Component.md b/docs/Set-Component.md similarity index 65% rename from docs/Update-Component.md rename to docs/Set-Component.md index a346a1b..79a41d0 100644 --- a/docs/Update-Component.md +++ b/docs/Set-Component.md @@ -5,7 +5,7 @@ online version: schema: 2.0.0 --- -# Update-Component +# Set-Component ## SYNOPSIS {{Fill in the Synopsis}} @@ -13,7 +13,7 @@ schema: 2.0.0 ## SYNTAX ``` -Update-Component [-id] [-qty] [-url] [-apiKey] +Set-Component [-id] [-qty] [-url] [-apiKey] [-WhatIf] [-Confirm] ``` ## DESCRIPTION @@ -30,6 +30,37 @@ PS C:\> {{ Add example code here }} ## PARAMETERS +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -apiKey {{Fill apiKey Description}} From 8e6ff8691b2ab2d15264354cd13395d2c0050b03 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 21:46:51 +0000 Subject: [PATCH 07/10] Should deploy now --- README.md | 1 + SnipeItPS.build.ps1 | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b365a91 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +[![Build status](https://ci.appveyor.com/api/projects/status/dvuw4ggx543nx3h7?svg=true)](https://ci.appveyor.com/project/snazy2000/snipeitps) \ No newline at end of file diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index ecba2fc..4ae94e4 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -134,12 +134,12 @@ task GenerateRelease CreateHelp, { # Copy module Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force # Copy additional files - #$additionalFiles = @( - # "$BuildRoot\CHANGELOG.md" + $additionalFiles = @( + "$BuildRoot\CHANGELOG.md" #"$BuildRoot\LICENSE" - #"$BuildRoot\README.md" - #) - #Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force + "$BuildRoot\README.md" + ) + Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force } # Synopsis: Update the manifest of the module @@ -183,6 +183,40 @@ task ConvertMarkdown -Partial @ConvertMarkdown InstallPandoc, {process { }, RemoveMarkdownFiles # endregion +# region publish +task Deploy -If ( + # Only deploy if the master branch changes + $env:APPVEYOR_REPO_BRANCH -eq 'master' -and + # Do not deploy if this is a pull request (because it hasn't been approved yet) + (-not ($env:APPVEYOR_PULL_REQUEST_NUMBER)) -and + # Do not deploy if the commit contains the string "skip-deploy" + # Meant for major/minor version publishes with a .0 build/patch version (like 2.1.0) + $env:APPVEYOR_REPO_COMMIT_MESSAGE -notlike '*skip-deploy*' +) { + Remove-Module SnipeitPS -ErrorAction SilentlyContinue +}, PublishToGallery + +task PublishToGallery { + assert ($env:PSGalleryAPIKey) "No key for the PSGallery" + + Import-Module $releasePath\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop + Publish-Module -Name SnipeitPS -NuGetApiKey $env:PSGalleryAPIKey +} + +# Synopsis: Push with a version tag. +task PushRelease GitStatus, GetVersion, { + # Done in appveyor.yml with deploy provider. + # This is needed, as I don't know how to athenticate (2-factor) in here. + exec { git checkout master } + $changes = exec { git status --short } + assert (!$changes) "Please, commit changes." + + exec { git push } + exec { git tag -a "v$Version" -m "v$Version" } + exec { git push origin "v$Version" } +} +# endregion + #region Cleaning tasks task Clean RemoveGeneratedFiles From f3b16e443cd9113010b78ece23f801ce6d98a3e7 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 21:54:46 +0000 Subject: [PATCH 08/10] Added license --- LICENSE | 21 +++++++++++++++++++++ SnipeItPS.build.ps1 | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2894d0f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Brian Bunke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index 4ae94e4..d68fb60 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -136,7 +136,7 @@ task GenerateRelease CreateHelp, { # Copy additional files $additionalFiles = @( "$BuildRoot\CHANGELOG.md" - #"$BuildRoot\LICENSE" + "$BuildRoot\LICENSE" "$BuildRoot\README.md" ) Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force From 7d48974996914a555008b9a7cc83b4acd2a4fdc9 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 22:28:44 +0000 Subject: [PATCH 09/10] Add parameters to Invoke-Method --- SnipeitPS/Private/ConvertTo-GetParameter.ps1 | 25 ++++++++++++++++++++ SnipeitPS/Private/Invoke-Method.psm1 | 14 ++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 SnipeitPS/Private/ConvertTo-GetParameter.ps1 diff --git a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 new file mode 100644 index 0000000..7afd8c9 --- /dev/null +++ b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 @@ -0,0 +1,25 @@ +function ConvertTo-GetParameter { + <# + .SYNOPSIS + Generate the GET parameter string for an URL from a hashtable + #> + [CmdletBinding()] + param ( + [Parameter( Position = 0, Mandatory = $true, ValueFromPipeline = $true )] + [hashtable]$InputObject + ) + + BEGIN { + [string]$parameters = "?" + } + + PROCESS { + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable" + foreach ($key in $InputObject.Keys) { + $parameters += "$key=$($InputObject[$key])&" + } + } + + END { + $parameters -replace ".$" + } \ No newline at end of file diff --git a/SnipeitPS/Private/Invoke-Method.psm1 b/SnipeitPS/Private/Invoke-Method.psm1 index ab49489..a5188a4 100644 --- a/SnipeitPS/Private/Invoke-Method.psm1 +++ b/SnipeitPS/Private/Invoke-Method.psm1 @@ -19,7 +19,11 @@ [ValidateNotNullOrEmpty()] [string]$Body, - [string] $Token + [string] $Token, + + # GET Parameters + [Hashtable]$GetParameters + ) BEGIN { @@ -38,6 +42,14 @@ } Process { + if ($GetParameters -and ($URi -notlike "*\?*")) + { + Write-Debug "Using `$GetParameters: $($GetParameters | Out-String)" + [string]$URI += (ConvertTo-GetParameter $GetParameters) + # Prevent recursive appends + $GetParameters = $null + } + # set mandatory parameters $splatParameters = @{ Uri = $URi From 13ec3a62ac71275ec2bbe0bbf993130e9f53589f Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 18 Nov 2017 22:34:55 +0000 Subject: [PATCH 10/10] fix stupid code... --- SnipeitPS/Private/ConvertTo-GetParameter.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 index 7afd8c9..e0f31c9 100644 --- a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 +++ b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 @@ -22,4 +22,5 @@ function ConvertTo-GetParameter { END { $parameters -replace ".$" - } \ No newline at end of file + } +} \ No newline at end of file