Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / node suites (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
apps/gitea -> apps/rithub-server; compose services/containers renamed (rithub-server-app/postgres/act-runner) with explicit project name and volume names pinned to the exact existing Docker volumes (no data loss); our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs -> ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter + giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram (tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go internal/giteaclient -> internal/ritclient in rithub-async-import (go build/test clean); new /auth/rit + /forges/rit/connect routes with /gitea back-compat aliases; locale/swagger/footer/captcha template text scrubbed of remaining "Gitea" strings. Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea renamed to /srv/rithub-server with a symlink kept, docker compose up -d from the new path, act_runner network-alias fix for its persisted instance URL. Live-verified: docker compose config diff showed zero unintended value changes, DB row counts unchanged (19 users, 635 repos), full route regression 200/expected, 0 "gitea" in headers/bodies on every checked page, real git clone+push over HTTPS and SSH with a disposable account (deleted after). Deferred on purpose (documented in plans/railyard.md): the forge discriminator / DB column names / Postgres role+volume names (data migrations, not a naming change) and the upstream GITEA__ env-to-ini keys and X-Gitea-* wire headers (hardcoded in the vendored engine binary). See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and live evidence. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
205 lines
7.5 KiB
JavaScript
205 lines
7.5 KiB
JavaScript
#!/usr/bin/env node
|
|
// Real-user "import your first repo" onboarding mail for Rithub.
|
|
//
|
|
// Finds real Rithub users (excludes the owner account and every QA/test
|
|
// account — mail.tm-style addresses and the "rithubqa*"/"rj1118*"/"rithub*test*"
|
|
// naming pattern used by this repo's own QA sessions) who have 0 repos, and
|
|
// sends each one a single, honest, one-time nudge email: "you signed up,
|
|
// here's the 2-minute way to bring your first repo over." Idempotent via a
|
|
// persisted sent-log (one line per user, append-only) — running this script
|
|
// again never re-sends to someone already recorded there. Every mail carries
|
|
// a real List-Unsubscribe mailto header; nothing is sent to a QA account.
|
|
//
|
|
// Run from anywhere with SSH access to railyard-box (for the real user/repo
|
|
// list via the engine's own public+admin API) and to box1 (to send mail through
|
|
// the already-authenticated arhan@scribase.com SMTP mailbox — same
|
|
// nodemailer wrapper the outbound engine itself uses, lib/smtp.mjs).
|
|
//
|
|
// Usage:
|
|
// node first-repo-onboarding-mail.mjs --dry-run # default; prints what would send
|
|
// node first-repo-onboarding-mail.mjs --live # actually sends (respects the cap check below)
|
|
// node first-repo-onboarding-mail.mjs --live --force # send even if the cap looks exhausted (do not use lightly)
|
|
|
|
import { execFileSync } from 'node:child_process';
|
|
|
|
const RAILYARD_SSH_HOST = 'railyard-box';
|
|
const BOX1_SSH_HOST = 'box';
|
|
const SENT_LOG_PATH = '/srv/outbound/data/rithub-onboarding-sent.jsonl';
|
|
const MAILBOX = {
|
|
email: 'arhan@scribase.com',
|
|
fromName: 'Rithub (by the Scribase team)',
|
|
replyTo: 'arhan@scribase.com',
|
|
smtp: { hostEnv: 'SMTP_HOST', portEnv: 'SMTP_PORT', userEnv: 'SMTP_USER', passEnv: 'SMTP_PASS' },
|
|
};
|
|
|
|
const args = new Set(process.argv.slice(2));
|
|
const LIVE = args.has('--live');
|
|
const FORCE = args.has('--force');
|
|
|
|
function ssh(host, cmd) {
|
|
return execFileSync('ssh', [host, cmd], { encoding: 'utf8', maxBuffer: 20_000_000 });
|
|
}
|
|
|
|
/** Real users only — never the owner account, never a QA/test account. */
|
|
function isRealUser(user) {
|
|
if (user.username === 'caelum0x') return false;
|
|
const email = (user.email || '').toLowerCase();
|
|
const username = user.username.toLowerCase();
|
|
const qaEmailHosts = ['euploading.com', 'mail.tm']; // mail.tm disposable domains used by QA
|
|
if (qaEmailHosts.some((h) => email.endsWith('@' + h) || email.includes('.' + h))) return false;
|
|
if (/^rithub(qa|journey|cta|ctaqa)/.test(username)) return false;
|
|
if (/^rj\d+$/.test(username)) return false;
|
|
return true;
|
|
}
|
|
|
|
function getRitUsers() {
|
|
const raw = ssh(RAILYARD_SSH_HOST, 'docker exec -u git rithub-server-app gitea admin user list');
|
|
const lines = raw.trim().split('\n').slice(1); // drop header row
|
|
return lines
|
|
.map((line) => {
|
|
const cols = line.trim().split(/\s+/);
|
|
return { id: cols[0], username: cols[1], email: cols[2] };
|
|
})
|
|
.filter((u) => u.username);
|
|
}
|
|
|
|
function getRepoCount(username) {
|
|
const raw = ssh(
|
|
RAILYARD_SSH_HOST,
|
|
`curl -s "https://rithub.dev/api/v1/users/${username}/repos"`
|
|
);
|
|
try {
|
|
const repos = JSON.parse(raw);
|
|
return Array.isArray(repos) ? repos.length : 0;
|
|
} catch {
|
|
return -1; // unknown — skip rather than guess
|
|
}
|
|
}
|
|
|
|
function getSentLog() {
|
|
const raw = ssh(BOX1_SSH_HOST, `sudo touch ${SENT_LOG_PATH} && sudo cat ${SENT_LOG_PATH}`);
|
|
const sent = new Set();
|
|
for (const line of raw.trim().split('\n')) {
|
|
if (!line.trim()) continue;
|
|
try {
|
|
const rec = JSON.parse(line);
|
|
if (rec.username) sent.add(rec.username);
|
|
} catch {
|
|
/* ignore malformed lines */
|
|
}
|
|
}
|
|
return sent;
|
|
}
|
|
|
|
function appendSentLog(record) {
|
|
const json = JSON.stringify(record).replace(/'/g, "'\\''");
|
|
ssh(BOX1_SSH_HOST, `echo '${json}' | sudo tee -a ${SENT_LOG_PATH} >/dev/null`);
|
|
}
|
|
|
|
function checkCap() {
|
|
const raw = ssh(BOX1_SSH_HOST, 'cd /srv/outbound/app/engine && sudo outbound dns-check');
|
|
const m = raw.match(new RegExp(`${MAILBOX.email.replace('.', '\\.')}\\s+\\S+\\n[\\s\\S]*?remaining (-?\\d+)`));
|
|
if (!m) return { ok: false, remaining: null, raw };
|
|
const remaining = Number(m[1]);
|
|
return { ok: remaining > 0, remaining, raw };
|
|
}
|
|
|
|
function buildMail(user) {
|
|
const subject = "Welcome to Rithub — bring your first repo over (2 minutes)";
|
|
const text = `Hi ${user.username},
|
|
|
|
You signed up for Rithub but haven't brought a repo over yet. The fastest way:
|
|
|
|
1. Sign in at https://rithub.dev/user/login
|
|
2. Click "Import from GitHub" (or go straight to https://rithub.dev/repo/migrate?service_type=2)
|
|
3. Paste any repo URL — it clones with full history, issues, and pull requests in one step.
|
|
|
|
That's it — no CLI needed for the import itself.
|
|
|
|
If you'd rather not hear from Rithub again, just reply to this email and we won't send anything further.
|
|
|
|
— Arhan, Rithub (built by the team behind Scribase)
|
|
`;
|
|
const headers = {
|
|
'List-Unsubscribe': `<mailto:${MAILBOX.replyTo}?subject=unsubscribe>`,
|
|
'List-Unsubscribe-Post': 'List-Unsubscribe=One-Click',
|
|
};
|
|
return { subject, text, headers };
|
|
}
|
|
|
|
async function sendLive(user, mail) {
|
|
// Runs the actual send on box1 so the SMTP password never has to leave
|
|
// that host or be printed anywhere — inline node -e, same smtp.mjs the
|
|
// outbound engine itself uses, loading creds from the engine's own env file.
|
|
const script = `
|
|
require('dotenv').config({ path: '/etc/products/outbound.env' });
|
|
(async () => {
|
|
const { smtpConfigFor, sendMail, newMessageId } = await import('/srv/outbound/app/engine/lib/smtp.mjs');
|
|
const mailbox = ${JSON.stringify(MAILBOX)};
|
|
const smtp = smtpConfigFor(mailbox, process.env);
|
|
await sendMail({
|
|
smtp,
|
|
mailbox,
|
|
to: ${JSON.stringify(user.email)},
|
|
subject: ${JSON.stringify(mail.subject)},
|
|
text: ${JSON.stringify(mail.text)},
|
|
headers: ${JSON.stringify(mail.headers)},
|
|
messageId: newMessageId('scribase.com'),
|
|
});
|
|
console.log('SENT');
|
|
})().catch((e) => { console.error('SEND_FAILED', e.message); process.exit(1); });
|
|
`;
|
|
const out = ssh(
|
|
BOX1_SSH_HOST,
|
|
`cd /srv/outbound/app/engine && sudo -u deploy node -e ${JSON.stringify(script)}`
|
|
);
|
|
return out.includes('SENT');
|
|
}
|
|
|
|
async function main() {
|
|
const users = getRitUsers().filter(isRealUser);
|
|
const alreadySent = getSentLog();
|
|
const candidates = [];
|
|
|
|
for (const user of users) {
|
|
if (alreadySent.has(user.username)) continue;
|
|
const repoCount = getRepoCount(user.username);
|
|
if (repoCount === 0) candidates.push(user);
|
|
}
|
|
|
|
console.log(`Real users: ${users.length}. Already-sent: ${alreadySent.size}. 0-repo candidates this run: ${candidates.length}`);
|
|
for (const c of candidates) console.log(` - ${c.username} <${c.email}>`);
|
|
|
|
if (candidates.length === 0) {
|
|
console.log('Nothing to send.');
|
|
return;
|
|
}
|
|
|
|
if (!LIVE) {
|
|
console.log('\n[dry-run] Would send the above. Re-run with --live to actually send.');
|
|
return;
|
|
}
|
|
|
|
const cap = checkCap();
|
|
if (!cap.ok && !FORCE) {
|
|
console.log(`\nHELD: ${MAILBOX.email}'s daily send cap looks exhausted (remaining=${cap.remaining}). Not sending live — re-run tomorrow, or pass --force to override (not recommended).`);
|
|
return;
|
|
}
|
|
|
|
for (const user of candidates) {
|
|
const mail = buildMail(user);
|
|
const ok = await sendLive(user, mail);
|
|
if (ok) {
|
|
appendSentLog({ username: user.username, email: user.email, sentAt: new Date().toISOString() });
|
|
console.log(`SENT -> ${user.username}`);
|
|
} else {
|
|
console.log(`FAILED -> ${user.username}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|