a71f801c3f
- Prisma schema: User, Session, RepoConfig, Preview, Job, WebhookToken, NoConfigComment, AdminSettings - Backend: auth (login/logout/me/first-user setup), webhook handler with HMAC verification, EC2 service, SSH service, deploy pipeline, job queue worker, cron workers - Frontend: Login with first-user detection, Dashboard, PreviewDetail with live log streaming, Settings, Repos config, Admin panel, SetupWizard, Privacy page - Docker Compose and Dockerfile for self-hosted deployment - Uses bcryptjs for Node 24 compatibility Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
171 lines
5.6 KiB
JavaScript
171 lines
5.6 KiB
JavaScript
"use strict";
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var gitea_exports = {};
|
|
__export(gitea_exports, {
|
|
buildPrCommentBody: () => buildPrCommentBody,
|
|
checkUserPermission: () => checkUserPermission,
|
|
deleteWebhook: () => deleteWebhook,
|
|
fetchUserRepos: () => fetchUserRepos,
|
|
getRepoCollaboratorPermission: () => getRepoCollaboratorPermission,
|
|
giteaApi: () => giteaApi,
|
|
postComment: () => postComment,
|
|
registerWebhook: () => registerWebhook,
|
|
updateComment: () => updateComment,
|
|
updateWebhookSecret: () => updateWebhookSecret,
|
|
validateGiteaUrl: () => validateGiteaUrl
|
|
});
|
|
module.exports = __toCommonJS(gitea_exports);
|
|
var import_axios = __toESM(require("axios"));
|
|
var import_encryption = require("../lib/encryption");
|
|
function giteaApi(user) {
|
|
const pat = user.giteaPAT ? (0, import_encryption.decrypt)(user.giteaPAT) : "";
|
|
return import_axios.default.create({
|
|
baseURL: `${user.giteaInstanceUrl}/api/v1`,
|
|
headers: {
|
|
Authorization: `token ${pat}`,
|
|
"Content-Type": "application/json"
|
|
},
|
|
timeout: 15e3
|
|
});
|
|
}
|
|
async function validateGiteaUrl(url) {
|
|
try {
|
|
const res = await import_axios.default.get(`${url}/api/v1/version`, { timeout: 1e4 });
|
|
return { success: true, version: res.data.version };
|
|
} catch (e) {
|
|
return { success: false, error: e.message };
|
|
}
|
|
}
|
|
async function fetchUserRepos(user) {
|
|
const api = giteaApi(user);
|
|
const repos = [];
|
|
let page = 1;
|
|
while (true) {
|
|
const res = await api.get(`/repos/search?limit=50&page=${page}`);
|
|
const data = res.data?.data ?? [];
|
|
if (data.length === 0) break;
|
|
repos.push(...data);
|
|
if (data.length < 50) break;
|
|
page++;
|
|
}
|
|
return repos;
|
|
}
|
|
async function registerWebhook(user, owner, repo, webhookUrl, secret) {
|
|
const api = giteaApi(user);
|
|
const res = await api.post(`/repos/${owner}/${repo}/hooks`, {
|
|
type: "gitea",
|
|
config: {
|
|
url: webhookUrl,
|
|
secret,
|
|
content_type: "json"
|
|
},
|
|
events: ["pull_request", "issue_comment"],
|
|
active: true
|
|
});
|
|
return res.data.id;
|
|
}
|
|
async function deleteWebhook(user, owner, repo, hookId) {
|
|
const api = giteaApi(user);
|
|
await api.delete(`/repos/${owner}/${repo}/hooks/${hookId}`);
|
|
}
|
|
async function updateWebhookSecret(user, owner, repo, hookId, webhookUrl, newSecret) {
|
|
const api = giteaApi(user);
|
|
await api.patch(`/repos/${owner}/${repo}/hooks/${hookId}`, {
|
|
config: {
|
|
url: webhookUrl,
|
|
secret: newSecret,
|
|
content_type: "json"
|
|
},
|
|
events: ["pull_request", "issue_comment"],
|
|
active: true
|
|
});
|
|
}
|
|
async function postComment(user, owner, repo, issueNumber, body) {
|
|
const api = giteaApi(user);
|
|
const res = await api.post(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { body });
|
|
return res.data.id;
|
|
}
|
|
async function updateComment(user, owner, repo, commentId, body) {
|
|
const api = giteaApi(user);
|
|
await api.patch(`/repos/${owner}/${repo}/issues/comments/${commentId}`, { body });
|
|
}
|
|
async function checkUserPermission(user, owner, repo, username) {
|
|
try {
|
|
const api = giteaApi(user);
|
|
const res = await api.get(`/repos/${owner}/${repo}/collaborators/${username}`);
|
|
return res.status === 204;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
async function getRepoCollaboratorPermission(user, owner, repo, username) {
|
|
try {
|
|
const api = giteaApi(user);
|
|
const res = await api.get(`/repos/${owner}/${repo}/collaborators/${username}/permission`);
|
|
return res.data?.permission ?? null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
function buildPrCommentBody(opts) {
|
|
const { owner, repo, prNumber, status, commitSha, updatedAt, ppBaseUrl, lastLogLines, instanceIp, port } = opts;
|
|
const ts = updatedAt.toISOString().replace("T", " ").slice(0, 19) + " UTC";
|
|
let statusLine = status;
|
|
if (lastLogLines) {
|
|
statusLine += `
|
|
|
|
\`\`\`
|
|
${lastLogLines}
|
|
\`\`\``;
|
|
}
|
|
return `## \u{1F680} PR Preview \u2014 \`${owner}/${repo}\` #${prNumber}
|
|
|
|
**Status:** ${statusLine}
|
|
**Commit:** \`${commitSha.slice(0, 8)}\`
|
|
**Updated:** ${ts}
|
|
|
|
---
|
|
_Powered by [PR Previews](${ppBaseUrl})_`;
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
buildPrCommentBody,
|
|
checkUserPermission,
|
|
deleteWebhook,
|
|
fetchUserRepos,
|
|
getRepoCollaboratorPermission,
|
|
giteaApi,
|
|
postComment,
|
|
registerWebhook,
|
|
updateComment,
|
|
updateWebhookSecret,
|
|
validateGiteaUrl
|
|
});
|
|
//# sourceMappingURL=gitea.js.map
|