name: Create jira issue from github issue

on:
  issues:
    types: [opened]

jobs:
  update_jira:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.1.1

      - name: Generate a token
        id: generate_token
        uses: actions/create-github-app-token@v1
        with:
          app-id: ${{ secrets.AUTH_APP_ID }}
          private-key: ${{ secrets.AUTH_APP_PK }}

      - name: Jira Create issue
        id: create
        uses: corda/jira-create-issue-action@master
        with:
          jiraBaseUrl: https://r3-cev.atlassian.net
          project: CORDA
          squad: Corda
          issuetype: Bug
          summary: ${{ github.event.issue.title }}
          labels: community
          jiraEmail: ${{ secrets.JIRA_USER_EMAIL }}
          jiraToken: ${{ secrets.JIRA_API_TOKEN }}
          description: |
            ${{ github.event.issue.body }}

            Created by github action.

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v4.0.0
        with:
          token: ${{ steps.generate_token.outputs.token }}
          issue-number: ${{ github.event.issue.number }}
          body: |
            Automatically created Jira issue: ${{ steps.create.outputs.issue }}
          reaction-type: '+1'
