mirror of
https://github.com/kekxv/AiReviewPR.git
synced 2025-02-11 22:41:50 +01:00
ai 代码审核
This commit is contained in:
79
dist/utils.js
vendored
Normal file
79
dist/utils.js
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.post = exports.doesAnyPatternMatch = exports.split_message = void 0;
|
||||
const http_1 = __importDefault(require("http"));
|
||||
const https_1 = __importDefault(require("https"));
|
||||
function split_message(files) {
|
||||
console.log("files debug:", files);
|
||||
files = files.trim();
|
||||
if (!files) {
|
||||
let t = files.split("\n");
|
||||
if (t.length > 0)
|
||||
return t.map(str => str.trim());
|
||||
return files.split(",").map(str => str.trim());
|
||||
}
|
||||
return [];
|
||||
}
|
||||
exports.split_message = split_message;
|
||||
function doesAnyPatternMatch(patterns, str) {
|
||||
// 遍历正则表达式数组
|
||||
return patterns.some(pattern => {
|
||||
// 创建正则表达式对象,匹配模式
|
||||
const regex = new RegExp(pattern);
|
||||
// 测试字符串是否与正则表达式匹配
|
||||
return regex.test(str);
|
||||
});
|
||||
}
|
||||
exports.doesAnyPatternMatch = doesAnyPatternMatch;
|
||||
/**
|
||||
* post data
|
||||
* @param url url
|
||||
* @param body post data
|
||||
* @param header post header
|
||||
* @param json is json res
|
||||
*/
|
||||
async function post({ url, body, header, json }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
json = typeof json === "boolean" ? json : true;
|
||||
const data = typeof body === "string" ? body : JSON.stringify(body);
|
||||
let url_ = new URL(url);
|
||||
header = header || {};
|
||||
header['Content-Type'] = header['Content-Type'] || 'application/json';
|
||||
header['Content-Length'] = Buffer.byteLength(data);
|
||||
const options = {
|
||||
hostname: url_.hostname,
|
||||
path: url_.pathname + (url_.search || ''),
|
||||
method: 'POST',
|
||||
headers: header
|
||||
};
|
||||
// noinspection DuplicatedCode
|
||||
const req = (url_.protocol === "http" ? http_1.default : https_1.default).request(options, (res) => {
|
||||
let responseBody = '';
|
||||
res.on('data', (chunk) => {
|
||||
responseBody += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
if (json) {
|
||||
resolve(JSON.parse(responseBody));
|
||||
}
|
||||
else {
|
||||
resolve(responseBody);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
reject(new Error('Failed to parse JSON response'));
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on('error', (error) => {
|
||||
reject(new Error(`Request failed: ${error.message}`));
|
||||
});
|
||||
req.write(data);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
exports.post = post;
|
||||
Reference in New Issue
Block a user