import * as httpm from '@actions/http-client'
import * as tc from '@actions/tool-cache';
import * as core from '@actions/core';
export async function getManifestFromRepo(
    owner: string,
    repo: string,
    auth?: string,
    branch = 'master'
  ): Promise<tc.IToolRelease[]> {
    const manifestUrl = `https://git.qtoa.cn/${owner}/${repo}/raw/branch/${branch}/versions-manifest.json`
    const http: httpm.HttpClient = new httpm.HttpClient('tool-cache')
    const headers: any = {}
    const response = await http.getJson<tc.IToolRelease[]>(manifestUrl, headers)
    const result = response.result ?? []
    core.info(`versions-manifest.json:\n${result}`)
    return result;
}

export async function getAvailableVersions(): Promise<tc.IToolRelease[] | null> {
  const owner = 'actions';
  const repository = 'java-versions';
  const branch = 'main';
  return await getManifestFromRepo(owner,repository,undefined,branch)
}