IOweb/node_modules/@iconify/tools/lib/download/github/hash.cjs
2026-07-03 15:07:38 -05:00

31 lines
904 B
JavaScript

'use strict';
const download_api_index = require('../api/index.cjs');
require('../api/cache.cjs');
require('fs');
require('crypto');
require('../../misc/scan.cjs');
require('../api/config.cjs');
require('../api/fetch.cjs');
async function getGitHubRepoHash(options) {
const uri = `https://api.github.com/repos/${options.user}/${options.repo}/branches/${options.branch}`;
const data = await download_api_index.sendAPIQuery({
uri,
headers: {
Accept: "application/vnd.github.v3+json",
Authorization: "token " + options.token
}
});
if (typeof data !== "string") {
throw new Error(`Error downloading data from GitHub API: ${data}`);
}
const content = JSON.parse(data);
const hash = content?.commit?.sha;
if (typeof hash !== "string") {
throw new Error("Error parsing GitHub API response");
}
return hash;
}
exports.getGitHubRepoHash = getGitHubRepoHash;