diff --git a/.github/workflows/move-on-merge-conflict.yaml b/.github/workflows/move-on-merge-conflict.yaml index d2937efb8..91f2dfb1e 100644 --- a/.github/workflows/move-on-merge-conflict.yaml +++ b/.github/workflows/move-on-merge-conflict.yaml @@ -3,6 +3,9 @@ name: Check Merge Conflicts and Update Jira on: workflow_call: + secrets: + JIRA_AUTH: { required: true } + GITHUB_TOKEN: { required: true } push: jobs: @@ -18,22 +21,34 @@ jobs: - name: Get branches to process id: get_branches - run: | - echo "No branches provided as input, fetching branches starting with NDT" - git fetch --all - branches=$(git branch -r | grep 'origin/NDT' | sed 's|origin/||' | xargs) - if [ -z "$branches" ]; then - echo "No branches starting with 'NDT' found." - echo "branches=[]" >> $GITHUB_OUTPUT - exit 0 - fi - branches_json=$(printf '%s\n' $branches | jq -R . | jq -s .) - echo "Branches to process: $branches_json" - echo "branches=$branches_json" >> $GITHUB_OUTPUT + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const {owner, repo } = context.repo; + const { data: pullRequests } = await github.pulls.lise({ + owner, + repo, + state: 'open', + }); + const branches = [] + const filteredPrs = pullRequests.filter(pr => !pr.head.repo.fork && pr.head.ref.startsWith('NDT-') && !pr.draft); + for (const pr of filteredPrs) { + const prReviews = await github.pulls.listReviews({ + owner, + repo, + pull_number: pr.number, + }); + const approved = prReviews.data.some(review => review.state === 'APPROVED'); + if(approved) { + branches.push(pr.head.ref); + } + } + return branches; - name: Process branches env: - BRANCHES: ${{ steps.get_branches.outputs.branches }} + BRANCHES: ${{ steps.get_branches.outputs.result }} JIRA_AUTH: ${{ secrets.JIRA_AUTH }} run: | set -e