Skip to content

Commit

Permalink
fix small bugs in jiraobserver
Browse files Browse the repository at this point in the history
  • Loading branch information
ITS-Unibas-Choco committed Dec 16, 2024
1 parent e3492ee commit 4356ddf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions WASP/Private/Invoke-JiraObserver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Invoke-JiraObserver {
# test → prod: PR nach prod, wenn nicht offen.Falls der PR schon gemerged wurde, wird der Jira State aktualisiert.
} elseif ($IssuesCompareState[$key].StatusOld -eq "Testing" -and $IssuesCompareState[$key].Status -eq "Production") {
# Es wird gecheckt ob ein offener oder gemergedter Pull Request nach prod existiert, falls nicht wird ein neuer PR erstellt
$UpdateJiraStateFile = Update-PullRequest -SourceBranch $DevBranch -DestinationBranch "test" -Software $key -DestinationName "Testing"
$UpdateJiraStateFile = Update-PullRequest -SourceBranch $DevBranch -DestinationBranch "prod" -Software $key -DestinationName "Production"

# prod → dev: kein PR, neuer branch mit @ + random hash
} elseif ($IssuesCompareState[$key].StatusOld -eq "Production" -and $IssuesCompareState[$key].Status -eq "Development") {
Expand All @@ -148,13 +148,16 @@ function Invoke-JiraObserver {
Write-Log -Message "New Repackaging Branch $RepackagingBranch created" -Severity 0
}
$UpdateJiraStateFile = $true
# test -> dev: änderung wird im Jira State File geschrieben
} elseif ($IssuesCompareState[$key].StatusOld -eq "Testing" -and $IssuesCompareState[$key].Status -eq "Development") {
$UpdateJiraStateFile = $true
# dev → prod: Error Message, da Testing übersprungen wurde
} elseif (($IssuesCompareState[$key].StatusOld -eq "Development" -and $IssuesCompareState[$key].Status -eq "Production")) {
Write-Log -Message "The status of the issue $key has changed from Development to Production without going through Testing. This Action is not allowed." -Severity 3
continue
$UpdateJiraStateFile = $false
}
else {
continue
$UpdateJiraStateFile = $false
}
if ($UpdateJiraStateFile -eq $true) {
# Der Jira State File wird aktualisiert für den entsprechenden Branch
Expand Down
7 changes: 3 additions & 4 deletions WASP/Private/Update-PullRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,20 @@ function Update-PullRequest {
$toBranch = $latestPullRequest.Details.base.ref

if (($fromBranch -eq $SourceBranch) -and ($toBranch -eq $DestinationBranch) -and ($state -eq "open")) {
Write-Log "No action needed" -Severity 0
Write-Log "No action needed. Pull Request from $SourceBranch to $DestinationBranch already exists" -Severity 1
return $false
} else {
$PullRequestTitle = "$Software to $DestinationName"
$response = New-PullRequest -SourceRepo $packageGalleryRepo -SourceUser $gitHubOrganization -SourceBranch $SourceBranch -DestinationRepo $packageGalleryRepo -DestinationUser $gitHubOrganization -DestinationBranch $DestinationBranch -PullRequestTitle $PullRequestTitle -ErrorAction Stop
Start-Sleep -Seconds 6
Start-Sleep -Seconds 4
if ($response.GetType().Name -ne "ErrorRecord") {
Write-Log -Message "New Pull Request $PullRequestTitle created" -Severity 0
Write-Log -Message "New Pull Request $PullRequestTitle from $SourceBranch to $DestinationBranch created" -Severity 1
return $false
} else {
$ErrorDetails = ConvertFrom-Json $response.ErrorDetails
$ErrorDetailsMessage = $ErrorDetails.Message
$ErrorMessage = $ErrorDetails.errors.message
if ($ErrorMessage -like "No commits between*") {
Write-Log -Message "No commits between $SourceBranch and $DestinationBranch" -Severity 0
return $true
} else {
Write-Log -Message "Error creating Pull Request: $ErrorDetailsMessage" -Severity 3
Expand Down

0 comments on commit 4356ddf

Please sign in to comment.