name: gitea-query-packages
description: "Change the language format of a file."
inputs:
  url:
    description: "Url of the Gitea 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 Gitea."
    required: true
    default: ${{ github.token }}
  type:
    description: "The type of package to search for."
    required: false
    default: ""
  page:
    description: "The page number of results to return."
    required: false
    default: ""
  limit:
    description: "The page size of results."
    required: false
    default: ""
  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="/api/v1/packages/${{ inputs.organization }}?"
      NAME="${{ inputs.name }}"
      TYPE="${{ inputs.type }}"
      PAGE="${{ inputs.page }}"
      LIMIT="${{ inputs.limit }}"

      if [[ -n "$NAME" ]]; then
        ROUTE="${ROUTE}q=$NAME&"
      fi
      if [[ -n "$TYPE" ]]; then
        ROUTE="${ROUTE}type=$TYPE&"
      fi
      if [[ -n "$PAGE" ]]; then
        ROUTE="${ROUTE}page=$PAGE&"
      fi
      if [[ -n "$LIMIT" ]]; then
        ROUTE="${ROUTE}limit=$LIMIT&"
      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 }}
