18 lines
819 B
JavaScript
18 lines
819 B
JavaScript
import axios from 'axios';
|
|
import https from 'https';
|
|
import { GITEA_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER } from './config.js';
|
|
|
|
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
const headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' });
|
|
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
|
|
|
|
export async function getPRDiff() {
|
|
const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000, httpsAgent });
|
|
return resp.data;
|
|
}
|
|
|
|
export async function postComment(body) {
|
|
const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/issues/${PR_NUMBER}/comments`), { body }, { headers: headers(), timeout: 30000, httpsAgent });
|
|
return resp.data;
|
|
}
|