diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index a00e01a..faa8443 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -1,4 +1,4 @@ -name: Codacy Bootstrap Issues +name: Sync Codacy Issues on: workflow_dispatch: @@ -99,3 +99,71 @@ jobs: await new Promise(resolve => setTimeout(resolve, 2000)); } } + + - name: Close Resolved GitHub Issues + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const dryRun = "${{ github.event.inputs.dry_run }}" === "true"; + const rawIssues = JSON.parse(fs.readFileSync('filtered_issues.json', 'utf8')); + + // Build current Codacy set (only *active* issues, not ignored) + const currentCodacyIds = new Set( + rawIssues.filter(i => !i.ignored).map(i => i.issueId) + ); + + // Build ignored Codacy set + const ignoredCodacyIds = new Set( + rawIssues.filter(i => i.ignored).map(i => i.issueId) + ); + + // Fetch ALL GitHub issues with codacy label + const allIssues = await github.paginate( + github.rest.issues.listForRepo, + { + owner: context.repo.owner, + repo: context.repo.repo, + state: "all", + labels: ["codacy"] + } + ); + + for (const ghIssue of allIssues) { + const matches = ghIssue.body?.match(/codacy-issue-([a-f0-9]+)/g); + if (!matches) continue; + + for (const match of matches) { + const issueId = match.replace("codacy-issue-", ""); + + // Close if not active OR explicitly ignored + if ((!currentCodacyIds.has(issueId) || ignoredCodacyIds.has(issueId)) + && ghIssue.state === "open") { + if (dryRun) { + console.log(`[DRY RUN] Would close issue #${ghIssue.number} (Codacy issueId ${issueId})`); + } else { + // Add comment before closing + const reason = ignoredCodacyIds.has(issueId) + ? "Auto closed because Codacy issue is marked as *ignored*" + : "Auto closed as not found in last analysis"; + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ghIssue.number, + body: reason + }); + + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ghIssue.number, + state: "closed" + }); + console.log(`❌ Closed GitHub issue #${ghIssue.number} for Codacy issueId ${issueId}`); + } + } + } + } + + \ No newline at end of file diff --git a/MessagingService.BusinessLogic/Services/MessagingDomainService.cs b/MessagingService.BusinessLogic/Services/MessagingDomainService.cs index 7688474..ccfbb4e 100644 --- a/MessagingService.BusinessLogic/Services/MessagingDomainService.cs +++ b/MessagingService.BusinessLogic/Services/MessagingDomainService.cs @@ -257,6 +257,10 @@ public async Task UpdateMessageStatus(EmailCommands.UpdateMessageStatusC case EmailServices.MessageStatus.Spam: emailAggregate.MarkMessageAsSpam(command.Description, command.Timestamp); break; + default: + // Unknown status - treat as failed + emailAggregate.MarkMessageAsFailed(command.Description, command.Timestamp); + break; } return Result.Success(); diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs index 01d7def..c240caa 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Security.Authentication; using System.Text; namespace MessagingService.BusinessLogic.Services.SMSServices.TheSMSWorks @@ -115,7 +116,7 @@ public async Task GetMessageStatus(String providerReferen } } else { - throw new Exception("Authentication Error"); + throw new AuthenticationException("Authentication Error"); } return response; diff --git a/MessagingService/Controllers/DomainEventController.cs b/MessagingService/Controllers/DomainEventController.cs index d504f54..b48c2d0 100644 --- a/MessagingService/Controllers/DomainEventController.cs +++ b/MessagingService/Controllers/DomainEventController.cs @@ -1,4 +1,6 @@ -namespace MessagingService.Controllers +using Shared.Exceptions; + +namespace MessagingService.Controllers { using System; using System.Collections.Generic; @@ -107,7 +109,7 @@ private async Task GetDomainEvent(Object domainEvent) { Type type = TypeMap.GetType(eventType); if (type == null) - throw new Exception($"Failed to find a domain event with type {eventType}"); + throw new NotFoundException($"Failed to find a domain event with type {eventType}"); JsonIgnoreAttributeIgnorerContractResolver jsonIgnoreAttributeIgnorerContractResolver = new(); JsonSerializerSettings jsonSerialiserSettings = new() {