Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions .github/workflows/pull-request-formatting-validator.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# This workflow validates basic pull request formatting requirements are met.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
# NOTE: This file is automatically synchronized from Patina DevOps. Update the original file there
# instead of the file in this repo.
#
# - Patina DevOps Repo: https://github.com/OpenDevicePartnership/patina-devops
# - File Sync Settings: https://github.com/OpenDevicePartnership/patina-devops/blob/main/.sync/Files.yml
##
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0
##

name: Validate Pull Request Formatting

Expand All @@ -18,11 +24,15 @@ jobs:
validate_pr:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- name: Generate Token
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.PATINA_AUTOMATION_APPLICATION_ID }}
private-key: ${{ secrets.PATINA_AUTOMATION_APPLICATION_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- run: |
prTitle="$(gh api graphql -F owner=$OWNER -F name=$REPO -F pr_number=$PR_NUMBER -f query='
query($name: String!, $owner: String!, $pr_number: Int!) {
Expand All @@ -31,15 +41,19 @@ jobs:
title
}
}
}')"
}' --jq '.data.repository.pullRequest.title')"

comments="$(gh api "repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/comments" --paginate --jq '.[].body')"

if [[ "${prTitle}" == *"Personal/"* ]]; then
gh pr comment $PR_URL --body "⚠️ Please add a meaningful PR title (remove the 'Personal/' prefix from the title)."
if [[ "${prTitle}" == "Repo File Sync: synced file(s) with OpenDevicePartnership/patina-devops" ]]; then
if ! echo "${comments}" | grep -qF '<!-- pr-val-sync-title -->'; then
gh pr comment $PR_URL --body "<!-- pr-val-sync-title -->⚠️ Please add a meaningful PR title (update the default file sync title)."
fi
echo 'VALIDATION_ERROR=true' >> $GITHUB_ENV
fi

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
OWNER: ${{ github.repository_owner }}
PR_NUMBER: ${{ github.event.number }}
PR_URL: ${{ github.event.pull_request.html_url }}
Expand Down
Loading