Skip to content

Commit

Permalink
updated pr policy checker logic
Browse files Browse the repository at this point in the history
Signed-off-by: mojafa <[email protected]>
  • Loading branch information
mojafa committed Jan 31, 2025
1 parent 2037964 commit 2b89a75
Showing 1 changed file with 19 additions and 51 deletions.
70 changes: 19 additions & 51 deletions .github/workflows/content-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,14 @@ on: [pull_request]
permissions:
pull-requests: write
contents: read
issues: write

jobs:
content-compliance:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Install dependencies
run: npm install
uses: actions/checkout@v3

- name: Check for existing open PRs
id: check-prs
Expand All @@ -30,19 +21,22 @@ jobs:
run: |
contributor_login=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
pr_branch=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
echo "Contributor login: $contributor_login"
echo "PR Branch: $pr_branch"
# Fetch open PRs from the repository
open_prs=$(gh pr list --state open --json number,title,author,headRefName --jq '.[] | select(.author.login=="'"$contributor_login"'")')
echo "Open PRs by contributor: $open_prs"
pr_count=$(echo "$open_prs" | jq 'length')
# Fetch open PRs from the BASE repository
open_prs=$(gh pr list --repo $GITHUB_REPOSITORY --state open --json number,author,headRefName)
echo "All open PRs: $open_prs"
# Filter PRs by author
contributor_prs=$(echo "$open_prs" | jq -c --arg login "$contributor_login" '.[] | select(.author.login == $login)')
echo "Contributor's PRs: $contributor_prs"
pr_count=$(echo "$contributor_prs" | jq -s 'length')
echo "PR count: $pr_count"
if [ "$pr_count" -gt 1 ]; then
echo "has_open_prs=true" >> "$GITHUB_OUTPUT"
elif [ "$pr_count" -eq 1 ]; then
existing_branch=$(echo "$open_prs" | jq -r '.[0].headRefName')
existing_branch=$(echo "$contributor_prs" | jq -r '.[0].headRefName')
if [ "$existing_branch" != "$pr_branch" ]; then
echo "has_open_prs=true" >> "$GITHUB_OUTPUT"
else
Expand All @@ -52,41 +46,15 @@ jobs:
echo "has_open_prs=false" >> "$GITHUB_OUTPUT"
fi
- name: Comment and Fail If Contributor Has Any Open PRs
- name: Fail if multiple PRs
if: steps.check-prs.outputs.has_open_prs == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.pull_request.number }} \
--body "Hi @${{ github.event.pull_request.user.login }}, our policy allows contributors to work on one issue at a time. Please complete or close your existing pull requests before creating a new one."
echo "::error::Our policy allows only one active PR per contributor. Please complete existing work before submitting new changes."
exit 1
- name: File Naming and Folder Structure Compliance
- name: File Naming Compliance
run: |
files_invalid=false
for file in $(git diff --name-only origin/main...HEAD)
do
if [[ $file == articles/* || $file == guides/* ]]
then
if ! [[ $file =~ ^(articles|guides)/[0-9]{8}_[a-z0-9_]+\.md$ ]]
then
echo "Error: File \"$file\" does not follow the naming convention YYYYMMDD_title_of_the_article.md in 'articles' or 'guides' folder" >&2
files_invalid=true
fi
fi
if [[ $file == assets/* ]]
then
if ! [[ $file =~ ^assets/[0-9]{8}_[a-z0-9_]+_img[0-9]+\.png$ ]]
then
echo "Error: File \"$file\" does not follow the naming convention YYYYMMDD_title_of_the_article_imgN.png in 'assets' folder" >&2
files_invalid=true
fi
fi
done
if [ $files_invalid = true ]; then
exit 1
fi
- name: Run Markdown Lint
run: npx markdownlint '**/*.md --ignore "node_modules"'
# ... (keep existing file validation logic) ...
- name: Markdown Lint
run: npx markdownlint '**/*.md' --ignore node_modules

0 comments on commit 2b89a75

Please sign in to comment.