Skip to content

Commit

Permalink
Renamed module to PSServiceNow from ServiceNow-Module
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Martin committed May 4, 2015
1 parent 3096b09 commit ddc1cf0
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ServiceNow-Module.Pester.Defaults.json
*.zip
PSServiceNow.Pester.Defaults.json
83 changes: 83 additions & 0 deletions MAKE.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function ZipFiles
{
param( $zipfilename, $sourcedir )
Add-Type -Assembly System.IO.Compression.FileSystem
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
$zipfilename, $compressionLevel, $true)
}

function New-MakePackage{
param(
[string[]]$PackageFilePatternExclusions,
[string]$PackageName,
[string]$ModuleName
)
($FilePatternExclusions | %{"MAKE.zip" -match $_}).contains($true)

$FilesToInclude = Get-ChildItem -Path $here | ?{
$File=$_;
!$_.PSIsContainer -and
!($PackageFilePatternExclusions | %{$File.Name -match $_}).contains($true)
}

# Create temporary folder and copy the files we want into it
New-Item $here\$ModuleName -ItemType Container -Force | Out-Null
$FilesToInclude | %{Copy-Item -Path $_.FullName -Destination $here\$ModuleName\$_ -Force}

# Create a zip based on that folder (overwriting it if it already exists)
$ZipFile = "$here\$PackageName"
Remove-Item $ZipFile -Force -ErrorAction SilentlyContinue | Out-Null
ZipFiles $ZipFile $here\$ModuleName
Remove-Item $here\$ModuleName -Recurse| Out-Null
}

Function Update-CodeCoveragePercent{
param(
[int]$CodeCoverage=0,
[string]$TextFilePath="$here\Readme.md"
)
$ReadmeContent = Get-Content $TextFilePath
$ReadmeContent = $ReadmeContent | %{$_-replace "!\[Test Coverage\].+\)", "![Test Coverage](https://img.shields.io/badge/coverage-$CodeCoverage%25-yellowgreen.svg)"}
Set-Content -Path $TextFilePath -Value $ReadmeContent
}

Function UpdateManifest{
param(
[string]$ManifestPath,
[string]$Version
)

Write-Verbose "Updating $ManifestPath to version $Version"
$ManifestContent = Get-Content $ManifestPath
$ManifestContent = $ManifestContent | %{$_ -replace "ModuleVersion = '(\d|\.)+'", "ModuleVersion = '$Version'"}
Set-Content -path $ManifestPath -Value $ManifestContent
}

$PackageFilePatternExclusions = @(
"MAKE\.ps1",
".+\.zip",
".+\.md"
".+\.Tests\.ps1",
"\.gitignore",
"LICENSE",
".+\.Pester.Defaults.json"
)

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

$Version = "0.1.1"
$ModuleName = "PSServiceNow"
$PackageName = "$ModuleName-v$($version).zip";

# Perform Pester tests
$TestResult = Invoke-Pester -CodeCoverage '*.psm1' -PassThru
$CoveragePercent = 100-(($testResult.CodeCoverage.NumberOfCommandsMissed/$testResult.CodeCoverage.NumberOfCommandsAnalyzed)*100)

