Skip to content

Commit 973ece4

Browse files
authored
[WIP] Add missing organization-custom-org-roles and organization-custom-repository-roles to JSON Schema (#56982)
1 parent 77c28f2 commit 973ece4

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎docs/public/editor/autocomplete-data.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@
486486
"enum": ["read", "write", "none"],
487487
"leaf": true
488488
},
489+
"organization-custom-org-roles": {
490+
"type": "string",
491+
"desc": "Permission level for organization custom org roles (read/write/none).",
492+
"enum": ["read", "write", "none"],
493+
"leaf": true
494+
},
495+
"organization-custom-repository-roles": {
496+
"type": "string",
497+
"desc": "Permission level for organization custom repository roles (read/write/none).",
498+
"enum": ["read", "write", "none"],
499+
"leaf": true
500+
},
489501
"security-events": {
490502
"type": "string",
491503
"desc": "Permission level for security events (read/write/none).",

‎pkg/parser/schema_errors.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ func findFrontmatterBounds(lines []string) (startIdx int, endIdx int, frontmatte
312312
var knownFieldValidValues = map[string]string{
313313
// Both entries mirror $defs/github_actions_permissions in main_workflow_schema.json.
314314
// Update both when the schema changes.
315-
"/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
316-
"/on/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
315+
"/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-custom-org-roles, organization-custom-repository-roles, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
316+
"/on/permissions": "Valid permission scopes: actions, all, attestations, checks, code-quality, copilot-requests, contents, deployments, discussions, id-token, issues, metadata, models, organization-custom-org-roles, organization-custom-repository-roles, organization-projects, packages, pages, pull-requests, repository-projects, security-events, statuses, vulnerability-alerts",
317317
}
318318

319319
// knownFieldScopes maps well-known JSON schema paths to a slice of valid scope names.
@@ -325,12 +325,14 @@ var knownFieldScopes = map[string][]string{
325325
"/permissions": {
326326
"actions", "all", "attestations", "checks", "code-quality", "copilot-requests", "contents", "deployments",
327327
"discussions", "id-token", "issues", "metadata", "models",
328+
"organization-custom-org-roles", "organization-custom-repository-roles",
328329
"organization-projects", "packages", "pages", "pull-requests",
329330
"repository-projects", "security-events", "statuses", "vulnerability-alerts",
330331
},
331332
"/on/permissions": {
332333
"actions", "all", "attestations", "checks", "code-quality", "copilot-requests", "contents", "deployments",
333334
"discussions", "id-token", "issues", "metadata", "models",
335+
"organization-custom-org-roles", "organization-custom-repository-roles",
334336
"organization-projects", "packages", "pages", "pull-requests",
335337
"repository-projects", "security-events", "statuses", "vulnerability-alerts",
336338
},

‎pkg/parser/schemas/main_workflow_schema.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14964,6 +14964,16 @@
1496414964
"enum": ["read", "write", "none"],
1496514965
"description": "Permission level for organization projects (read/write/none). Controls access to manage organization-level GitHub Projects boards."
1496614966
},
14967+
"organization-custom-org-roles": {
14968+
"type": "string",
14969+
"enum": ["read", "write", "none"],
14970+
"description": "Permission level for organization custom org roles (read/write/none). Controls access to custom organization role metadata."
14971+
},
14972+
"organization-custom-repository-roles": {
14973+
"type": "string",
14974+
"enum": ["read", "write", "none"],
14975+
"description": "Permission level for organization custom repository roles (read/write/none). Controls access to custom repository role metadata."
14976+
},
1496714977
"security-events": {
1496814978
"type": "string",
1496914979
"enum": ["read", "write", "none"],

‎pkg/workflow/permissions_schema_consistency_test.go‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"testing"
99

10+
"github.com/github/gh-aw/pkg/parser"
1011
"github.com/stretchr/testify/require"
1112
)
1213

@@ -62,6 +63,19 @@ func TestPermissionConstantsMatchSchemaEnum(t *testing.T) {
6263
}
6364
}
6465

66+
// Workflow-level permissions continue to accept custom org/repo role scopes,
67+
// even though they are only available via GitHub App tokens when minting a
68+
// token for the workflow.
69+
for _, scope := range []PermissionScope{
70+
PermissionOrganizationCustomOrgRoles,
71+
PermissionOrganizationCustomRepositoryRoles,
72+
} {
73+
if _, ok := actionsPermProps[string(scope)]; !ok {
74+
t.Errorf("permission scope %q from GetAllGitHubAppOnlyScopes() is missing from "+
75+
"$defs.github_actions_permissions.properties in pkg/parser/schemas/main_workflow_schema.json", scope)
76+
}
77+
}
78+
6579
// GitHub App-only scopes must appear under either github_actions_permissions
6680
// (e.g. organization-projects, which is grouped there for historical reasons) or
6781
// github_app_permissions.
@@ -112,3 +126,35 @@ func TestPermissionsSchemaEnumMatchesConstants(t *testing.T) {
112126
}
113127
}
114128
}
129+
130+
// TestOrganizationCustomRolePermissionsValidateAgainstSchema is a regression test that
131+
// ensures workflow frontmatter using the organization-custom-org-roles and
132+
// organization-custom-repository-roles permission scopes validates cleanly against the
133+
// JSON Schema, and that invalid values for these scopes are still rejected.
134+
func TestOrganizationCustomRolePermissionsValidateAgainstSchema(t *testing.T) {
135+
for _, scope := range []string{"organization-custom-org-roles", "organization-custom-repository-roles"} {
136+
t.Run(scope+"/valid", func(t *testing.T) {
137+
frontmatter := map[string]any{
138+
"on": "workflow_dispatch",
139+
"permissions": map[string]any{
140+
scope: "read",
141+
},
142+
}
143+
if err := parser.ValidateMainWorkflowFrontmatterWithSchemaAndLocation(frontmatter, "workflow.md"); err != nil {
144+
t.Fatalf("expected %q permission scope to validate cleanly, got error: %v", scope, err)
145+
}
146+
})
147+
148+
t.Run(scope+"/invalid-value", func(t *testing.T) {
149+
frontmatter := map[string]any{
150+
"on": "workflow_dispatch",
151+
"permissions": map[string]any{
152+
scope: "not-a-real-value",
153+
},
154+
}
155+
if err := parser.ValidateMainWorkflowFrontmatterWithSchemaAndLocation(frontmatter, "workflow.md"); err == nil {
156+
t.Fatalf("expected invalid value for %q permission scope to be rejected", scope)
157+
}
158+
})
159+
}
160+
}

0 commit comments

Comments
 (0)