Skip to content

Commit

Permalink
Merge pull request #34 from ITS-Unibas/jira-pull
Browse files Browse the repository at this point in the history
Pull the Current Jira Issues from the WASP Board and Prepare for comparison
  • Loading branch information
TK5-Tim authored Sep 12, 2024
2 parents 6704574 + ad8b641 commit 1d5324e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
60 changes: 60 additions & 0 deletions WASP/Private/Get-JiraIssues.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function Get-JiraIssues () {
<#
.Synopsis
Get the Current Jira Issues for the given Project.
.Description
Get the Current Jira Issues for the given Project.
.Notes
FileName: Get-JiraIssues.ps1
Author: Tim Keller
Contact: tim.keller@unibas.ch
Created: 2024-09-04
Updated: 2024-09-05
Version: 1.0.0
#>
param(
)

begin {
$Config = Read-ConfigFile
$JiraUrl = $Config.Application.JiraBaseURL
$ProjectKey = $Config.Application.ProjectKey

} process {
<#Create the URL for the Jira Issues API Endpoint#>
$Base64Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Config.Application.RepositoryManagerAPIUser, $Config.Application.RepostoryManagerAPIPassword)))
$Url = $JiraUrl + "/rest/api/latest/search?jql=project=$ProjectKey&maxResults=500"
Write-Log "Retrieving Jira Issues for Project $ProjectKey"
try {
$Response = Invoke-RestMethod -Uri $Url -Method Get -Headers @{Authorization = "Basic $Base64Auth" }
}
catch {
$StatusCode = $_.Exception.Response.StatusCode.value__
Write-Log "Get request failed with $StatusCode" -Severity 3
}
<#Save the number of total issues to check if all of them were downloaded.#>
$totalIssues = $Response.total

<#Iteratively save the Issues for all of the steps in one object.#>
$Results = @()
$Results += $Response.Issues

<#Make a new request until all issues are stored in the Reults object#>
while($Results.Count -ne $totalIssues){
<#The starting point for the pagination of the request is the number of issues already pulled#>
$StartAt = $Response.startAt + $Response.issues.Count
$UrlIter = $JiraUrl + "/rest/api/latest/search?jql=project=$ProjectKey&startAt=$StartAt&maxResults=500"
try {
$Response = Invoke-RestMethod -Uri $UrlIter -Method Get -Headers @{Authorization = "Basic $Base64Auth" }
}
catch {
$StatusCode = $_.Exception.Response.StatusCode.value__
Write-Log "Get request failed with $StatusCode" -Severity 3
}
$Results += $Response.Issues

}
Write-Log "Successfully Retrieved $totalIssues Jira Issues for the Project $ProjectKey"
Return $Results
}
}
11 changes: 10 additions & 1 deletion WASP/Private/Invoke-JiraObserver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ function Invoke-JiraObserver {
}

# aktueller Stand Tickets von Jira holen (Get Request)
$currentJiraStates
$IssueResults = Get-JiraIssues

# Filter the information to be able to compare the current jira state to the state read from the file
$IssuesCurrentState = @{}
$IssueResults | ForEach-Object {
$IssuesCurrentState[$_.fields.summary] = [PSCustomObject]@{
Assignee = $_.fields.assignee.name
Status = $_.fields.status.name
}
}

<# Vergleich Status Tickets mit Stand im neusten Jira-State File:
Expand Down

0 comments on commit 1d5324e

Please sign in to comment.