Skip to content

Commit 780d08a

Browse files
author
Nitesh
committed
resolve merge conflict
2 parents 2c21165 + e9c37f5 commit 780d08a

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

.github/workflows/require-docs.yml

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,47 @@ jobs:
99
name: Check Documentation Update
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v4
14-
1512
- name: Check if Documentation is Required
1613
id: check_docs
1714
run: |
18-
echo "Checking PR body for documentation checkbox..."
19-
# Read the PR body from the GitHub event payload
20-
if echo "${{ github.event.pull_request.body }}" | grep -qi '\[x\].*documentation needed'; then
15+
# Read PR body from the event JSON file — never from shell interpolation.
16+
# jq handles all escaping; the shell never sees the user-controlled string.
17+
if jq -r '.pull_request.body // ""' "$GITHUB_EVENT_PATH" | \
18+
grep -qi '\[x\].*documentation needed'; then
2119
echo "Documentation required detected."
22-
echo "docs_required=true" >> $GITHUB_OUTPUT
20+
echo "docs_required=true" >> "$GITHUB_OUTPUT"
2321
else
2422
echo "Documentation not required."
25-
echo "docs_required=false" >> $GITHUB_OUTPUT
23+
echo "docs_required=false" >> "$GITHUB_OUTPUT"
2624
fi
2725
2826
- name: Enforce Documentation Update (if required)
2927
if: steps.check_docs.outputs.docs_required == 'true'
30-
env:
31-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
run: |
33-
# Retrieve feature branch and repository owner from the GitHub context
34-
FEATURE_BRANCH="${{ github.head_ref }}"
35-
REPO_OWNER="${{ github.repository_owner }}"
36-
WEBSITE_REPO="website"
37-
echo "Searching for a merged documentation PR for feature branch: $FEATURE_BRANCH in $REPO_OWNER/$WEBSITE_REPO..."
38-
MERGED_PR=$(gh pr list --repo "$REPO_OWNER/$WEBSITE_REPO" --state merged --json headRefName,title,url | jq -r \
39-
--arg FEATURE_BRANCH "$FEATURE_BRANCH" '.[] | select(.title | contains($FEATURE_BRANCH)) | .url')
40-
if [[ -z "$MERGED_PR" ]]; then
41-
echo ":x: Documentation PR for branch '$FEATURE_BRANCH' is required and has not been merged."
42-
exit 1
43-
else
44-
echo ":white_check_mark: Found merged documentation PR: $MERGED_PR"
45-
fi
28+
uses: actions/github-script@v7
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
script: |
32+
const featureBranch = context.payload.pull_request.head.ref;
33+
const repoOwner = context.repo.owner;
34+
const websiteRepo = 'website';
35+
36+
core.info(`Searching for a merged documentation PR for feature branch: ${featureBranch} in ${repoOwner}/${websiteRepo}...`);
37+
38+
const { data: pulls } = await github.rest.pulls.list({
39+
owner: repoOwner,
40+
repo: websiteRepo,
41+
state: 'closed',
42+
per_page: 100,
43+
});
44+
45+
const mergedPr = pulls.find(
46+
(pr) => pr.merged_at && pr.title.includes(featureBranch)
47+
);
48+
49+
if (!mergedPr) {
50+
core.setFailed(
51+
`❌ Documentation PR for branch '${featureBranch}' is required and has not been merged.`
52+
);
53+
} else {
54+
core.info(`✅ Found merged documentation PR: ${mergedPr.html_url}`);
55+
}

0 commit comments

Comments
 (0)