Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions WASP/Private/Flag-JiraTicket.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function Flag-JiraTicket {
<#
.SYNOPSIS
Flags a Jira Ticket
.DESCRIPTION
Flags or unflags and optionally comments a Jira Ticket with the given parameters
.NOTES
FileName: Flag-JiraTicket.ps1
Author: Julian Bopp
Contact: its-wcs-ma@unibas.ch
Created: 2025-08-21
Version: 1.0.0
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string] $issueKey,
[Parameter(Mandatory = $false)][string] $comment,
[Parameter(Mandatory = $false)][bool] $unflag
)

begin {
$config = Read-ConfigFile
$jiraBaseUrl = $config.Application.JiraBaseUrl
$jiraUser = $config.Application.JiraUser
$jiraPassword = $config.Application.JiraPassword
$projectKey = $config.Application.ProjectKey
$issueType = $config.Application.IssueType
}

process {
$url = "$($jiraBaseUrl)/rest/api/2/issue/$issueKey"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("${jiraUser}:${jiraPassword}")))

$header = @{
"Authorization" = "Basic $base64AuthInfo"
"Content-Type" = "application/json"
}

# Create comment if provided
if ($comment) {
$flagComment = "(flag) " + $comment
if ($unflag) {
$flagComment = "(flagoff) " + $comment
}
}
# Create the JSON payload
$value = "Impediment"

if ($unflag) {
$value = $null
}

$body = @{
fields = @{
# This field is used for the flagging
customfield_10000 = @(
@{ value = $value }
)

}
} | ConvertTo-Json -Depth 3

Write-Log -Message "Flagging jira ticket $issueKey" -Severity 1
$response = Invoke-WebRequest -Uri $url -Method Put -Headers $header -Body $body

if ($comment) {
New-JiraComment -issueKey $issueKey -comment $flagComment
}

if ($response.StatusCode -eq 204) {
Write-Log -Message "StatusCode: $($response.StatusCode)" -Severity 0
if ($unflag) {
Write-Log -Message "Jira ticket successfully unflagged" -Severity -0
} else {
Write-Log -Message "Jira ticket successfully flagged" -Severity -0
}
} else {
Write-Log -Message "Failed to flag/unflag jira ticket! StatusCode: $($response.StatusCode): $($response.StatusDescription)" -Severity 3
}
}

end {
}
}
61 changes: 61 additions & 0 deletions WASP/Private/Get-JiraIssueKeyFromName.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Get-JiraIssueKeyFromName {
<#
.SYNOPSIS
Retrieves a Jira issue key from an issue name (summary).
.DESCRIPTION
Uses Jira REST API search to find an issue by its summary/title
and returns the issue key (e.g., PROJ-123).
.NOTES
FileName: Get-JiraIssueKeyFromName.ps1
Author: Julian Bopp
Contact: its-wcs-ma@unibas.ch
Created: 2025-09-09
Version: 1.0.0
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string] $issueName
)

begin {
$config = Read-ConfigFile
$jiraBaseUrl = $config.Application.JiraBaseUrl
$jiraUser = $config.Application.JiraUser
$jiraPassword = $config.Application.JiraPassword
$projectKey = $config.Application.ProjectKey
}

process {
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("${jiraUser}:${jiraPassword}")))

$header = @{
"Authorization" = "Basic $base64AuthInfo"
"Content-Type" = "application/json"
}