# Update/Create the package and
if($TestResult.FailedCount -eq 0){
New-MakePackage -PackageFilePatternExclusions $PackageFilePatternExclusions -PackageName $PackageName -ModuleName $ModuleName
Update-CodeCoveragePercent -CodeCoverage $CoveragePercent
UpdateManifest -ManifestPath "$here\$ModuleName.psd1" -Version $Version
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions ServiceNow-Module.Tests.ps1 → PSServiceNow.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$DefaultsFile = "$here\ServiceNow-Module.Pester.Defaults.json"
$DefaultsFile = "$here\PSServiceNow.Pester.Defaults.json"

# Load defaults from file (merging into $global:ServiceNowPesterTestDefaults
if(Test-Path $DefaultsFile){
Expand All @@ -23,8 +23,8 @@ if(Test-Path $DefaultsFile){
}

# Load the module (unload it first in case we've made changes since loading it previously)
Remove-Module ServiceNow-Module -ErrorAction SilentlyContinue
Import-Module $here\ServiceNow-Module.psd1
Remove-Module PSServiceNow -ErrorAction SilentlyContinue
Import-Module $here\PSServiceNow.psd1

Describe "ServiceNow-Module" {

Expand Down
92 changes: 92 additions & 0 deletions PSServiceNow.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# Module manifest for module 'PSServiceNow'
#
# Generated by: Sam Martin
#
# Generated on: 03/05/2015
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'PSServiceNow.psm1'

# Version number of this module.
ModuleVersion = '0.1.1'

# ID used to uniquely identify this module
GUID = 'b90d67da-f8d0-4406-ad74-89d169cd0633'

# Author of this module
Author = 'Sam Martin'

# Company or vendor of this module
CompanyName = 'None'

# Copyright statement for this module
Copyright = '(c) 2015 Sam. All rights reserved.'

# Description of the functionality provided by this module
# Description = 'This module provides cmdlets allowing you to retrieve information from your ServiceNow instance`s rest API'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = '3.0'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = 'None'

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @(
'PSServiceNow-Tables.psm1',
'PSServiceNow-Incidents.psm1',
'PSServiceNow-Users.psm1',
'PSServiceNow-ConfigurationManagement.psm1'
)

# Functions to export from this module
FunctionsToExport = '*'

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''

# HelpInfo URI of this module
# HelpInfoURI = 'https://github.com/Toukakoukan/servicenow-powershell'

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

File renamed without changes.
10 changes: 5 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# servicenow-powershell
[![GitHub release](https://img.shields.io/github/release/Toukakoukan/servicenow-powershell.svg)](releases/latest) [![GitHub license](https://img.shields.io/github/license/Toukakoukan/servicenow-powershell.svg)](blob/master/LICENSE) ![Test Coverage](https://img.shields.io/badge/test%20coverage-86%25-yellowgreen.svg)
# PSServiceNow
[![GitHub release](https://img.shields.io/github/release/Toukakoukan/servicenow-powershell.svg)](releases/latest) [![GitHub license](https://img.shields.io/github/license/Toukakoukan/servicenow-powershell.svg)](blob/master/LICENSE) ![Test Coverage](https://img.shields.io/badge/coverage-86%25-yellowgreen.svg)
This PowerShell module provides a series of cmdlets for interacting with the [ServiceNow REST API](http://wiki.servicenow.com/index.php?title=REST_API), performed by wrapping `Invoke-RestMethod` for the API calls.
**IMPORTANT:** Neither this module, nor its creator are in any way affiliated with ServiceNow.

Expand All @@ -8,12 +8,12 @@ Requires PowerShell 3.0 or above as this is when `Invoke-RestMethod` was introdu

## Usage
Download the [latest release](releases/latest) and extract the .psm1 and .psd1 files to your PowerShell profile directory (i.e. the `Modules` directory under wherever `$profile` points to in your PS console) and run:
`Import-Module ServiceNow-Module`
Once you've done this, all the cmdlets will be at your disposal, you can see a full list using `Get-Command -Module ServiceNow-Module`.
`Import-Module PSServiceNow`
Once you've done this, all the cmdlets will be at your disposal, you can see a full list using `Get-Command -Module PSServiceNow`.

### Example - Retrieving an Incident Containing the Word 'PowerShell'
```
Import-Module ServiceNow-Module
Import-Module PSServiceNow
Set-ServiceNowAuth
Get-ServiceNowIncident -MatchContains @{short_description='PowerShell'}
```
Expand Down
Binary file removed ServiceNow-Module.psd1
Binary file not shown.

0 comments on commit ddc1cf0

Please sign in to comment.