Skip to content

Commit 02cf51c

Browse files
committed
chore: check if client PR exists or not
Each status-go PR should ideally be verified against a status-app PR.
1 parent 1f29a6e commit 02cf51c

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Companion PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
jobs:
12+
check-companion-pr:
13+
name: Check
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Check for companion PR
19+
id: check
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
set +e
24+
output=$(./_assets/scripts/check-companion-pr.sh "${{ github.event.pull_request.number }}" "${{ github.event.pull_request.head.sha }}")
25+
exit_code=$?
26+
set -e
27+
echo "$output"
28+
while IFS='=' read -r key value; do
29+
echo "${key,,}=${value}" >> "$GITHUB_OUTPUT"
30+
done < <(echo "$output" | grep -E '^[A-Z_]+=')
31+
exit $exit_code
32+
33+
- name: Post comment
34+
if: always()
35+
uses: actions/github-script@v7
36+
env:
37+
OUTPUTS_JSON: ${{ toJSON(steps.check.outputs) }}
38+
with:
39+
script: |
40+
const outputs = JSON.parse(process.env.OUTPUTS_JSON);
41+
const prNumber = context.payload.pull_request.number;
42+
const headSha = context.payload.pull_request.head.sha;
43+
44+
let body;
45+
if (outputs.reason === 'no_link_in_description') {
46+
body = [
47+
'<!-- companion-pr-check -->',
48+
'## ⚠️ Companion PR Required',
49+
'',
50+
'Add a link to your status-app PR in this PR\'s description.',
51+
'',
52+
'Example: `https://github.com/status-im/status-app/pull/123`'
53+
].join('\n');
54+
} else if (outputs.reason === 'sha_mismatch') {
55+
body = [
56+
'<!-- companion-pr-check -->',
57+
'## ⚠️ Companion PR Needs Update',
58+
'',
59+
'[#' + outputs.companion_pr_number + '](' + outputs.companion_pr_url + ') is not using the latest status-go commit (`' + headSha + '`).',
60+
'',
61+
'Update `vendor/status-go` in the companion PR.'
62+
].join('\n');
63+
} else if (outputs.verified === 'true') {
64+
body = [
65+
'<!-- companion-pr-check -->',
66+
'## ✅ Companion PR Verified',
67+
'',
68+
'[#' + outputs.companion_pr_number + ' - ' + outputs.companion_pr_title + '](' + outputs.companion_pr_url + ')'
69+
].join('\n');
70+
} else {
71+
return;
72+
}
73+
74+
const { data: comments } = await github.rest.issues.listComments({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
issue_number: prNumber
78+
});
79+
80+
const existing = comments.find(c => c.user.type === 'Bot' && c.body.includes('<!-- companion-pr-check -->'));
81+
82+
if (existing) {
83+
await github.rest.issues.updateComment({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
comment_id: existing.id,
87+
body
88+
});
89+
} else {
90+
await github.rest.issues.createComment({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
issue_number: prNumber,
94+
body
95+
});
96+
}

scripts/check-companion-pr.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
pr_body=$(gh api "repos/status-im/status-go/pulls/$1" --jq '.body // ""')
5+
6+
if [[ "$pr_body" =~ https://github\.com/status-im/status-app/pull/([0-9]+) ]]; then
7+
companion_pr=${BASH_REMATCH[1]}
8+
elif [[ "$pr_body" =~ status-im/status-app#([0-9]+) ]]; then
9+
companion_pr=${BASH_REMATCH[1]}
10+
else
11+
echo "REASON=no_link_in_description"
12+
exit 1
13+
fi
14+
15+
companion_json=$(gh api "repos/status-im/status-app/pulls/${companion_pr}")
16+
companion_title=$(echo "$companion_json" | jq -r '.title' | tr '\n' ' ')
17+
companion_sha=$(echo "$companion_json" | jq -r '.head.sha')
18+
19+
submodule_sha=$(gh api "repos/status-im/status-app/contents/vendor/status-go?ref=${companion_sha}" --jq '.sha')
20+
21+
if [[ "$submodule_sha" != "$2" ]]; then
22+
echo "COMPANION_PR_NUMBER=${companion_pr}"
23+
echo "COMPANION_PR_TITLE=${companion_title}"
24+
echo "COMPANION_PR_URL=https://github.com/status-im/status-app/pull/${companion_pr}"
25+
echo "REASON=sha_mismatch"
26+
exit 1
27+
fi
28+
29+
echo "COMPANION_PR_NUMBER=${companion_pr}"
30+
echo "COMPANION_PR_TITLE=${companion_title}"
31+
echo "COMPANION_PR_URL=https://github.com/status-im/status-app/pull/${companion_pr}"
32+
echo "VERIFIED=true"

0 commit comments

Comments
 (0)