# This file was generated by GoReleaser. DO NOT EDIT.
cask "custom_block_url" do
  module GitHubHelper
    def self.token
      require "utils/github"

      # Prefer environment variable if available
      github_token = ENV["HOMEBREW_GITHUB_API_TOKEN"]
      github_token ||= GitHub::API.credentials
      raise "Failed to retrieve github api token" if github_token.nil? || github_token.empty?

      github_token
    end

    def self.release_asset_url(tag, name)
      require "json"
      require "net/http"
      require "uri"

      resp = Net::HTTP.get(
        # Replace with your GitHub repository URL
        URI.parse("https://api.github.com/repos/goreleaser/example/releases/tags/#{tag}"),
        {
          "Accept" => "application/vnd.github+json",
          "Authorization" => "Bearer #{token}",
          "X-GitHub-Api-Version" => "2022-11-28"
        }
      )

      release = JSON.parse(resp)
      release["assets"].find { |asset| asset["name"] == name }["url"]
    end
  end

  version "1.0.1"

  on_macos do
    on_intel do
      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
      url "#{GitHubHelper.release_asset_url("v#{version}", "bin.tgz")}",
        header: [
          "Accept: application/octet-stream",
          "Authorization: Bearer #{GitHubHelper.token}",
          "X-GitHub-Api-Version: 2022-11-28",
        ]
    end
    on_arm do
      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
      url "#{GitHubHelper.release_asset_url("v#{version}", "bin.txz")}",
        header: [
          "Accept: application/octet-stream",
          "Authorization: Bearer #{GitHubHelper.token}",
          "X-GitHub-Api-Version: 2022-11-28",
        ]
    end
  end

  on_linux do
    on_intel do
      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
      url "#{GitHubHelper.release_asset_url("v#{version}", "bin.tar.zst")}",
        header: [
          "Accept: application/octet-stream",
          "Authorization: Bearer #{GitHubHelper.token}",
          "X-GitHub-Api-Version: 2022-11-28",
        ]
    end
  end

  name "custom_block_url"
  desc "Run pipe test formula and FOO=foo_is_bar"
  homepage "https://github.com/goreleaser"

  livecheck do
    skip "Auto-generated on release."
  end
  conflicts_with cask: [
      "fish",
    ]

  depends_on cask: [
      "fish",
      "powershell",
    ],
    formula: [
      "ash",
      "bash",
      "zsh",
    ]

  binary "custom_block_url"

  service "foo.plist"

  postflight do
    system "echo"
    touch "/tmp/hi"
  end

  # No zap stanza required

  caveats <<~EOS
    don't do this custom_block_url
  EOS
end
