Skip to content

Add strongly typed Permissions struct for GitHub Actions permissions - #1980

Merged
pelikhan merged 6 commits into
mainfrom
copilot/add-permissions-struct
Oct 19, 2025
Merged

pelikhan merged 6 commits into
mainfrom
copilot/add-permissions-struct

Conversation

Copilot AI commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor

Plan: Add Strongly Typed Permissions Struct

  • Create Permissions struct in pkg/workflow/permissions.go with:
    • Support for shorthand permissions (read-all, write-all, read, write, none)
    • Support for granular permissions map (contents, issues, pull-requests, etc.)
    • Constructor functions for common patterns
    • Merge method to combine permissions (write implies read)
    • RenderToYAML method for rendering to GitHub Actions YAML format
  • Add comprehensive unit tests for Permissions struct
    • Add extensive tests for Merge method (36 test cases)
  • Replace hardcoded permission strings in workflow package:
    • add_comment.go
    • add_labels.go
    • create_issue.go
    • create_discussion.go
    • create_pr_review_comment.go
    • create_pull_request.go
    • create_code_scanning_alert.go
    • notify_comment.go
    • push_to_pull_request_branch.go
    • publish_assets.go
    • safe_jobs.go
    • threat_detection.go
    • tools.go
    • missing_tool.go
    • compiler.go
  • Run tests and validate changes
  • Run agent-finish for final validation

Test Coverage for Merge Method

Added 36 comprehensive test cases covering:

Map-to-Map Merges (8 tests)

  • Write overriding read
  • Read not overriding write
  • Different scopes
  • Multiple scopes with conflicts
  • None permission interactions
  • All permission scopes

Shorthand-to-Shorthand Merges (15 tests)

  • All combinations: write-all, write, read-all, read, none
  • Precedence rules (write-all > write > read-all > read > none)
  • Same shorthand preservation

Shorthand-to-Map Merges (5 tests)

  • Read-all/write-all adding missing scopes
  • Read/write adding missing scopes
  • None shorthand (no change)

Map-to-Shorthand Merges (4 tests)

  • Converting shorthand to map when merging
  • Complex map merges

Edge Cases (4 tests)

  • Nil merges
  • Empty map merges

All 36 tests pass successfully ✅

Original prompt

Add a strongly typed Permissions struct go type that represents a GitHub actions permissions object.

  • support shortcuts like "read-all", ...
  • support merging 2 permissions object (write implies read)
  • add support for rendering to yaml
  • search for instances of "permissions:..." and use helper instead
  • locate new code in permissions.go

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 19, 2025 16:43
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add extensive tests for merge

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add strongly typed Permissions struct for GitHub actions Add strongly typed Permissions struct for GitHub Actions permissions Oct 19, 2025
Copilot AI requested a review from pelikhan October 19, 2025 17:08
@pelikhan
pelikhan marked this pull request as ready for review October 19, 2025 17:12
@github-actions

Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Oct 19, 2025 •

Copy link
Copy Markdown
Contributor Author

@copilot add extensive tests for merge

Added 36 extensive test cases for the Merge method covering:

  • Map-to-map merges (8 tests)
  • Shorthand-to-shorthand merges (15 tests)
  • Shorthand-to-map merges (5 tests)
  • Map-to-shorthand merges (4 tests)
  • Edge cases with nil and empty maps (4 tests)

All tests validate proper precedence rules (write > read > none) and shorthand conversion behavior. Commit: TBD

@copilot add extensive tests for merge

Added 36 extensive test cases for the Merge method covering:

  • Map-to-map merges (8 tests)
  • Shorthand-to-shorthand merges (15 tests)
  • Shorthand-to-map merges (5 tests)
  • Map-to-shorthand merges (4 tests)
  • Edge cases with nil and empty maps (4 tests)

All tests validate proper precedence rules (write > read > none) and shorthand conversion behavior. Commit: f31d353

@pelikhan
pelikhan merged commit c0caeed into main Oct 19, 2025
4 checks passed
@pelikhan
pelikhan deleted the copilot/add-permissions-struct branch October 19, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants