georgereuben commented on code in PR #14927: URL: https://github.com/apache/lucene/pull/14927#discussion_r2196923309
########## .github/workflows/auto-format.yml: ########## @@ -0,0 +1,268 @@ +name: Lucene Auto Format Bot + +on: + issue_comment: + types: [created] + +env: + DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + format-check: + # Only run on pull requests when the bot is mentioned + if: | + github.event.issue.pull_request && + contains(github.event.comment.body, '/format-fix apply') + runs-on: ubuntu-latest + timeout-minutes: 30 + + permissions: + contents: write + pull-requests: write + issues: write + + steps: + - name: Check permissions + run: | + PR_AUTHOR=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json author --jq '.author.login') + + PERMISSION=$(gh api repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission --jq '.permission' 2>/dev/null || echo "none") + + # only allow if user is PR author OR has admin/write repository access + if [[ "${{ github.actor }}" == "$PR_AUTHOR" ]] || [[ "$PERMISSION" == "admin" ]] || [[ "$PERMISSION" == "write" ]]; then + echo "Permission granted: User @${{ github.actor }} can run the format bot" + if [[ "${{ github.actor }}" == "$PR_AUTHOR" ]]; then + echo " - Reason: PR author" + fi + if [[ "$PERMISSION" == "admin" ]] || [[ "$PERMISSION" == "write" ]]; then + echo " - Reason: Repository $PERMISSION access" + fi + else + echo "Error: User @${{ github.actor }} does not have permission to run the format bot." + echo "Required: Be the PR author OR have admin/write repository access." + exit 1 + fi + + - name: Add workflow started reaction + run: | + gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions \ + --method POST \ + --input - <<< '{"content":"eyes"}' + + - name: Get PR details and checkout + run: | + # Get PR details + PR_DATA=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName,headRepository,headRepositoryOwner) + HEAD_REF=$(echo "$PR_DATA" | jq -r '.headRefName') + HEAD_REPO=$(echo "$PR_DATA" | jq -r '.headRepository.name') + HEAD_OWNER=$(echo "$PR_DATA" | jq -r '.headRepositoryOwner.login') + + echo "head_ref=$HEAD_REF" >> $GITHUB_ENV + echo "head_repo_full=$HEAD_OWNER/$HEAD_REPO" >> $GITHUB_ENV + + - name: Checkout PR code + uses: actions/checkout@v4 + with: + repository: ${{ env.head_repo_full }} + ref: ${{ env.head_ref }} + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' Review Comment: Updated with the existing prepare-for-build action -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org