8000
Skip to content

[code-simplifier] refactor: simplify detection job permissions and WASM result building#23651

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/detection-job-permissions-2026-03-31-459ff5a097674774
Mar 31, 2026
Merged

[code-simplifier] refactor: simplify detection job permissions and WASM result building#23651
pelikhan merged 1 commit intomainfrom
code-simplifier/detection-job-permissions-2026-03-31-459ff5a097674774

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Code simplifications to recently modified files from PR #23647 (fix: correct YAML indentation for detection job permissions block).

Files Simplified

  • pkg/workflow/threat_detection.go — Flattened detection job permissions logic
  • cmd/gh-aw-wasm/main.go — Cleaned up WASM result building

Improvements Made

1. Reduced Nesting in buildDetectionJob

The outer if needsContentsRead || copilotRequestsEnabled guard was unnecessary because NewPermissions().RenderToYAML() already returns "" when no permissions are set. Removing it makes the code more linear:

Before / After

Before:

var permissions string
needsContentsRead := ...
copilotRequestsEnabled := ...
if needsContentsRead || copilotRequestsEnabled {
    var perms *Permissions
    if needsContentsRead {
        perms = NewPermissionsContentsRead()
    } else {
        perms = NewPermissions()
    }
    if copilotRequestsEnabled {
        perms.Set(PermissionCopilotRequests, PermissionWrite)
    }
    permissions = perms.RenderToYAML()
}

After:

needsContentsRead := ...
copilotRequestsEnabled := ...
var perms *Permissions
if needsContentsRead {
    perms = NewPermissionsContentsRead()
} else {
    perms = NewPermissions()
}
if copilotRequestsEnabled {
    perms.Set(PermissionCopilotRequests, PermissionWrite)
}
permissions := perms.RenderToYAML()

2. Cleaned Up WASM Entry Point

  • Removed redundant comments in compileWorkflow that merely restated the code
  • Removed blank line before keys declaration in jsObjectToFileMap
  • Inlined the warnings variable directly into result.Set(...) since it was only used once

Changes Based On

Recent changes from:

Testing

  • TestDetectionJobPermissionsIndentation passes (validates both the fix and the refactoring preserve behavior)
  • make fmt — no formatting changes
  • make build — builds successfully
  • make test-unit — all unit tests pass

Review Focus

Please verify:

  • The buildDetectionJob permissions logic is equivalent (empty permissions returns "" from RenderToYAML)
  • WASM result building is functionally identical

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

Note

🔒 Integrity filter blocked 1 item

The following item were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Code Simplifier ·

  • expires on Apr 1, 2026, 6:22 AM UTC

- Remove outer guard in buildDetectionJob: always build Permissions
  object (RenderToYAML returns empty string when no permissions set),
  eliminating one level of nesting and making the logic more linear
- Inline warnings array in doCompile result building (WASM entry point)
- Remove redundant comments in cmd/gh-aw-wasm/main.go that merely
  re-stated what the adjacent code does

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request Mar 31, 2026
@pelikhan pelikhan marked this pull request as ready for review March 31, 2026 11:55
Copilot AI review requested due to automatic review settings March 31, 2026 11:55
Copy link
Copy Markdown
Contributor
Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs small refactors to simplify workflow compilation code paths without changing behavior, focusing on detection job permissions rendering and WASM result construction.

Changes:

  • Flattened buildDetectionJob permissions construction by always instantiating Permissions and relying on RenderToYAML() returning "" when empty.
  • Simplified WASM entrypoint code by removing redundant comments/whitespace and inlining one-time warnings allocation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/workflow/threat_detection.go Makes detection job permissions building more linear while preserving empty-output behavior via Permissions.RenderToYAML().
cmd/gh-aw-wasm/main.go Minor cleanup in WASM compile path; inlines warnings array creation into the result object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit a77e00f into main Mar 31, 2026
67 checks passed
@pelikhan pelikhan deleted the code-simplifier/detection-job-permissions-2026-03-31-459ff5a097674774 branch March 31, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0