name: github-query-nuget
description: "Make a query to the GitHub NuGet api."
inputs:
  url:
    description: "Url of the GitHub server repository."
    required: true
    default: ${{ github.server_url }}
  organization:
    description: "Organization to search."
    required: true
    default: ${{ github.repository_owner }}
  apiToken:
    description: "Api Token to for GitHub."
    required: true
    default: ${{ github.token }}
  prerelease:
    description: "Show prerelease packages. Values: true, false."
    required: false
    default: "false"
  name:
    description: "Name of a specific package."
    required: false
    default: ""
  additionalArgs:
    description: "Additional arguments to pass into curl."
    required: false
outputs:
  query:
    description: "The query result."
    value: ${{ steps.query.outputs.query }}
runs:
  using: "composite"
  steps:
  - name: "Build route."
    id: route
    run: |
      ROUTE="/_registry/nuget/${{ inputs.organization }}/query?"
      NAME="${{ inputs.name }}"
      PRERELEASE="${{ inputs.prerelease }}"
      if [[ "$PRERELEASE" == "true" ]]; then
        ROUTE="${ROUTE}prerelease=true&"
      fi
      if [[ -n "$NAME" ]]; then
        ROUTE="${ROUTE}q=$NAME"
      fi

      echo "route=$ROUTE" >> "$GITHUB_OUTPUT"
    shell: bash
  - name: "Build and run query."
    id: query
    uses: act/common/github/github-query@master
    with:
      url: ${{ inputs.url }}
      route: ${{ steps.route.outputs.route }}
      apiToken: ${{ inputs.apiToken }}
      additionalArgs: ${{ inputs.additionalArgs }}
