github.heygears.com/openimsdk/tools@v0.0.49/.github/workflows/auto-gh-pr.yml (about)

     1  # Copyright © 2023 OpenIM open source community. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  name: Auto PR to release
    16  
    17  on:
    18    pull_request:
    19      # types:
    20      #   - closed
    21    issue_comment:
    22      types: [created]
    23    pull_request_review_comment:
    24      types: [created]
    25  
    26  jobs:
    27    sync-issue-to-pr:
    28      runs-on: ubuntu-latest
    29      steps:
    30        - name: Checkout code
    31          uses: actions/checkout@v4
    32        
    33        - name: Sync Issue to PR
    34          if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main'
    35          run: |
    36            PR_BODY="${{ github.event.pull_request.body }}"
    37  
    38            ISSUE_NUMBER=$(echo "$PR_BODY" | grep -oP 'Fixes #\K\d+')
    39            if [[ -z "$ISSUE_NUMBER" ]]; then
    40              echo "No Issue number found."
    41              exit 1
    42            fi
    43  
    44            echo "Issue number found: $ISSUE_NUMBER"
    45  
    46            # Using GitHub CLI to get issue details
    47            gh issue view "$ISSUE_NUMBER" --repo "${{ github.repository }}" --json labels,assignees,milestone,title > issue_data.json
    48  
    49            # Check if jq is installed
    50            if ! command -v jq &> /dev/null; then
    51              echo "Installing jq..."
    52              sudo apt-get install -y jq
    53            fi
    54  
    55            # Parse data with jq
    56            LABELS=$(jq -r '.labels | map(.name) | join(",")' issue_data.json)
    57            ASSIGNEES=$(jq -r '.assignees | map(.login) | join(",")' issue_data.json)
    58            MILESTONE=$(jq -r '.milestone.title' issue_data.json)
    59  
    60            # Check if any of the fields are empty and set them to None
    61            LABELS=${LABELS:-None}
    62            ASSIGNEES=${ASSIGNEES:-None}
    63            MILESTONE=${MILESTONE:-None}
    64  
    65            # Edit the PR with issue details, handling empty fields
    66            gh pr edit "${{ github.event.pull_request.number }}" --repo "${{ github.repository }}" \
    67              ${LABELS:+--add-label "$LABELS"} \
    68              ${ASSIGNEES:+--add-assignee "$ASSIGNEES"} \
    69              ${MILESTONE:+--milestone "$MILESTONE"}
    70          continue-on-error: true
    71          env:
    72            GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}