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
0 commit comments