name: Merge Elastic updates

on:
  workflow_run:
    workflows: [ CI ]
    types:
      - completed
    branches:
      - update/main
      - update/release-6.x

jobs:

  merge:
    name: Merge pull request
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    runs-on: ubuntu-latest

    steps:
      - name: Approve and merge
        uses: ridedott/merge-me-action@v2
        with:
          GITHUB_LOGIN: docker-elk-updater
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

name: Merge Elastic updates

on:
  workflow_run:
    workflows: [ CI ]
    types:
      - completed
    branches:
      - update/main
      - update/release-6.x

jobs:

  merge:
    name: Merge pull request
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    runs-on: ubuntu-latest

    steps:
      - name: Approve and merge
        uses: ridedott/merge-me-action@v2
        with:
          GITHUB_LOGIN: docker-elk-updater
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Delete branch
        uses: actions/github-script@v5
        with:
          script: |
            await github.request('DELETE /repos/{owner}/{repo}/git/refs/{ref}', {
              owner: '${{ github.event.workflow_run.repository.owner.login }}',
              repo: '${{ github.event.workflow_run.repository.name }}',
              ref: 'heads/${{ github.event.workflow_run.head_branch }}'
            })

Delete branch after successful Elastic update merge
ci: Delete branch after successful Elastic update merge
