Skip to content

Commit 3676218

Browse files
authored
Add discussions permission to GitHub App token for safe-outputs (#7455)
1 parent b455683 commit 3676218

File tree

9 files changed

+56
-7
lines changed

9 files changed

+56
-7
lines changed

.github/workflows/artifacts-summary.lock.yml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/changeset.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/daily-file-diet.lock.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/issue-classifier.lock.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/release.lock.yml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/stale-repo-identifier.lock.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/super-linter.lock.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/workflow/safe_outputs_app.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ func convertPermissionsToAppTokenFields(permissions *Permissions) map[string]str
218218
if level, ok := permissions.Get(PermissionOrganizationProj); ok {
219219
fields["permission-organization-projects"] = string(level)
220220
}
221+
if level, ok := permissions.Get(PermissionDiscussions); ok {
222+
fields["permission-discussions"] = string(level)
223+
}
221224

222225
// Note: The following GitHub Actions permissions do NOT have GitHub App equivalents:
223-
// - discussions (no GitHub App permission for this)
224226
// - models (no GitHub App permission for this)
225227
// - id-token (not applicable to GitHub Apps)
226228
// - attestations (no GitHub App permission for this)

pkg/workflow/safe_outputs_app_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,46 @@ Test workflow without safe outputs.
204204
require.NoError(t, err, "Failed to parse markdown content")
205205
assert.Nil(t, workflowData.SafeOutputs, "SafeOutputs should be nil")
206206
}
207+
208+
// TestSafeOutputsAppTokenDiscussionsPermission tests that discussions permission is included
209+
func TestSafeOutputsAppTokenDiscussionsPermission(t *testing.T) {
210+
compiler := NewCompiler(false, "", "1.0.0")
211+
212+
markdown := `---
213+
on: issues
214+
safe-outputs:
215+
create-discussion:
216+
category: "General"
217+
app:
218+
app-id: ${{ vars.APP_ID }}
219+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
220+
---
221+
222+
# Test Workflow
223+
224+
Test workflow with discussions permission.
225+
`
226+
227+
// Create a temporary test file
228+
tmpDir := t.TempDir()
229+
testFile := filepath.Join(tmpDir, "test.md")
230+
err := os.WriteFile(testFile, []byte(markdown), 0644)
231+
require.NoError(t, err, "Failed to write test file")
232+
233+
workflowData, err := compiler.ParseWorkflowFile(testFile)
234+
require.NoError(t, err, "Failed to parse markdown content")
235+
require.NotNil(t, workflowData.SafeOutputs, "SafeOutputs should not be nil")
236+
require.NotNil(t, workflowData.SafeOutputs.CreateDiscussions, "CreateDiscussions should not be nil")
237+
238+
// Build the consolidated safe_outputs job
239+
job, _, err := compiler.buildConsolidatedSafeOutputsJob(workflowData, "main", testFile)
240+
require.NoError(t, err, "Failed to build safe_outputs job")
241+
require.NotNil(t, job, "Job should not be nil")
242+
243+
// Convert steps to string for easier assertion
244+
stepsStr := strings.Join(job.Steps, "")
245+
246+
// Verify that permission-discussions: write is included in the GitHub App token minting step
247+
assert.Contains(t, stepsStr, "permission-discussions: write", "GitHub App token should include discussions write permission")
248+
assert.Contains(t, stepsStr, "permission-contents: read", "GitHub App token should include contents read permission")
249+
}

0 commit comments

Comments
 (0)