# JQL to search by issue summary
$jql = "project = $projectKey AND summary ~ `"$issueName`""
$searchUrl = "$jiraBaseUrl/rest/api/2/search?jql=$([System.Web.HttpUtility]::UrlEncode($jql))"

Write-Log -Message "Searching for Jira issue with summary: $issueName" -Severity 1
$response = Invoke-RestMethod -Uri $searchUrl -Method Get -Headers $header

if ($response.issues.Count -eq 0) {
Write-Log -Message "No Jira issue found with summary: $issueName" -Severity 2
return $null
}

# Return all matching issue keys
$issueKeys = $response.issues | ForEach-Object { $_.key }

# if multiple issues found, log a warning
if ($issueKeys.Count -gt 1) {
Write-Log -Message "Multiple Jira issues found with summary: $issueName. Returning all matching keys." -Severity 2
}

Write-Log -Message "Found Jira issues: $($issueKeys -join ', ')" -Severity 0
return $issueKeys
}

end { }
}
58 changes: 58 additions & 0 deletions WASP/Private/New-JiraComment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function New-JiraComment {
<#
.SYNOPSIS
Adds a comment to a Jira Ticket
.DESCRIPTION
Adds a comment to a Jira Ticket
.NOTES
FileName: New-JiraComment.ps1
Author: Julian Bopp
Contact: its-wcs-ma@unibas.ch
Created: 2025-08-21
Version: 1.0.0
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string] $issueKey,
[Parameter(Mandatory = $true)][string] $comment
)

begin {
$config = Read-ConfigFile
$jiraBaseUrl = $config.Application.JiraBaseUrl
$jiraUser = $config.Application.JiraUser
$jiraPassword = $config.Application.JiraPassword
$projectKey = $config.Application.ProjectKey
$issueType = $config.Application.IssueType # Story
}

process {
$url = "$($jiraBaseUrl)/rest/api/2/issue/$issueKey/comment"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("${jiraUser}:${jiraPassword}")))

$header = @{
"Authorization" = "Basic $base64AuthInfo"
"Content-Type" = "application/json"
}

# Create the JSON payload for the new comment
$body = @{
body = $comment
} | ConvertTo-Json -Depth 3

Write-Log -Message "Commenting jira ticket $issueKey with comment: $comment" -Severity 1

$response = Invoke-WebRequest -Uri $url -Method Post -Headers $header -Body $body

if ($response.StatusCode -eq 201) {
Write-Log -Message "StatusCode: $($response.StatusCode)" -Severity 0
Write-Log -Message "Jira ticket successfully commented: $($response.Content)" -Severity 0
} else {
Write-Log -Message "Failed to comment jira ticket! StatusCode: $($response.StatusCode): $($response.StatusDescription)" -Severity 3
}
}

end {
}
}
27 changes: 27 additions & 0 deletions WASP/Private/New-RemoteBranch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,36 @@ function New-RemoteBranch {
begin {
$Config = Read-ConfigFile
$RemoteBranches = Get-RemoteBranches -Repo $Repository -User $User

$GitRepo = $config.Application.PackagesWishlist
$GitFile = $GitRepo.Substring($GitRepo.LastIndexOf("/") + 1, $GitRepo.Length - $GitRepo.LastIndexOf("/") - 1)
$WishlistFolderName = $GitFile.Replace(".git", "")
$PackagesWishlistPath = Join-Path -Path $config.Application.BaseDirectory -ChildPath $WishlistFolderName
$wishlistPath = Join-Path -Path $PackagesWishlistPath -ChildPath "wishlist.txt"
}

process {

$wishlist = Get-Content -Path $wishlistPath | Where-Object { $_ -notlike "#*" }
$nameAndVersionSeparator = '@'

$packageName = $packageName -replace "$nameAndVersionSeparator.*", ""
$packageName = $packageName -replace "dev/", ""
$foundInWishlist = $false
foreach ($line in $wishlist) {
$line = $line -replace "@.*", ""
if ($line -eq $packageName) {
$foundInWishlist = $true
}
}

if (-not $foundInWishlist) {
$IssueKey = Get-JiraIssueKeyFromName -issueName $packageName
Write-Log "Package $packageName not found in wishlist. Will not create branch." -Severity 2
Flag-JiraTicket -issueKey $IssueKey -comment "Package $packageName not found in wishlist. Will not create branch."
return
}

if ($RemoteBranches.Contains($BranchName)) {
Write-Log "Branch $branchName already exist. Nothing to do"
return
Expand Down