Skip to content

Commit a79e7e2

Browse files
committed
WIP
1 parent d78359a commit a79e7e2

3 files changed

Lines changed: 60 additions & 69 deletions

File tree

.github/actions/pr_comment/action.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: "Upsert PR Comment with Octo-STS"
2+
description: >
3+
Exchanges OIDC for an Octo-STS GitHub-App token and
4+
creates or updates a single comment on the PR.
5+
6+
inputs:
7+
body-file:
8+
description: "Path to file whose contents become the comment body"
9+
required: true
10+
repo: # optional; defaults to triggering repo
11+
description: "Repository (owner/repo)."
12+
required: false
13+
pr-number: # optional; defaults to triggering PR
14+
description: "Pull-request number."
15+
required: false
16+
17+
runs:
18+
using: "composite"
19+
steps:
20+
# 1. Get installation token from DD-Octo-STS
21+
- name: Obtain Octo-STS token
22+
id: octo-sts
23+
uses: DataDog/dd-octo-sts-action@08f2144903ced3254a3dafec2592563409ba2aa0 # v1.0.1
24+
with:
25+
audience: dd-octo-sts
26+
scope: DataDog/java-profiler
27+
policy: self.pr-comment
28+
29+
# 2. Upsert the comment
30+
- name: Upsert PR comment
31+
env:
32+
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
33+
BODY_FILE: ${{ inputs['body-file'] }}
34+
REPO: ${{ inputs.repo || github.repository }}
35+
PR: ${{ inputs['pr-number'] || github.event.pull_request.number }}
36+
shell: bash
37+
run: |
38+
set -e
39+
# find last comment by this actor
40+
# first, build a jq filter that embeds the actor’s login
41+
filter=".[] | select(.user.login == \"${GITHUB_ACTOR}\") | .id"
42+
cid=$(gh api "repos/$REPO/issues/$PR/comments?per_page=100" \
43+
--jq "${filter}" | tail -n1)
44+
45+
if [[ -n "$cid" ]]; then
46+
gh api --method PATCH "repos/$REPO/issues/comments/$cid" \
47+
-F body="<${BODY_FILE}"
48+
echo "✏️ Updated comment $cid"
49+
else
50+
gh api --method POST "repos/$REPO/issues/$PR/comments" \
51+
-F body="<${BODY_FILE}"
52+
echo "💬 Created new comment"
53+
fi

.github/workflows/codecheck.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ concurrency:
66

77
on:
88
pull_request:
9+
types: [opened, synchronize, reopened]
910

1011
permissions:
1112
contents: read
1213
pull-requests: write
1314
actions: read
15+
id-token: write
1416

1517
jobs:
1618
scan-build:
@@ -47,12 +49,9 @@ jobs:
4749
run: |
4850
find ddprof-lib/build/reports/scan-build -name 'index.html' | xargs -I {} python .github/scripts/python_utils.py scanbuild_cleanup {} ${HEAD_REF} > comment.html
4951
- name: Post or update PR comment
50-
uses: ./.github/actions/pr_comment
52+
uses: ./.github/actions/upsert-pr-comment
5153
with:
52-
github-token: ${{ secrets.GITHUB_TOKEN }}
53-
comment-id: "scan-build"
54-
commenter: "pr-comment-scanbuild"
55-
comment-file: 'comment.html'
54+
body-file: comment.html
5655

5756
cppcheck:
5857
if: needs.check-for-pr.outputs.skip != 'true'
@@ -91,12 +90,10 @@ jobs:
9190
report.html
9291
report.xml
9392
- name: Post or update PR comment
94-
uses: ./.github/actions/pr_comment
93+
uses: ./.github/actions/upsert-pr-comment
9594
with:
96-
github-token: ${{ secrets.GITHUB_TOKEN }}
97-
comment-id: "cppcheck"
98-
commenter: "pr-comment-cppcheck"
99-
comment-file: 'comment.html'
95+
body-file: comment.html
96+
10097
codeql:
10198
if: needs.check-for-pr.outputs.skip != 'true'
10299
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)