@@ -42,24 +42,52 @@ jobs:
4242 run : pnpm install
4343
4444 - name : Run graphql-lint-unused
45- id : graphql- lint
45+ id : lint
4646 continue-on-error : true
4747 run : |
48- OUTPUT=$(pnpm run graphql-lint-unused 2>&1) || true
48+ OUTPUT=$(pnpm run graphql-lint-unused 2>&1)
49+ EXIT_CODE=$?
4950 echo "$OUTPUT"
51+ SUMMARY=$(echo "$OUTPUT" | sed -n '/GENERAL STATISTICS/,/^$/p')
5052 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
51- echo "result <<$EOF" >> "$GITHUB_OUTPUT"
52- echo "$OUTPUT " >> "$GITHUB_OUTPUT"
53+ echo "summary <<$EOF" >> "$GITHUB_OUTPUT"
54+ echo "$SUMMARY " >> "$GITHUB_OUTPUT"
5355 echo "$EOF" >> "$GITHUB_OUTPUT"
56+ exit $EXIT_CODE
5457
5558 - name : Comment PR with results
56- uses : peter-evans/create-or-update-comment@v4
59+ if : github.event.pull_request.head.repo.full_name == github.repository
60+ uses : actions/github-script@v7
61+ env :
62+ LINT_SUMMARY : ${{ steps.lint.outputs.summary }}
5763 with :
58- issue-number : ${{ github.event.pull_request.number }}
59- body : |
60- ## GraphQL Unused Fields Report
64+ script : |
65+ const summary = process.env.LINT_SUMMARY;
66+ if (!summary.trim()) return;
6167
62- ```
63- ${{ steps.graphql-lint.outputs.result }}
64- ```
65- comment-tag : graphql-lint-unused
68+ const tag = '<!-- graphql-lint-unused -->';
69+ const body = `${tag}\n## GraphQL Unused Fields Report\n\n\`\`\`\n${summary}\n\`\`\``;
70+
71+ const { data: comments } = await github.rest.issues.listComments({
72+ owner: context.repo.owner,
73+ repo: context.repo.repo,
74+ issue_number: context.issue.number,
75+ });
76+
77+ const existing = comments.find(c => c.body.includes(tag));
78+
79+ if (existing) {
80+ await github.rest.issues.updateComment({
81+ owner: context.repo.owner,
82+ repo: context.repo.repo,
83+ comment_id: existing.id,
84+ body,
85+ });
86+ } else {
87+ await github.rest.issues.createComment({
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ issue_number: context.issue.number,
91+ body,
92+ });
93+ }
0 commit comments