Skip to content

Commit 041daf8

Browse files
committed
fix(deprecation): update logic so file reflects the entire deprecation map from a given pr
1 parent d73cf2c commit 041daf8

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

examples-copier/services/webhook_handler_new.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818

1919
const (
2020
maxWebhookBodyBytes = 1 << 20 // 1MB
21-
statusDeleted = "DELETED"
21+
// GitHub GraphQL API returns file status in uppercase for the ChangeType field
22+
// Possible values: ADDED, MODIFIED, DELETED, RENAMED, COPIED, CHANGED
23+
statusDeleted = "DELETED"
2224
)
2325

2426
// simpleVerifySignature verifies the webhook signature
@@ -386,11 +388,21 @@ func processFileForTarget(ctx context.Context, prNumber int, sourceCommitSHA str
386388

387389
// Handle deleted files
388390
if file.Status == statusDeleted {
391+
LogInfoCtx(ctx, "file marked as deleted, handling deprecation", map[string]interface{}{
392+
"file": file.Path,
393+
"status": file.Status,
394+
"target": targetPath,
395+
})
389396
handleFileDeprecation(ctx, prNumber, sourceCommitSHA, file, rule, target, targetPath, sourceBranch, config, container)
390397
return
391398
}
392399

393400
// Handle file copy
401+
LogInfoCtx(ctx, "file marked for copy", map[string]interface{}{
402+
"file": file.Path,
403+
"status": file.Status,
404+
"target": targetPath,
405+
})
394406
handleFileCopyWithAudit(ctx, prNumber, sourceCommitSHA, file, rule, target, targetPath, variables, sourceBranch, config, container)
395407
}
396408

@@ -557,16 +569,14 @@ func queueFileForUploadWithStrategy(target types.TargetConfig, file github.Repos
557569

558570
// addToDeprecationMapForTarget adds a file to the deprecation map
559571
func addToDeprecationMapForTarget(targetPath string, target types.TargetConfig, fileStateService FileStateService) {
560-
deprecationFile := "deprecated_examples.json"
561-
if target.DeprecationCheck != nil && target.DeprecationCheck.File != "" {
562-
deprecationFile = target.DeprecationCheck.File
563-
}
564-
565572
entry := types.DeprecatedFileEntry{
566573
FileName: targetPath,
567574
Repo: target.Repo,
568575
Branch: target.Branch,
569576
}
570577

571-
fileStateService.AddFileToDeprecate(deprecationFile, entry)
578+
// Use a composite key to ensure uniqueness: repo + targetPath
579+
// This allows multiple files to be deprecated to the same deprecation file
580+
key := target.Repo + ":" + targetPath
581+
fileStateService.AddFileToDeprecate(key, entry)
572582
}

0 commit comments

Comments
 (0)