name: pkgx/pantry/complain
description: creates an issue for failure conditions

inputs:
  pkg:
    description: project to complain about
    required: true
  token:
    description: github token
    required: true
    default: ${{ github.token }}

runs:
  using: composite
  steps:
    - name: Find Issue
      uses: actions-cool/issues-helper@v3
      id: find
      with:
        actions: 'find-issues'
        token: ${{ inputs.token }}
        issue-state: 'open'
        title-includes: '❌ build issues: ${{ inputs.pkg }}'
        labels: 'build-failure'

    - name: Create Issue
      uses: actions-cool/issues-helper@v3
      id: create
      if: ${{ steps.find.outputs.issues == '[]' }}
      with:
        actions: 'create-issue'
        token: ${{ inputs.token }}
        title: '❌ build issues: ${{ inputs.pkg }}'
        body: 'Running log of build failure for ${{ inputs.pkg }}'
        labels: 'build-failure'
        assignees: 'jhheider'

    - name: Log Comment
      uses: actions-cool/issues-helper@v3
      with:
        actions: 'create-comment'
        token: ${{ inputs.token }}
        issue-number: ${{ steps.create.outputs.issue-number || fromJSON(steps.find.outputs.issues)[0].number }}
        body: |
          # Build failure
          ## ${{ inputs.pkg }}

          logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
