Skip to content

Commit afb5ae9

Browse files
committed
feat(pr-workflow): validate feature flag key format in PR body when feature flag label is present
1 parent 0f7fe58 commit afb5ae9

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

.github/workflows/pr-request-report-labels.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ jobs:
4343
elif [ "$total_count" -gt 1 ]; then
4444
echo "valid=false" >> "$GITHUB_OUTPUT"
4545
echo "message=Only one report label is allowed: \`report: include\`, \`report: exclude\` OR \`report: highlight\`." >> "$GITHUB_OUTPUT"
46+
fi
47+
48+
feature_flag_count="$(jq '[.[] | select(.name == "feature flag")] | length' <<< "$labels_json")"
49+
if [ "$feature_flag_count" -gt 0 ]; then
50+
pr_body='${{ toJson(github.event.pull_request.body) }}'
51+
pr_feature_flag_key="$(jq -nr --arg body "$pr_body" 'try ($body | gsub("\r"; "") | capture("(?m)^feature-flag:\\s*`(?<flag>[^`]+)`$").flag) catch ""')"
52+
if [ -z "$pr_feature_flag_key" ]; then
53+
echo "valid=false" >> "$GITHUB_OUTPUT"
54+
echo "message=PR body must contain the feature flag key in the format: \`feature-flag: \\\`<feature-flag-key>\\\`\`." >> "$GITHUB_OUTPUT"
55+
else
56+
echo "valid=true" >> "$GITHUB_OUTPUT"
57+
fi
4658
else
4759
echo "valid=true" >> "$GITHUB_OUTPUT"
4860
fi

0 commit comments

Comments
 (0)