2024-09-18 13:53:31 +08:00
|
|
|
import * as http from 'http';
|
|
|
|
import * as https from 'https';
|
2025-01-08 18:36:59 +08:00
|
|
|
import * as vscode from 'vscode';
|
2024-10-17 12:15:32 +08:00
|
|
|
const {
|
|
|
|
generateKeyPairSync,
|
|
|
|
} = require('node:crypto')
|
2025-01-08 18:36:59 +08:00
|
|
|
const axios = require('axios');
|
|
|
|
const cheerio = require('cheerio');
|
2024-09-18 13:53:31 +08:00
|
|
|
|
|
|
|
export function fetch(url: string): Promise<string> {
|
2024-11-12 19:07:30 +08:00
|
|
|
// determine the library to use (based on the url protocol)
|
|
|
|
const lib = url.startsWith('https://') ? https : http;
|
2024-09-18 13:53:31 +08:00
|
|
|
|
2024-11-12 19:07:30 +08:00
|
|
|
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;
|
|
|
|
}
|
2024-09-18 13:53:31 +08:00
|
|
|
|
2024-11-12 19:07:30 +08:00
|
|
|
let data = '';
|
|
|
|
response.on('data', (chunk) => {
|
|
|
|
data += chunk;
|
|
|
|
});
|
|
|
|
response.on('end', () => {
|
|
|
|
resolve(data);
|
|
|
|
});
|
|
|
|
}).on('error', (err) => {
|
|
|
|
reject(err);
|
2024-09-18 13:53:31 +08:00
|
|
|
});
|
2024-11-12 19:07:30 +08:00
|
|
|
});
|
2024-09-18 13:53:31 +08:00
|
|
|
}
|
2024-08-22 11:48:02 +08:00
|
|
|
|
2024-11-12 19:07:30 +08:00
|
|
|
export const Sleep = (ms: number) => {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
2024-08-22 11:48:02 +08:00
|
|
|
}
|
|
|
|
|
2025-01-08 18:36:59 +08:00
|
|
|
export async function getVsCodeCommitId(): Promise<string> {
|
|
|
|
// 获取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 <a> 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 ""
|
|
|
|
}
|
2024-10-17 12:15:32 +08:00
|
|
|
}
|