Skip to content

Export Codeowners Plus information to JSON data for ingestion#43

Merged
BakerNet merged 14 commits into
mainfrom
dev/output-json
Jun 11, 2025
Merged

Export Codeowners Plus information to JSON data for ingestion#43
BakerNet merged 14 commits into
mainfrom
dev/output-json

Conversation

@BakerNet

Copy link
Copy Markdown
Collaborator

Summary / Background

Some changes either on GH's CDN end or Chrome Cors enforcement has broken our internal browser extension tool.

The tool was pulling the logs of the workflow.

We can avoid pulling logs by exposing the underlying data as a Check Run output instead.

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@pooyaw

pooyaw commented Jun 10, 2025

Copy link
Copy Markdown

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions

github-actions Bot commented Jun 10, 2025

Copy link
Copy Markdown

Codeowners approval required for this PR:

@github-actions github-actions Bot requested a review from zbedforrest June 10, 2025 21:21
Comment thread .github/workflows/codeowners.yml Outdated
Comment on lines +45 to +61
- name: Create Check Run with JSON Output
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPORT_JSON: ${{ steps.codeowners-plus.outputs.data }}
run: |
# Use the 'gh' CLI to interact with the GitHub API
gh api --method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/check-runs" \
-f "name=Codeowners Plus Report" \
-f "head_sha=${{ github.event.pull_request.head.sha || github.sha }}" \
-f "status=completed" \
-f "output[title]=Codeowners Plus Report" \
-f "output[summary]=Codeowners Plus analysis JSON data including file owners and results" \
-f "output[text]=$REPORT_JSON"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! One thought I had is that passing the JSON report via an environment variable and then a command-line argument can be fragile for large outputs. A more robust pattern is to pipe the data to gh api’s stdin. This avoids command-line length limits if they ever come up and any potential shell quoting issues.

Suggested change
- name: Create Check Run with JSON Output
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPORT_JSON: ${{ steps.codeowners-plus.outputs.data }}
run: |
# Use the 'gh' CLI to interact with the GitHub API
gh api --method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/check-runs" \
-f "name=Codeowners Plus Report" \
-f "head_sha=${{ github.event.pull_request.head.sha || github.sha }}" \
-f "status=completed" \
-f "output[title]=Codeowners Plus Report" \
-f "output[summary]=Codeowners Plus analysis JSON data including file owners and results" \
-f "output[text]=$REPORT_JSON"
- name: Create Check Run with JSON Output
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo '${{ steps.codeowners-plus.outputs.data }}' | gh api --method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/check-runs" \
-f "name=Codeowners Plus Report" \
-f "head_sha=${{ github.event.pull_request.head.sha }}" \
-f "status=completed" \
-f "output[title]=Codeowners Plus Report" \
-f "output[summary]=Codeowners Plus analysis JSON data including file owners and results" \
-f "output[text]=@-"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also incorporated in the suggestion is my removal of the github.sha fallback. Do we need it? Since this workflow only runs on pull_request events, github.event.pull_request.head.sha should always be available

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I moved to a JSON field with --input - because I felt it was more readable. But good callout to use stdin

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah i like that. definitely more readable!

Comment thread internal/app/app.go
Success: success,
Message: message,
}
return outputData, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new logic to assemble the OutputData struct is a key part of this change, but it doesn’t appear to be covered by unit tests. Probably explains the slight drop in test coverage

@BakerNet BakerNet requested a review from zbedforrest June 10, 2025 23:01
Comment thread main.go

// Use GitHub Actions delimiter approach for robust handling of special characters
output := fmt.Sprintf("data<<EOF\n%s\nEOF\n", string(jsonData))
err = os.WriteFile(githubOutput, []byte(output), 0644)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does it matter if we overwrite the file vs append to it?

@BakerNet BakerNet Jun 11, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We shouldn't have to worry here - each step get's it's own output file, so we could only ever overwrite our own values. Since we own them, it's our problem and right now, we only have one value anyways.

@BakerNet BakerNet requested a review from zbedforrest June 11, 2025 00:20
@BakerNet BakerNet merged commit 1d5cd68 into main Jun 11, 2025
14 of 18 checks passed
@BakerNet BakerNet deleted the dev/output-json branch June 11, 2025 00:35
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.

3 participants