name: Create PR
on:
  push:
    branches:
      - stable

jobs:
  PR:
    name: Create
    if: github.repository_owner == 'votca'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@master
        with:
          ref: ${{ github.event.ref }}
          fetch-depth: 0
          token: ${{ secrets.VOTCA_BOT_TOKEN }}
      - name: Try to merge master branch
        run: |
          git config --global user.name "Votca Bot"
          git config --global user.email "github@votca.org"
          git checkout -b stable_fixes
          git merge origin/master || true
          git push origin stable_fixes
      - name: Create Pull Request
        uses: actions/github-script@0.3.0
        with:
          github-token: ${{ secrets.VOTCA_BOT_TOKEN }}
          script: |
            github.pulls.create({
              owner: 'votca',
              repo: 'xtp-tutorials',
              title: 'Fixes from stable',
              head: 'stable_fixes',
              base: 'master'
            })
