message: refactor: backport based on new pr template
diff: name: Backport
  on:
  - push:
  - branches: [ develop ]
  -
  + pull_request:
  + types: [ closed ]
  jobs:
  backport:
  - if: ${{ github.repository_owner == 'nervosnetwork' }}
  - runs-on: ubuntu-18.04
  + runs-on: ubuntu-20.04
  + if: github.event.pull_request.merged == true && contains(github.event.pull_request.body, 'Need to cherry-pick to the release branch')
  name: Backport
  steps:
  - - name: Create Reminder for Bug Fixings
  + - name: Create Reminder for cherry-pick and assign it to pr author
  run: |
  - curl \
  - --url https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} \
  - --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  - | jq -r .commit.message \
  - | grep '\([0-9]\+: \)\?fix: ' \
  - | while IFS= read -r line; do
  - title="$(echo "Backport Reminder: $line" | jq -R -c .)"
  - curl --request POST \
  - --url https://api.github.com/repos/${{ github.repository }}/issues \
  - --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
  - --data '{
  - "title": '"$title"',
  - "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: ${{ github.sha }}."
  + HTTP_RESPONSE=`curl -v -X "POST" "https://api.github.com/repos/${{ github.repository }}/issues" \
  + -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" \
  + -H "Content-Type: text/plain; charset=utf-8" \
  + --write-out "%{http_code}\n"\
  + -o /dev/null\
  + -d $'{
  + "title": "Backport #${{ github.event.number }} ${{ github.event.pull_request.title }}",
  + "body": "#${{ github.event.number }}",
  + "assignees": [
  + "${{ github.event.pull_request.user.login }}"
  + ],
  + "labels": [
  + "s:backport-needed"
  + ]
  + }'`
  +
  + if [[ $HTTP_RESPONSE == '422' ]];then
  + echo "create issue without assignees"
  + curl -v -X "POST" "https://api.github.com/repos/${{ github.repository }}/issues" \
  + -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" \
  + -H "Content-Type: text/plain; charset=utf-8" \
  + --write-out "%{http_code}\n"\
  + -o /dev/null\
  + -d $'{
  + "title": "Backport #${{ github.event.number }} ${{ github.event.pull_request.title }}",
  + "body": "#${{ github.event.number }}",
  + "labels": [
  + "s:backport-needed"
  + ]
  }'
  - done
  + fi
  +
  