import * as http from 'http'; import * as https from 'https'; import * as vscode from 'vscode'; const { generateKeyPairSync, } = require('node:crypto') const axios = require('axios'); const cheerio = require('cheerio'); export function fetch(url: string): Promise { // determine the library to use (based on the url protocol) const lib = url.startsWith('https://') ? https : http; return new Promise((resolve, reject) => { lib.get(url, (response) => { // make sure the status code is 200 if (response.statusCode !== 200) { reject(new Error(`Failed to load page, status code: ${response.statusCode}`)); return; } let data = ''; response.on('data', (chunk) => { data += chunk; }); response.on('end', () => { resolve(data); }); }).on('error', (err) => { reject(err); }); }); } export const Sleep = (ms: number) => { return new Promise(resolve => setTimeout(resolve, ms)) } export async function getVsCodeCommitId(): Promise { // 获取vscode version const version = vscode.version // 根据version提取相应的release页面中的commitid try{ const { data } = await axios.get(`https://github.com/microsoft/vscode/releases/tag/${version}`); // Load the HTML into cheerio const $ = cheerio.load(data); // Find the tag with the 'data-hovercard-type="commit"' attribute const commitLink = $('a[data-hovercard-type="commit"]'); // Extract the href attribute and commit hash const href = commitLink.attr('href'); // href example: /microsoft/vscode/commit/fabdb6a30b49f79a7aba0f2ad9df9b399473380f const commitHash = href.split('/').pop(); return commitHash } catch(error) { console.error('Failed to get commit id: ' + error) return "" } }