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

inputs:
  projects:
    description: projects to complain about
    required: true
  platform:
    description: platform key
    required: true
  token:
    description: github token
    required: true
    default: ${{ github.token }}
  # slack-webhook:
  #   description: slack webhook
  #   required: false
  # slack-channel:
  #   description: slack channel
  #   required: false

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.projects }}"
        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.projects }}"
        body: "Running log of build failures for ${{ inputs.projects }}"
        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.projects }}
          ### ${{ inputs.platform }}

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

    # - uses: martialonline/workflow-status@v3
    #   id: status

    # - uses: rtCamp/action-slack-notify@v2
    #   if: ${{ inputs.slack-webhook != '' }}
    #   env:
    #     SLACK_WEBHOOK: ${{ inputs.slack-webhook }}
    #     SLACK_CHANNEL: ${{ inputs.slack-channel }}
    #     SLACK_MESSAGE: new-version:${{ inputs.projects }} (${{ inputs.platform }}) ${{ steps.status.outputs.status }}
    #     SLACK_COLOR: ${{ steps.status.outputs.status }}
