gitpadi 2.0.7 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitlab/duo/chat-rules.md +40 -0
- package/.gitlab/duo/mr-review-instructions.md +44 -0
- package/.gitlab-ci.yml +136 -0
- package/README.md +585 -57
- package/action.yml +21 -2
- package/dist/applicant-scorer.js +27 -105
- package/dist/cli.js +1045 -34
- package/dist/commands/apply-for-issue.js +396 -0
- package/dist/commands/bounty-hunter.js +441 -0
- package/dist/commands/contribute.js +245 -51
- package/dist/commands/drips.js +351 -0
- package/dist/commands/gitlab-issues.js +87 -0
- package/dist/commands/gitlab-mrs.js +163 -0
- package/dist/commands/gitlab-pipelines.js +95 -0
- package/dist/commands/prs.js +3 -3
- package/dist/core/github.js +24 -0
- package/dist/core/gitlab.js +233 -0
- package/dist/gitlab-agents/ci-recovery-agent.js +173 -0
- package/dist/gitlab-agents/contributor-scoring-agent.js +159 -0
- package/dist/gitlab-agents/grade-assignment-agent.js +252 -0
- package/dist/gitlab-agents/mr-review-agent.js +200 -0
- package/dist/gitlab-agents/reminder-agent.js +164 -0
- package/dist/grade-assignment.js +262 -0
- package/dist/remind-contributors.js +127 -0
- package/dist/review-and-merge.js +125 -0
- package/examples/gitpadi.yml +152 -0
- package/package.json +20 -4
- package/src/applicant-scorer.ts +33 -141
- package/src/cli.ts +1078 -34
- package/src/commands/apply-for-issue.ts +452 -0
- package/src/commands/bounty-hunter.ts +529 -0
- package/src/commands/contribute.ts +264 -50
- package/src/commands/drips.ts +408 -0
- package/src/commands/gitlab-issues.ts +87 -0
- package/src/commands/gitlab-mrs.ts +185 -0
- package/src/commands/gitlab-pipelines.ts +104 -0
- package/src/commands/prs.ts +3 -3
- package/src/core/github.ts +24 -0
- package/src/core/gitlab.ts +397 -0
- package/src/gitlab-agents/ci-recovery-agent.ts +201 -0
- package/src/gitlab-agents/contributor-scoring-agent.ts +196 -0
- package/src/gitlab-agents/grade-assignment-agent.ts +275 -0
- package/src/gitlab-agents/mr-review-agent.ts +231 -0
- package/src/gitlab-agents/reminder-agent.ts +203 -0
- package/src/grade-assignment.ts +283 -0
- package/src/remind-contributors.ts +159 -0
- package/src/review-and-merge.ts +143 -0
package/dist/cli.js
CHANGED
|
@@ -8,19 +8,27 @@ import chalk from 'chalk';
|
|
|
8
8
|
import inquirer from 'inquirer';
|
|
9
9
|
import gradient from 'gradient-string';
|
|
10
10
|
import figlet from 'figlet';
|
|
11
|
-
import {
|
|
11
|
+
import { execFileSync } from 'child_process';
|
|
12
12
|
import boxen from 'boxen';
|
|
13
13
|
import { createSpinner } from 'nanospinner';
|
|
14
14
|
import { Octokit } from '@octokit/rest';
|
|
15
15
|
import { initGitHub, setRepo, getOwner, getRepo, getOctokit, saveConfig, getToken, getAuthenticatedUser, getRepoPermissions } from './core/github.js';
|
|
16
|
+
import { initGitLab, getGitLabToken, getNamespace, getProject, saveGitLabConfig, savePlatformPreference, loadPlatformPreference, getAuthenticatedGitLabUser, getGitLabProject, setGitLabProject, } from './core/gitlab.js';
|
|
16
17
|
import * as issues from './commands/issues.js';
|
|
17
18
|
import * as prs from './commands/prs.js';
|
|
18
19
|
import * as repos from './commands/repos.js';
|
|
19
20
|
import * as contributors from './commands/contributors.js';
|
|
20
21
|
import * as releases from './commands/releases.js';
|
|
21
22
|
import * as contribute from './commands/contribute.js';
|
|
22
|
-
|
|
23
|
+
import * as applyForIssue from './commands/apply-for-issue.js';
|
|
24
|
+
import { runBountyHunter } from './commands/bounty-hunter.js';
|
|
25
|
+
import { dripsMenu } from './commands/drips.js';
|
|
26
|
+
import * as gitlabIssues from './commands/gitlab-issues.js';
|
|
27
|
+
import * as gitlabMRs from './commands/gitlab-mrs.js';
|
|
28
|
+
import * as gitlabPipelines from './commands/gitlab-pipelines.js';
|
|
29
|
+
const VERSION = '2.1.2';
|
|
23
30
|
let targetConfirmed = false;
|
|
31
|
+
let gitlabProjectConfirmed = false;
|
|
24
32
|
// ── Styling ────────────────────────────────────────────────────────────
|
|
25
33
|
const cyber = gradient(['#ff00ff', '#00ffff', '#ff00ff']);
|
|
26
34
|
const neon = gradient(['#00ff87', '#60efff']);
|
|
@@ -99,7 +107,7 @@ async function bootSequence() {
|
|
|
99
107
|
const bootSteps = [
|
|
100
108
|
'▸ Initializing GitPadi engine',
|
|
101
109
|
'▸ Loading command modules',
|
|
102
|
-
'▸
|
|
110
|
+
'▸ Connecting to GitHub & GitLab',
|
|
103
111
|
'▸ Systems online',
|
|
104
112
|
];
|
|
105
113
|
for (const step of bootSteps) {
|
|
@@ -130,6 +138,18 @@ async function ensureAuthenticated() {
|
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
console.log(neon(' ⚡ Authentication — let\'s connect you to GitHub.\n'));
|
|
141
|
+
console.log(dim(' ┌─ How to get your GitHub Token ──────────────────────────────┐'));
|
|
142
|
+
console.log(dim(' │'));
|
|
143
|
+
console.log(dim(' │ 1. Open: ') + cyan('https://github.com/settings/tokens'));
|
|
144
|
+
console.log(dim(' │ 2. Click ') + bold('"Generate new token (classic)"'));
|
|
145
|
+
console.log(dim(' │ 3. Give it a name (e.g. "gitpadi")'));
|
|
146
|
+
console.log(dim(' │ 4. Select scopes: ') + yellow('repo') + dim(' (and ') + yellow('read:org') + dim(' for org repos)'));
|
|
147
|
+
console.log(dim(' │ 5. Click "Generate token" and copy it'));
|
|
148
|
+
console.log(dim(' │'));
|
|
149
|
+
console.log(dim(' │ The token will look like: ') + dim('ghp_xxxxxxxxxxxxxxxxxxxx'));
|
|
150
|
+
console.log(dim(' │'));
|
|
151
|
+
console.log(dim(' └─────────────────────────────────────────────────────────────┘'));
|
|
152
|
+
console.log('');
|
|
133
153
|
const { t } = await inquirer.prompt([{
|
|
134
154
|
type: 'password',
|
|
135
155
|
name: 't',
|
|
@@ -255,34 +275,662 @@ async function ensureTargetRepo(force = false) {
|
|
|
255
275
|
}
|
|
256
276
|
console.log(green(`\n ✅ Locked in → ${cyan(`${targetOwner}/${repo}`)}\n`));
|
|
257
277
|
}
|
|
278
|
+
// ── GitLab Authentication ───────────────────────────────────────────────
|
|
279
|
+
async function ensureGitLabAuthenticated() {
|
|
280
|
+
initGitLab();
|
|
281
|
+
let token = getGitLabToken();
|
|
282
|
+
if (token) {
|
|
283
|
+
try {
|
|
284
|
+
await getAuthenticatedGitLabUser();
|
|
285
|
+
return; // token valid
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
console.log(red(' ❌ Saved GitLab session invalid. Re-authenticating...'));
|
|
289
|
+
token = '';
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
console.log(neon('\n ⚡ GitLab Authentication — connect your account.\n'));
|
|
293
|
+
console.log(dim(' ┌─ How to get your GitLab Personal Access Token ──────────────┐'));
|
|
294
|
+
console.log(dim(' │'));
|
|
295
|
+
console.log(dim(' │ 1. Open: ') + cyan('https://gitlab.com/-/user_settings/personal_access_tokens'));
|
|
296
|
+
console.log(dim(' │ 2. Click ') + bold('"Add new token"'));
|
|
297
|
+
console.log(dim(' │ 3. Give it a name (e.g. "gitpadi") and set an expiry date'));
|
|
298
|
+
console.log(dim(' │ 4. Select scopes: ') + yellow('api') + dim(' (covers read/write access)'));
|
|
299
|
+
console.log(dim(' │ 5. Click "Create personal access token" and copy it'));
|
|
300
|
+
console.log(dim(' │'));
|
|
301
|
+
console.log(dim(' │ The token will look like: ') + dim('glpat-xxxxxxxxxxxxxxxxxxxx'));
|
|
302
|
+
console.log(dim(' │ For self-hosted GitLab, use your own host in the next step.'));
|
|
303
|
+
console.log(dim(' │'));
|
|
304
|
+
console.log(dim(' └─────────────────────────────────────────────────────────────┘'));
|
|
305
|
+
console.log('');
|
|
306
|
+
const { host } = await inquirer.prompt([{
|
|
307
|
+
type: 'input',
|
|
308
|
+
name: 'host',
|
|
309
|
+
message: cyan('🌐 GitLab host:'),
|
|
310
|
+
default: 'https://gitlab.com',
|
|
311
|
+
}]);
|
|
312
|
+
const { t } = await inquirer.prompt([{
|
|
313
|
+
type: 'password',
|
|
314
|
+
name: 't',
|
|
315
|
+
message: magenta('🔑 GitLab Personal Access Token') + dim(' (glpat-xxx):'),
|
|
316
|
+
mask: '•',
|
|
317
|
+
validate: async (v) => {
|
|
318
|
+
if (!v.startsWith('glpat-') && !v.startsWith('gl-')) {
|
|
319
|
+
return 'Token should start with glpat-';
|
|
320
|
+
}
|
|
321
|
+
const spinner = createSpinner(dim('Validating token...')).start();
|
|
322
|
+
try {
|
|
323
|
+
// Temp init to validate
|
|
324
|
+
const tmpRes = await fetch(`${host.replace(/\/$/, '')}/api/v4/user`, {
|
|
325
|
+
headers: { 'PRIVATE-TOKEN': v },
|
|
326
|
+
});
|
|
327
|
+
if (!tmpRes.ok)
|
|
328
|
+
throw new Error('Invalid');
|
|
329
|
+
spinner.success({ text: green('Token valid!') });
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
spinner.error({ text: red('Invalid token — GitLab rejected it.') });
|
|
334
|
+
return 'Invalid token';
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
}]);
|
|
338
|
+
saveGitLabConfig(t, host, '', '');
|
|
339
|
+
initGitLab(t, '', '', host);
|
|
340
|
+
const user = await getAuthenticatedGitLabUser();
|
|
341
|
+
console.log(green(`\n ✅ Authenticated as @${user.username}\n`));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Prompts user to select a GitLab project (namespace/project)
|
|
345
|
+
*/
|
|
346
|
+
async function ensureGitLabProject(force = false) {
|
|
347
|
+
let ns = getNamespace();
|
|
348
|
+
let proj = getProject();
|
|
349
|
+
if (!force && ns && proj) {
|
|
350
|
+
if (gitlabProjectConfirmed)
|
|
351
|
+
return;
|
|
352
|
+
const { confirm } = await inquirer.prompt([{
|
|
353
|
+
type: 'confirm',
|
|
354
|
+
name: 'confirm',
|
|
355
|
+
message: cyan('🎯 Targeting ') + bold(`${ns}/${proj}`) + cyan('. Correct?'),
|
|
356
|
+
default: true,
|
|
357
|
+
}]);
|
|
358
|
+
if (confirm) {
|
|
359
|
+
gitlabProjectConfirmed = true;
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
console.log(neon('\n 📦 GitLab Project — which project are we working on?\n'));
|
|
364
|
+
const user = await getAuthenticatedGitLabUser();
|
|
365
|
+
const { targetNs } = await inquirer.prompt([{
|
|
366
|
+
type: 'input',
|
|
367
|
+
name: 'targetNs',
|
|
368
|
+
message: cyan('👤 Namespace (user or group):'),
|
|
369
|
+
default: ns || user.username,
|
|
370
|
+
validate: (v) => v.length > 0 || 'Required',
|
|
371
|
+
}]);
|
|
372
|
+
const { targetProj } = await inquirer.prompt([{
|
|
373
|
+
type: 'input',
|
|
374
|
+
name: 'targetProj',
|
|
375
|
+
message: cyan('📦 Project path:'),
|
|
376
|
+
default: proj || '',
|
|
377
|
+
validate: (v) => v.length > 0 || 'Required',
|
|
378
|
+
}]);
|
|
379
|
+
// Verify project exists
|
|
380
|
+
const spin = createSpinner(dim(`Verifying ${targetNs}/${targetProj}...`)).start();
|
|
381
|
+
try {
|
|
382
|
+
const project = await getGitLabProject(targetNs, targetProj);
|
|
383
|
+
spin.success({ text: green(`Found: ${project.path_with_namespace}`) });
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
spin.warn({ text: yellow('Could not verify project — proceeding anyway.') });
|
|
387
|
+
}
|
|
388
|
+
setGitLabProject(targetNs, targetProj);
|
|
389
|
+
gitlabProjectConfirmed = true;
|
|
390
|
+
console.log(green(`\n ✅ Locked in → ${cyan(`${targetNs}/${targetProj}`)}\n`));
|
|
391
|
+
}
|
|
392
|
+
// ── GitLab Maintainer Menu ─────────────────────────────────────────────
|
|
393
|
+
async function gitlabMaintainerMenu() {
|
|
394
|
+
while (true) {
|
|
395
|
+
line('═');
|
|
396
|
+
console.log(gradient(['#FC6D26', '#E24329'])(' 🦊 GITPADI GITLAB MAINTAINER'));
|
|
397
|
+
console.log(dim(' Manage issues, merge requests, and pipelines'));
|
|
398
|
+
line('═');
|
|
399
|
+
console.log('');
|
|
400
|
+
const { category } = await inquirer.prompt([{
|
|
401
|
+
type: 'list',
|
|
402
|
+
name: 'category',
|
|
403
|
+
message: bold('Select operation:'),
|
|
404
|
+
choices: [
|
|
405
|
+
{ name: `${magenta('📋')} ${bold('Issues')} ${dim('— create, close, comment')}`, value: 'issues' },
|
|
406
|
+
{ name: `${cyan('🔀')} ${bold('Merge Requests')} ${dim('— list, merge, review, diff')}`, value: 'mrs' },
|
|
407
|
+
{ name: `${yellow('🔧')} ${bold('Pipelines')} ${dim('— list, view jobs, read logs')}`, value: 'pipelines' },
|
|
408
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
409
|
+
{ name: `${dim('⚙️')} ${dim('Switch Project')}`, value: 'switch' },
|
|
410
|
+
{ name: `${dim('⬅')} ${dim('Back to Mode Selector')}`, value: 'back' },
|
|
411
|
+
],
|
|
412
|
+
loop: false,
|
|
413
|
+
}]);
|
|
414
|
+
if (category === 'back')
|
|
415
|
+
break;
|
|
416
|
+
if (category === 'switch') {
|
|
417
|
+
await ensureGitLabProject(true);
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (category === 'issues')
|
|
421
|
+
await safeMenu(gitlabIssueMenu);
|
|
422
|
+
else if (category === 'mrs')
|
|
423
|
+
await safeMenu(gitlabMRMenu);
|
|
424
|
+
else if (category === 'pipelines')
|
|
425
|
+
await safeMenu(gitlabPipelineMenu);
|
|
426
|
+
console.log('');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
async function gitlabIssueMenu() {
|
|
430
|
+
const { action } = await inquirer.prompt([{
|
|
431
|
+
type: 'list', name: 'action', message: magenta('📋 Issue Operation:'),
|
|
432
|
+
choices: [
|
|
433
|
+
{ name: ` ${dim('⬅ Back')}`, value: 'back' },
|
|
434
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
435
|
+
{ name: ` ${green('▸')} List issues`, value: 'list' },
|
|
436
|
+
{ name: ` ${green('▸')} Create issue`, value: 'create' },
|
|
437
|
+
{ name: ` ${red('▸')} Close issue`, value: 'close' },
|
|
438
|
+
{ name: ` ${green('▸')} Reopen issue`, value: 'reopen' },
|
|
439
|
+
{ name: ` ${cyan('▸')} Comment on issue`, value: 'comment' },
|
|
440
|
+
],
|
|
441
|
+
}]);
|
|
442
|
+
if (action === 'back')
|
|
443
|
+
return;
|
|
444
|
+
if (action === 'list') {
|
|
445
|
+
const a = await ask([
|
|
446
|
+
{ type: 'list', name: 'state', message: 'State:', choices: ['opened', 'closed', 'all'], default: 'opened' },
|
|
447
|
+
{ type: 'input', name: 'limit', message: dim('Max results:'), default: '50' },
|
|
448
|
+
]);
|
|
449
|
+
await gitlabIssues.listIssues({ state: a.state, limit: parseInt(a.limit) });
|
|
450
|
+
}
|
|
451
|
+
else if (action === 'create') {
|
|
452
|
+
const a = await ask([
|
|
453
|
+
{ type: 'input', name: 'title', message: yellow('Issue title'), validate: (v) => v.length > 0 || 'Required' },
|
|
454
|
+
{ type: 'input', name: 'description', message: dim('Description (optional):'), default: '' },
|
|
455
|
+
{ type: 'input', name: 'labels', message: dim('Labels (comma-separated):'), default: '' },
|
|
456
|
+
]);
|
|
457
|
+
await gitlabIssues.createIssue({ title: a.title, description: a.description || undefined, labels: a.labels || undefined });
|
|
458
|
+
}
|
|
459
|
+
else if (action === 'close' || action === 'reopen') {
|
|
460
|
+
const { n } = await ask([{ type: 'input', name: 'n', message: yellow('Issue #') + dim(' (q=back):') }]);
|
|
461
|
+
if (!n || isNaN(Number(n)))
|
|
462
|
+
return;
|
|
463
|
+
if (action === 'close')
|
|
464
|
+
await gitlabIssues.closeIssue(parseInt(n));
|
|
465
|
+
else
|
|
466
|
+
await gitlabIssues.reopenIssue(parseInt(n));
|
|
467
|
+
}
|
|
468
|
+
else if (action === 'comment') {
|
|
469
|
+
const a = await ask([
|
|
470
|
+
{ type: 'input', name: 'n', message: yellow('Issue #') + dim(' (q=back):') },
|
|
471
|
+
{ type: 'input', name: 'body', message: cyan('Comment:') },
|
|
472
|
+
]);
|
|
473
|
+
if (!a.n || isNaN(Number(a.n)))
|
|
474
|
+
return;
|
|
475
|
+
await gitlabIssues.commentOnIssue(parseInt(a.n), a.body);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async function gitlabMRMenu() {
|
|
479
|
+
const { action } = await inquirer.prompt([{
|
|
480
|
+
type: 'list', name: 'action', message: cyan('🔀 Merge Request Operation:'),
|
|
481
|
+
choices: [
|
|
482
|
+
{ name: ` ${dim('⬅ Back')}`, value: 'back' },
|
|
483
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
484
|
+
{ name: ` ${green('▸')} List merge requests`, value: 'list' },
|
|
485
|
+
{ name: ` ${green('▸')} Merge MR ${dim('(checks pipeline first)')}`, value: 'merge' },
|
|
486
|
+
{ name: ` ${yellow('▸')} Force merge ${dim('(skip pipeline)')}`, value: 'force-merge' },
|
|
487
|
+
{ name: ` ${red('▸')} Close MR`, value: 'close' },
|
|
488
|
+
{ name: ` ${yellow('▸')} Review MR`, value: 'review' },
|
|
489
|
+
{ name: ` ${cyan('▸')} View diff`, value: 'diff' },
|
|
490
|
+
],
|
|
491
|
+
}]);
|
|
492
|
+
if (action === 'back')
|
|
493
|
+
return;
|
|
494
|
+
if (action === 'list') {
|
|
495
|
+
const a = await ask([
|
|
496
|
+
{ type: 'list', name: 'state', message: 'State:', choices: ['opened', 'closed', 'merged', 'all'], default: 'opened' },
|
|
497
|
+
{ type: 'input', name: 'limit', message: dim('Max results:'), default: '50' },
|
|
498
|
+
]);
|
|
499
|
+
await gitlabMRs.listMRs({ state: a.state, limit: parseInt(a.limit) });
|
|
500
|
+
}
|
|
501
|
+
else if (action === 'merge' || action === 'force-merge') {
|
|
502
|
+
const a = await ask([
|
|
503
|
+
{ type: 'input', name: 'n', message: yellow('MR !') + dim('(q=back):') },
|
|
504
|
+
{ type: 'confirm', name: 'squash', message: 'Squash commits?', default: true },
|
|
505
|
+
{ type: 'confirm', name: 'confirm', message: action === 'force-merge' ? yellow('⚠️ Force merge (skip pipeline)?') : red('⚠️ Merge this MR?'), default: false },
|
|
506
|
+
]);
|
|
507
|
+
if (a.confirm)
|
|
508
|
+
await gitlabMRs.mergeMR(parseInt(a.n), { squash: a.squash, force: action === 'force-merge' });
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
const { n } = await ask([{ type: 'input', name: 'n', message: yellow('MR !') + dim('(q=back):') }]);
|
|
512
|
+
if (!n || isNaN(Number(n)))
|
|
513
|
+
return;
|
|
514
|
+
if (action === 'close')
|
|
515
|
+
await gitlabMRs.closeMR(parseInt(n));
|
|
516
|
+
else if (action === 'review')
|
|
517
|
+
await gitlabMRs.reviewMR(parseInt(n));
|
|
518
|
+
else
|
|
519
|
+
await gitlabMRs.diffMR(parseInt(n));
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async function gitlabPipelineMenu() {
|
|
523
|
+
const { action } = await inquirer.prompt([{
|
|
524
|
+
type: 'list', name: 'action', message: yellow('🔧 Pipeline Operation:'),
|
|
525
|
+
choices: [
|
|
526
|
+
{ name: ` ${dim('⬅ Back')}`, value: 'back' },
|
|
527
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
528
|
+
{ name: ` ${green('▸')} List pipelines`, value: 'list' },
|
|
529
|
+
{ name: ` ${cyan('▸')} View pipeline jobs`, value: 'jobs' },
|
|
530
|
+
{ name: ` ${cyan('▸')} View job log`, value: 'log' },
|
|
531
|
+
],
|
|
532
|
+
}]);
|
|
533
|
+
if (action === 'back')
|
|
534
|
+
return;
|
|
535
|
+
if (action === 'list') {
|
|
536
|
+
const a = await ask([
|
|
537
|
+
{ type: 'input', name: 'ref', message: dim('Branch/ref (blank for all):'), default: '' },
|
|
538
|
+
{ type: 'input', name: 'limit', message: dim('Max results:'), default: '20' },
|
|
539
|
+
]);
|
|
540
|
+
await gitlabPipelines.listPipelines({ ref: a.ref || undefined, limit: parseInt(a.limit) });
|
|
541
|
+
}
|
|
542
|
+
else if (action === 'jobs') {
|
|
543
|
+
const { n } = await ask([{ type: 'input', name: 'n', message: yellow('Pipeline ID:') + dim(' (q=back):') }]);
|
|
544
|
+
if (!n || isNaN(Number(n)))
|
|
545
|
+
return;
|
|
546
|
+
await gitlabPipelines.viewPipelineJobs(parseInt(n));
|
|
547
|
+
}
|
|
548
|
+
else if (action === 'log') {
|
|
549
|
+
const { n } = await ask([{ type: 'input', name: 'n', message: yellow('Job ID:') + dim(' (q=back):') }]);
|
|
550
|
+
if (!n || isNaN(Number(n)))
|
|
551
|
+
return;
|
|
552
|
+
await gitlabPipelines.viewJobLog(parseInt(n));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
// ── Platform Selector ──────────────────────────────────────────────────
|
|
556
|
+
async function selectPlatform() {
|
|
557
|
+
const saved = loadPlatformPreference();
|
|
558
|
+
if (saved) {
|
|
559
|
+
const { keepPlatform } = await inquirer.prompt([{
|
|
560
|
+
type: 'confirm',
|
|
561
|
+
name: 'keepPlatform',
|
|
562
|
+
message: `${dim('Last session:')} ${saved === 'github' ? cyan('GitHub') : gradient(['#FC6D26', '#E24329'])('GitLab')} — continue with this?`,
|
|
563
|
+
default: true,
|
|
564
|
+
}]);
|
|
565
|
+
if (keepPlatform)
|
|
566
|
+
return saved;
|
|
567
|
+
}
|
|
568
|
+
const { platform } = await inquirer.prompt([{
|
|
569
|
+
type: 'list',
|
|
570
|
+
name: 'platform',
|
|
571
|
+
message: bold('Choose your platform:'),
|
|
572
|
+
choices: [
|
|
573
|
+
{ name: `${cyan('🐙')} ${bold('GitHub')} ${dim('— github.com')}`, value: 'github' },
|
|
574
|
+
{ name: `${gradient(['#FC6D26', '#E24329'])('🦊')} ${bold('GitLab')} ${dim('— gitlab.com or self-hosted')}`, value: 'gitlab' },
|
|
575
|
+
],
|
|
576
|
+
loop: false,
|
|
577
|
+
}]);
|
|
578
|
+
savePlatformPreference(platform);
|
|
579
|
+
return platform;
|
|
580
|
+
}
|
|
258
581
|
// ── Mode Selector ──────────────────────────────────────────────────────
|
|
259
582
|
async function mainMenu() {
|
|
583
|
+
const platform = await selectPlatform();
|
|
584
|
+
// Authenticate for selected platform
|
|
585
|
+
if (platform === 'gitlab') {
|
|
586
|
+
await ensureGitLabAuthenticated();
|
|
587
|
+
}
|
|
260
588
|
while (true) {
|
|
261
589
|
line('═');
|
|
262
|
-
|
|
590
|
+
const platformLabel = platform === 'github'
|
|
591
|
+
? cyan('GitHub')
|
|
592
|
+
: gradient(['#FC6D26', '#E24329'])('GitLab');
|
|
593
|
+
console.log(cyber(` ⟨ GITPADI MODE SELECTOR ⟩`) + dim(` [${platformLabel}]`));
|
|
263
594
|
console.log(dim(' Select your workflow persona to continue'));
|
|
264
595
|
line('═');
|
|
265
596
|
console.log('');
|
|
266
|
-
|
|
597
|
+
if (platform === 'github') {
|
|
598
|
+
const { mode } = await inquirer.prompt([{
|
|
599
|
+
type: 'list',
|
|
600
|
+
name: 'mode',
|
|
601
|
+
message: bold('Choose your path:'),
|
|
602
|
+
choices: [
|
|
603
|
+
{ name: `${cyan('✨')} ${bold('Contributor Mode')} ${dim('— fork, clone, sync, submit PRs')}`, value: 'contributor' },
|
|
604
|
+
{ name: `${magenta('🛠️')} ${bold('Maintainer Mode')} ${dim('— manage issues, PRs, contributors')}`, value: 'maintainer' },
|
|
605
|
+
{ name: `${yellow('🏫')} ${bold('Organization/School')} ${dim('— assignments, grading, leaderboard')}`, value: 'org' },
|
|
606
|
+
{ name: `${cyan('🌊')} ${bold('Drips Network')} ${dim('— apply for bounty issues on drips.network')}`, value: 'drips' },
|
|
607
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
608
|
+
{ name: `${dim('🔄')} ${dim('Switch Platform')}`, value: 'switch' },
|
|
609
|
+
{ name: `${dim('👋')} ${dim('Exit')}`, value: 'exit' },
|
|
610
|
+
],
|
|
611
|
+
loop: false,
|
|
612
|
+
}]);
|
|
613
|
+
if (mode === 'exit')
|
|
614
|
+
break;
|
|
615
|
+
if (mode === 'switch') {
|
|
616
|
+
savePlatformPreference('gitlab');
|
|
617
|
+
return mainMenu();
|
|
618
|
+
}
|
|
619
|
+
if (mode === 'contributor')
|
|
620
|
+
await safeMenu(contributorMenu);
|
|
621
|
+
else if (mode === 'maintainer') {
|
|
622
|
+
await ensureTargetRepo();
|
|
623
|
+
await safeMenu(maintainerMenu);
|
|
624
|
+
}
|
|
625
|
+
else if (mode === 'org') {
|
|
626
|
+
await ensureTargetRepo();
|
|
627
|
+
await safeMenu(orgMenu);
|
|
628
|
+
}
|
|
629
|
+
else if (mode === 'drips') {
|
|
630
|
+
await safeMenu(dripsMenu);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
// GitLab mode
|
|
635
|
+
const { mode } = await inquirer.prompt([{
|
|
636
|
+
type: 'list',
|
|
637
|
+
name: 'mode',
|
|
638
|
+
message: bold('Choose your path:'),
|
|
639
|
+
choices: [
|
|
640
|
+
{ name: `${gradient(['#FC6D26', '#E24329'])('🛠️')} ${bold('GitLab Maintainer')} ${dim('— issues, MRs, pipelines')}`, value: 'gl-maintainer' },
|
|
641
|
+
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
642
|
+
{ name: `${dim('🔄')} ${dim('Switch Platform')}`, value: 'switch' },
|
|
643
|
+
{ name: `${dim('👋')} ${dim('Exit')}`, value: 'exit' },
|
|
644
|
+
],
|
|
645
|
+
loop: false,
|
|
646
|
+
}]);
|
|
647
|
+
if (mode === 'exit')
|
|
648
|
+
break;
|
|
649
|
+
if (mode === 'switch') {
|
|
650
|
+
savePlatformPreference('github');
|
|
651
|
+
return mainMenu();
|
|
652
|
+
}
|
|
653
|
+
if (mode === 'gl-maintainer') {
|
|
654
|
+
await ensureGitLabProject();
|
|
655
|
+
await safeMenu(gitlabMaintainerMenu);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
// ── Organization / School Menu ─────────────────────────────────────────
|
|
661
|
+
async function orgMenu() {
|
|
662
|
+
while (true) {
|
|
663
|
+
line('═');
|
|
664
|
+
console.log(yellow(' 🏫 GITPADI ORGANIZATION / SCHOOL'));
|
|
665
|
+
console.log(dim(' Create assignments, grade PRs, track student performance'));
|
|
666
|
+
line('═');
|
|
667
|
+
console.log('');
|
|
668
|
+
const { action } = await inquirer.prompt([{
|
|
267
669
|
type: 'list',
|
|
268
|
-
name: '
|
|
269
|
-
message: bold('
|
|
670
|
+
name: 'action',
|
|
671
|
+
message: bold('Select operation:'),
|
|
270
672
|
choices: [
|
|
271
|
-
{ name: `${
|
|
272
|
-
{ name: `${
|
|
673
|
+
{ name: `${yellow('📝')} ${bold('Create Assignment')} ${dim('— post a new assignment as an issue')}`, value: 'create' },
|
|
674
|
+
{ name: `${green('📊')} ${bold('Grade a PR')} ${dim('— score a student submission')}`, value: 'grade' },
|
|
675
|
+
{ name: `${cyan('🏆')} ${bold('Cohort Leaderboard')} ${dim('— rank all students by score')}`, value: 'leaderboard' },
|
|
273
676
|
new inquirer.Separator(dim(' ─────────────────────────────')),
|
|
274
|
-
{ name: `${dim('
|
|
677
|
+
{ name: `${dim('⚙️')} ${dim('Switch Repo')}`, value: 'switch' },
|
|
678
|
+
{ name: `${dim('⬅')} ${dim('Back to Mode Selector')}`, value: 'back' },
|
|
275
679
|
],
|
|
276
680
|
loop: false,
|
|
277
681
|
}]);
|
|
278
|
-
if (
|
|
279
|
-
await safeMenu(contributorMenu);
|
|
280
|
-
else if (mode === 'maintainer') {
|
|
281
|
-
await ensureTargetRepo();
|
|
282
|
-
await safeMenu(maintainerMenu);
|
|
283
|
-
}
|
|
284
|
-
else
|
|
682
|
+
if (action === 'back')
|
|
285
683
|
break;
|
|
684
|
+
if (action === 'switch') {
|
|
685
|
+
await ensureTargetRepo(true);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
// ── Create Assignment ──────────────────────────────────────────
|
|
689
|
+
if (action === 'create') {
|
|
690
|
+
const answers = await ask([
|
|
691
|
+
{ type: 'input', name: 'title', message: yellow('Assignment title:') },
|
|
692
|
+
{ type: 'input', name: 'description', message: yellow('Description (what students should build):') },
|
|
693
|
+
{ type: 'input', name: 'deadline', message: yellow('Deadline (e.g. "March 15, 2026"):'), default: '' },
|
|
694
|
+
{ type: 'input', name: 'files', message: yellow('Expected files/folders (comma-separated):'), default: '' },
|
|
695
|
+
{ type: 'input', name: 'labels', message: yellow('Labels (space-separated):'), default: 'assignment' },
|
|
696
|
+
]);
|
|
697
|
+
if (!answers.title)
|
|
698
|
+
continue;
|
|
699
|
+
const ora = (await import('ora')).default;
|
|
700
|
+
const spinner = ora('Creating assignment...').start();
|
|
701
|
+
try {
|
|
702
|
+
const octokit = getOctokit();
|
|
703
|
+
const owner = getOwner();
|
|
704
|
+
const repo = getRepo();
|
|
705
|
+
let body = `## 📝 ${answers.title}\n\n`;
|
|
706
|
+
body += `${answers.description}\n\n`;
|
|
707
|
+
if (answers.deadline)
|
|
708
|
+
body += `**Deadline:** ${answers.deadline}\n\n`;
|
|
709
|
+
if (answers.files)
|
|
710
|
+
body += `**Expected files:** ${answers.files}\n\n`;
|
|
711
|
+
body += `---\n\n`;
|
|
712
|
+
body += `### Submission Instructions\n\n`;
|
|
713
|
+
body += `1. Fork this repository\n`;
|
|
714
|
+
body += `2. Create a branch named \`assignment-<issue-number>\` (e.g. \`assignment-5\`)\n`;
|
|
715
|
+
body += `3. Complete the assignment\n`;
|
|
716
|
+
body += `4. Open a Pull Request with \`Fixes #<issue-number>\` in the description\n`;
|
|
717
|
+
body += `5. GitPadi will automatically grade your submission\n\n`;
|
|
718
|
+
body += `### Grading Criteria\n\n`;
|
|
719
|
+
body += `| Criteria | Points |\n|----------|--------|\n`;
|
|
720
|
+
body += `| CI Passing | 25 |\n`;
|
|
721
|
+
body += `| Assignment Relevance | 25 |\n`;
|
|
722
|
+
body += `| Test Coverage | 20 |\n`;
|
|
723
|
+
body += `| Code Quality | 15 |\n`;
|
|
724
|
+
body += `| Submission Format | 15 |\n`;
|
|
725
|
+
body += `| **Total** | **100** |\n\n`;
|
|
726
|
+
body += `**Pass threshold:** 40/100 (Grade C or above)\n`;
|
|
727
|
+
const labels = answers.labels.split(/\s+/).filter((l) => l);
|
|
728
|
+
const { data: issue } = await octokit.issues.create({
|
|
729
|
+
owner, repo,
|
|
730
|
+
title: `📝 ${answers.title}`,
|
|
731
|
+
body,
|
|
732
|
+
labels,
|
|
733
|
+
});
|
|
734
|
+
spinner.succeed(green(`Assignment created: #${issue.number} — ${issue.html_url}`));
|
|
735
|
+
}
|
|
736
|
+
catch (e) {
|
|
737
|
+
spinner.fail(e.message);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
// ── Grade a PR ─────────────────────────────────────────────────
|
|
741
|
+
else if (action === 'grade') {
|
|
742
|
+
const { prNum } = await ask([{ type: 'input', name: 'prNum', message: cyan('PR number to grade:') }]);
|
|
743
|
+
if (!prNum || isNaN(Number(prNum)))
|
|
744
|
+
continue;
|
|
745
|
+
const ora = (await import('ora')).default;
|
|
746
|
+
const spinner = ora('Grading submission...').start();
|
|
747
|
+
try {
|
|
748
|
+
const octokit = getOctokit();
|
|
749
|
+
const owner = getOwner();
|
|
750
|
+
const repo = getRepo();
|
|
751
|
+
const prNumber = parseInt(prNum);
|
|
752
|
+
const { data: pr } = await octokit.pulls.get({ owner, repo, pull_number: prNumber });
|
|
753
|
+
const student = pr.user?.login || 'unknown';
|
|
754
|
+
const branchName = pr.head.ref;
|
|
755
|
+
const prBody = pr.body || '';
|
|
756
|
+
// Detect assignment
|
|
757
|
+
const bodyMatch = prBody.match(/(?:fixes|closes|resolves|assignment)\s*#(\d+)/i);
|
|
758
|
+
const branchMatch = branchName.match(/(?:assignment|hw|task|fix\/issue)-(\d+)/i);
|
|
759
|
+
const assignmentNum = bodyMatch ? parseInt(bodyMatch[1]) : branchMatch ? parseInt(branchMatch[1]) : null;
|
|
760
|
+
if (!assignmentNum) {
|
|
761
|
+
spinner.fail('No assignment issue linked. Student should use `Fixes #N` or branch `assignment-N`.');
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
// Fetch assignment
|
|
765
|
+
const { data: issue } = await octokit.issues.get({ owner, repo, issue_number: assignmentNum });
|
|
766
|
+
const { data: files } = await octokit.pulls.listFiles({ owner, repo, pull_number: prNumber });
|
|
767
|
+
const totalChanges = files.reduce((sum, f) => sum + f.additions + f.deletions, 0);
|
|
768
|
+
// CI
|
|
769
|
+
const sha = pr.head.sha;
|
|
770
|
+
const { data: ciChecks } = await octokit.checks.listForRef({ owner, repo, ref: sha });
|
|
771
|
+
const { data: statuses } = await octokit.repos.getCombinedStatusForRef({ owner, repo, ref: sha });
|
|
772
|
+
const ciPassed = statuses.state === 'success' || (ciChecks.total_count > 0 && ciChecks.check_runs.every((c) => c.conclusion === 'success'));
|
|
773
|
+
const ciFailed = statuses.state === 'failure' || ciChecks.check_runs.some((c) => c.conclusion === 'failure');
|
|
774
|
+
// Quick score
|
|
775
|
+
let score = 0;
|
|
776
|
+
if (ciPassed)
|
|
777
|
+
score += 25;
|
|
778
|
+
score += 15; // base relevance
|
|
779
|
+
const testFiles = files.filter((f) => f.filename.includes('test') || f.filename.includes('spec'));
|
|
780
|
+
if (testFiles.length > 0)
|
|
781
|
+
score += 20;
|
|
782
|
+
else
|
|
783
|
+
score += 5;
|
|
784
|
+
if (totalChanges < 500)
|
|
785
|
+
score += 15;
|
|
786
|
+
else
|
|
787
|
+
score += 5;
|
|
788
|
+
const hasRef = /(?:fixes|closes|resolves)\s+#\d+/i.test(prBody);
|
|
789
|
+
if (hasRef && prBody.length > 20)
|
|
790
|
+
score += 15;
|
|
791
|
+
else
|
|
792
|
+
score += 5;
|
|
793
|
+
const letter = score >= 80 ? 'A' : score >= 60 ? 'B' : score >= 40 ? 'C' : score >= 20 ? 'D' : 'F';
|
|
794
|
+
const emoji = score >= 80 ? '🟢' : score >= 60 ? '🔵' : score >= 40 ? '🟡' : score >= 20 ? '🟠' : '🔴';
|
|
795
|
+
const passed = score >= 40;
|
|
796
|
+
spinner.stop();
|
|
797
|
+
console.log(bold(`\n 📊 Grade for @${student} — PR #${prNumber}`));
|
|
798
|
+
console.log(` Assignment: ${issue.title} (#${assignmentNum})`);
|
|
799
|
+
console.log(` Changes: ${totalChanges} lines across ${files.length} files`);
|
|
800
|
+
console.log(` CI: ${ciPassed ? green('✅ Passed') : ciFailed ? red('❌ Failed') : yellow('⏳ Pending')}`);
|
|
801
|
+
console.log(` Tests: ${testFiles.length > 0 ? green(`${testFiles.length} file(s)`) : red('None')}`);
|
|
802
|
+
console.log(bold(`\n Score: ${score}/100 — Grade ${letter} ${emoji}\n`));
|
|
803
|
+
// Post grade
|
|
804
|
+
const gradeBody = `## ${emoji} GitPadi Grade — PR #${prNumber}\n\n**Student:** @${student}\n**Assignment:** ${issue.title} (#${assignmentNum})\n**Score:** ${score}/100\n**Grade:** ${letter}\n\n${passed ? '> ✅ **Passed.**' : '> ❌ **Did not pass.** Please fix and re-submit.'}\n\n---\n_Graded by [GitPadi](https://github.com/Netwalls/contributor-agent) 📝_\n\n<!-- gitpadi-grade -->`;
|
|
805
|
+
await octokit.issues.createComment({ owner, repo, issue_number: prNumber, body: gradeBody });
|
|
806
|
+
console.log(green(' ✅ Grade posted to PR.'));
|
|
807
|
+
if (passed && ciPassed) {
|
|
808
|
+
const { merge } = await inquirer.prompt([{
|
|
809
|
+
type: 'list', name: 'merge', message: green('Merge this PR?'),
|
|
810
|
+
choices: [
|
|
811
|
+
{ name: `${green('✅')} Yes, squash & merge`, value: 'yes' },
|
|
812
|
+
{ name: `${dim('⬅')} No`, value: 'no' },
|
|
813
|
+
]
|
|
814
|
+
}]);
|
|
815
|
+
if (merge === 'yes') {
|
|
816
|
+
const mergeSpinner = ora('Merging...').start();
|
|
817
|
+
await octokit.pulls.merge({
|
|
818
|
+
owner, repo, pull_number: prNumber,
|
|
819
|
+
merge_method: 'squash',
|
|
820
|
+
commit_title: `[Grade ${letter}] ${pr.title} (#${prNumber})`,
|
|
821
|
+
});
|
|
822
|
+
mergeSpinner.succeed(green(`PR #${prNumber} merged!`));
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
catch (e) {
|
|
827
|
+
spinner.fail(e.message);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
// ── Cohort Leaderboard ─────────────────────────────────────────
|
|
831
|
+
else if (action === 'leaderboard') {
|
|
832
|
+
const ora = (await import('ora')).default;
|
|
833
|
+
const Table = (await import('cli-table3')).default;
|
|
834
|
+
const spinner = ora('Building cohort leaderboard...').start();
|
|
835
|
+
try {
|
|
836
|
+
const octokit = getOctokit();
|
|
837
|
+
const owner = getOwner();
|
|
838
|
+
const repo = getRepo();
|
|
839
|
+
// Find all PRs with grade comments
|
|
840
|
+
const { data: allPRs } = await octokit.pulls.list({ owner, repo, state: 'all', per_page: 100 });
|
|
841
|
+
const studentScores = {};
|
|
842
|
+
for (const pr of allPRs) {
|
|
843
|
+
const { data: comments } = await octokit.issues.listComments({ owner, repo, issue_number: pr.number });
|
|
844
|
+
const gradeComment = comments.find(c => c.body?.includes('<!-- gitpadi-grade -->'));
|
|
845
|
+
if (gradeComment && gradeComment.body) {
|
|
846
|
+
const student = pr.user?.login || 'unknown';
|
|
847
|
+
const scoreMatch = gradeComment.body.match(/\*\*Score:\*\*\s*(\d+)/);
|
|
848
|
+
const gradeMatch = gradeComment.body.match(/\*\*Grade:\*\*\s*(\w)/);
|
|
849
|
+
if (scoreMatch) {
|
|
850
|
+
if (!studentScores[student])
|
|
851
|
+
studentScores[student] = { scores: [], grades: [], prs: [] };
|
|
852
|
+
studentScores[student].scores.push(parseInt(scoreMatch[1]));
|
|
853
|
+
studentScores[student].grades.push(gradeMatch ? gradeMatch[1] : '?');
|
|
854
|
+
studentScores[student].prs.push(pr.number);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
spinner.stop();
|
|
859
|
+
const students = Object.entries(studentScores)
|
|
860
|
+
.map(([name, data]) => ({
|
|
861
|
+
name,
|
|
862
|
+
avg: Math.round(data.scores.reduce((a, b) => a + b, 0) / data.scores.length),
|
|
863
|
+
total: data.scores.reduce((a, b) => a + b, 0),
|
|
864
|
+
assignments: data.scores.length,
|
|
865
|
+
grades: data.grades.join(', '),
|
|
866
|
+
}))
|
|
867
|
+
.sort((a, b) => b.avg - a.avg);
|
|
868
|
+
if (students.length === 0) {
|
|
869
|
+
console.log(yellow('\n No graded submissions found yet.\n'));
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
const table = new Table({
|
|
873
|
+
head: ['Rank', 'Student', 'Avg Score', 'Assignments', 'Grades', 'Total Points'].map(h => cyan(h)),
|
|
874
|
+
style: { head: [], border: [] },
|
|
875
|
+
});
|
|
876
|
+
students.forEach((s, i) => {
|
|
877
|
+
const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : `${i + 1}.`;
|
|
878
|
+
const avgColor = s.avg >= 80 ? green : s.avg >= 60 ? cyan : s.avg >= 40 ? yellow : red;
|
|
879
|
+
table.push([
|
|
880
|
+
medal,
|
|
881
|
+
bold(`@${s.name}`),
|
|
882
|
+
avgColor(`${s.avg}/100`),
|
|
883
|
+
`${s.assignments}`,
|
|
884
|
+
s.grades,
|
|
885
|
+
`${s.total}`,
|
|
886
|
+
]);
|
|
887
|
+
});
|
|
888
|
+
console.log(bold(`\n 🏆 COHORT LEADERBOARD — ${owner}/${repo}\n`));
|
|
889
|
+
console.log(table.toString());
|
|
890
|
+
console.log(green(`\n 👑 Top student: @${students[0].name} (${students[0].avg}/100 avg)\n`));
|
|
891
|
+
// Offer to post leaderboard as an issue comment
|
|
892
|
+
const { post } = await inquirer.prompt([{
|
|
893
|
+
type: 'list', name: 'post',
|
|
894
|
+
message: 'Post leaderboard to a pinned issue?',
|
|
895
|
+
choices: [
|
|
896
|
+
{ name: `${green('✅')} Yes`, value: 'yes' },
|
|
897
|
+
{ name: `${dim('⬅')} No`, value: 'no' },
|
|
898
|
+
]
|
|
899
|
+
}]);
|
|
900
|
+
if (post === 'yes') {
|
|
901
|
+
let leaderBody = `## 🏆 Cohort Leaderboard\n\n`;
|
|
902
|
+
leaderBody += `_Last updated: ${new Date().toLocaleDateString()}_\n\n`;
|
|
903
|
+
leaderBody += `| Rank | Student | Avg Score | Assignments | Grades |\n|------|---------|-----------|-------------|--------|\n`;
|
|
904
|
+
students.forEach((s, i) => {
|
|
905
|
+
const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : `${i + 1}`;
|
|
906
|
+
leaderBody += `| ${medal} | @${s.name} | ${s.avg}/100 | ${s.assignments} | ${s.grades} |\n`;
|
|
907
|
+
});
|
|
908
|
+
leaderBody += `\n👑 **Top student:** @${students[0].name}\n\n<!-- gitpadi-leaderboard -->`;
|
|
909
|
+
// Find or create leaderboard issue
|
|
910
|
+
const { data: issues } = await octokit.issues.listForRepo({ owner, repo, state: 'open', labels: 'leaderboard', per_page: 5 });
|
|
911
|
+
const existing = issues[0];
|
|
912
|
+
if (existing) {
|
|
913
|
+
await octokit.issues.update({ owner, repo, issue_number: existing.number, body: leaderBody });
|
|
914
|
+
console.log(green(` ✅ Leaderboard updated: ${existing.html_url}`));
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
const { data: newIssue } = await octokit.issues.create({
|
|
918
|
+
owner, repo, title: '🏆 Cohort Leaderboard', body: leaderBody, labels: ['leaderboard'],
|
|
919
|
+
});
|
|
920
|
+
// Pin it
|
|
921
|
+
try {
|
|
922
|
+
await octokit.issues.update({ owner, repo, issue_number: newIssue.number });
|
|
923
|
+
}
|
|
924
|
+
catch { }
|
|
925
|
+
console.log(green(` ✅ Leaderboard created: ${newIssue.html_url}`));
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
catch (e) {
|
|
930
|
+
spinner.fail(e.message);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
console.log('');
|
|
286
934
|
}
|
|
287
935
|
}
|
|
288
936
|
// ── Contributor Menu ───────────────────────────────────────────────────
|
|
@@ -292,27 +940,54 @@ async function contributorMenu() {
|
|
|
292
940
|
console.log(cyan(' ✨ GITPADI CONTRIBUTOR WORKSPACE'));
|
|
293
941
|
console.log(dim(' Automating forking, syncing, and PR delivery'));
|
|
294
942
|
line('═');
|
|
295
|
-
// Auto-check for updates if in a repo
|
|
296
|
-
if (getOwner() && getRepo()) {
|
|
297
|
-
await contribute.syncBranch();
|
|
298
|
-
}
|
|
299
943
|
const { action } = await inquirer.prompt([{
|
|
300
944
|
type: 'list',
|
|
301
945
|
name: 'action',
|
|
302
946
|
message: bold('Contributor Action:'),
|
|
303
947
|
choices: [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
{ name: `${
|
|
307
|
-
{ name: `${
|
|
308
|
-
|
|
948
|
+
// ── Bounty Discovery ──────────────────────────────────
|
|
949
|
+
new inquirer.Separator(dim(' ── Bounty Discovery ─────────────────────')),
|
|
950
|
+
{ name: `${green('🎯')} ${bold('Bounty Hunter')} ${dim('— auto-apply Drips Wave & GrantFox')}`, value: 'hunt' },
|
|
951
|
+
{ name: `${yellow('🙋')} ${bold('Apply for Issue')} ${dim('— browse a repo & request to work')}`, value: 'apply' },
|
|
952
|
+
{ name: `${cyan('🔍')} ${bold('My Applications')} ${dim('— see issues you applied for')}`, value: 'my-apps' },
|
|
953
|
+
// ── Contribution Flow ─────────────────────────────────
|
|
954
|
+
new inquirer.Separator(dim(' ── Contribution Flow ────────────────────')),
|
|
955
|
+
{ name: `${cyan('🚀')} ${bold('Start Contribution')} ${dim('— fork, clone & branch from URL')}`, value: 'start' },
|
|
956
|
+
{ name: `${green('🔄')} ${bold('Sync with Upstream')} ${dim('— pull latest from original repo')}`, value: 'sync' },
|
|
957
|
+
{ name: `${magenta('🚀')} ${bold('Submit PR')} ${dim('— stage, commit, push & open PR')}`, value: 'submit' },
|
|
958
|
+
{ name: `${red('🔧')} ${bold('Fix & Re-push')} ${dim('— fix CI failures & force-push')}`, value: 'fix' },
|
|
959
|
+
{ name: `${cyan('💬')} ${bold('Reply to Comments')} ${dim('— respond to reviewer feedback')}`, value: 'reply' },
|
|
960
|
+
// ── Visibility ────────────────────────────────────────
|
|
961
|
+
new inquirer.Separator(dim(' ── Visibility ───────────────────────────')),
|
|
962
|
+
{ name: `${yellow('📋')} ${bold('View Action Logs')} ${dim('— check CI status on latest commit')}`, value: 'logs' },
|
|
963
|
+
{ name: `${green('📝')} ${bold('My Open PRs')} ${dim('— list your open PRs in this repo')}`, value: 'my-prs' },
|
|
964
|
+
{ name: `${magenta('📊')} ${bold('My Score')} ${dim('— see your contributor tier & breakdown')}`, value: 'my-score' },
|
|
965
|
+
// ── Back ──────────────────────────────────────────────
|
|
966
|
+
new inquirer.Separator(dim(' ─────────────────────────────────────────')),
|
|
309
967
|
{ name: `${dim('⬅')} ${dim('Back to Mode Selector')}`, value: 'back' },
|
|
310
968
|
],
|
|
311
969
|
loop: false,
|
|
970
|
+
pageSize: 18,
|
|
312
971
|
}]);
|
|
313
972
|
if (action === 'back')
|
|
314
973
|
break;
|
|
315
|
-
if (action === '
|
|
974
|
+
if (action === 'hunt') {
|
|
975
|
+
await runBountyHunter({ platform: 'all', maxApplications: 3, dryRun: false });
|
|
976
|
+
}
|
|
977
|
+
else if (action === 'apply') {
|
|
978
|
+
await applyForIssue.browseAndApply();
|
|
979
|
+
}
|
|
980
|
+
else if (action === 'my-apps') {
|
|
981
|
+
await myApplicationsMenu();
|
|
982
|
+
}
|
|
983
|
+
else if (action === 'my-prs') {
|
|
984
|
+
await ensureTargetRepo();
|
|
985
|
+
await myOpenPRsMenu();
|
|
986
|
+
}
|
|
987
|
+
else if (action === 'my-score') {
|
|
988
|
+
await myScoreMenu();
|
|
989
|
+
}
|
|
990
|
+
else if (action === 'start') {
|
|
316
991
|
const { url } = await ask([{ type: 'input', name: 'url', message: 'Enter Repo or Issue URL:' }]);
|
|
317
992
|
await contribute.forkAndClone(url);
|
|
318
993
|
}
|
|
@@ -325,8 +1000,14 @@ async function contributorMenu() {
|
|
|
325
1000
|
else if (action === 'logs') {
|
|
326
1001
|
await contribute.viewLogs();
|
|
327
1002
|
}
|
|
1003
|
+
else if (action === 'fix') {
|
|
1004
|
+
await contribute.fixAndRepush();
|
|
1005
|
+
}
|
|
1006
|
+
else if (action === 'reply') {
|
|
1007
|
+
await contribute.replyToComments();
|
|
1008
|
+
}
|
|
328
1009
|
else if (action === 'submit') {
|
|
329
|
-
const branch =
|
|
1010
|
+
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { encoding: 'utf-8' }).trim();
|
|
330
1011
|
const match = branch.match(/issue-(\d+)/);
|
|
331
1012
|
const detectedIssue = match ? parseInt(match[1]) : undefined;
|
|
332
1013
|
let detectedTitle = '';
|
|
@@ -387,16 +1068,19 @@ async function maintainerMenu() {
|
|
|
387
1068
|
name: 'category',
|
|
388
1069
|
message: bold('Select operation:'),
|
|
389
1070
|
choices: [
|
|
390
|
-
{ name: `${magenta('📋')} ${bold('Issues')}
|
|
391
|
-
{ name: `${cyan('🔀')} ${bold('Pull Requests')}
|
|
392
|
-
{ name: `${green('
|
|
393
|
-
{ name: `${yellow('🏆')} ${bold('Contributors')}
|
|
394
|
-
{ name: `${
|
|
395
|
-
|
|
1071
|
+
{ name: `${magenta('📋')} ${bold('Issues')} ${dim('— create, close, assign, bulk-create')}`, value: 'issues' },
|
|
1072
|
+
{ name: `${cyan('🔀')} ${bold('Pull Requests')} ${dim('— list, merge, review, approve, diff')}`, value: 'prs' },
|
|
1073
|
+
{ name: `${green('✅')} ${bold('Review & Merge')} ${dim('— review a PR, check CI, squash merge')}`, value: 'review-merge' },
|
|
1074
|
+
{ name: `${yellow('🏆')} ${bold('Contributors')} ${dim('— score applicants, rank, auto-assign')}`, value: 'contributors' },
|
|
1075
|
+
{ name: `${green('📦')} ${bold('Repositories')} ${dim('— create, delete, clone, topics, info')}`, value: 'repos' },
|
|
1076
|
+
{ name: `${red('🚀')} ${bold('Releases')} ${dim('— create, list, tag releases')}`, value: 'releases' },
|
|
1077
|
+
{ name: `${green('🎯')} ${bold('Bounty Hunter')} ${dim('— auto-apply to Drips Wave & GrantFox')}`, value: 'hunt' },
|
|
1078
|
+
new inquirer.Separator(dim(' ─────────────────────────────────────────')),
|
|
396
1079
|
{ name: `${dim('⚙️')} ${dim('Switch Repo')}`, value: 'switch' },
|
|
397
1080
|
{ name: `${dim('⬅')} ${dim('Back to Mode Selector')}`, value: 'back' },
|
|
398
1081
|
],
|
|
399
1082
|
loop: false,
|
|
1083
|
+
pageSize: 12,
|
|
400
1084
|
}]);
|
|
401
1085
|
if (category === 'back')
|
|
402
1086
|
break;
|
|
@@ -414,9 +1098,316 @@ async function maintainerMenu() {
|
|
|
414
1098
|
await safeMenu(contributorScoringMenu);
|
|
415
1099
|
else if (category === 'releases')
|
|
416
1100
|
await safeMenu(releaseMenu);
|
|
1101
|
+
else if (category === 'hunt')
|
|
1102
|
+
await runBountyHunter({ platform: 'all', maxApplications: 3, dryRun: false });
|
|
1103
|
+
else if (category === 'review-merge') {
|
|
1104
|
+
await ensureTargetRepo();
|
|
1105
|
+
const { prNum } = await ask([{ type: 'input', name: 'prNum', message: cyan('PR number to review:') }]);
|
|
1106
|
+
if (!prNum || isNaN(Number(prNum)))
|
|
1107
|
+
continue;
|
|
1108
|
+
const ora = (await import('ora')).default;
|
|
1109
|
+
const spinner = ora('Reviewing PR...').start();
|
|
1110
|
+
try {
|
|
1111
|
+
const octokit = getOctokit();
|
|
1112
|
+
const owner = getOwner();
|
|
1113
|
+
const repo = getRepo();
|
|
1114
|
+
const prNumber = parseInt(prNum);
|
|
1115
|
+
const { data: pr } = await octokit.pulls.get({ owner, repo, pull_number: prNumber });
|
|
1116
|
+
const { data: files } = await octokit.pulls.listFiles({ owner, repo, pull_number: prNumber });
|
|
1117
|
+
const totalChanges = files.reduce((sum, f) => sum + f.additions + f.deletions, 0);
|
|
1118
|
+
// CI Check
|
|
1119
|
+
const sha = pr.head.sha;
|
|
1120
|
+
const { data: ciChecks } = await octokit.checks.listForRef({ owner, repo, ref: sha });
|
|
1121
|
+
const { data: statuses } = await octokit.repos.getCombinedStatusForRef({ owner, repo, ref: sha });
|
|
1122
|
+
const ciPassed = statuses.state === 'success' || (ciChecks.total_count > 0 && ciChecks.check_runs.every((c) => c.conclusion === 'success'));
|
|
1123
|
+
const ciFailed = statuses.state === 'failure' || ciChecks.check_runs.some((c) => c.conclusion === 'failure');
|
|
1124
|
+
spinner.stop();
|
|
1125
|
+
console.log(bold(`\n 📋 PR #${prNumber}: "${pr.title}"\n`));
|
|
1126
|
+
console.log(` ${dim('Author:')} @${pr.user?.login}`);
|
|
1127
|
+
console.log(` ${dim('Changes:')} ${totalChanges} lines across ${files.length} files`);
|
|
1128
|
+
console.log(` ${dim('CI:')} ${ciPassed ? green('✅ Passed') : ciFailed ? red('❌ Failed') : yellow('⏳ Pending')}\n`);
|
|
1129
|
+
if (ciFailed) {
|
|
1130
|
+
// Notify contributor
|
|
1131
|
+
const failMsg = `❌ **CI Failed.** Please fix the failing checks and re-push.\n\nUse \`npx gitpadi\` → \`Fix & Re-push\` for a guided workflow.\n\n---\n_Review by [GitPadi](https://github.com/Netwalls/contributor-agent) 🤖_`;
|
|
1132
|
+
await octokit.issues.createComment({ owner, repo, issue_number: prNumber, body: failMsg });
|
|
1133
|
+
console.log(red(' ❌ CI failed. Contributor notified.'));
|
|
1134
|
+
}
|
|
1135
|
+
else if (ciPassed) {
|
|
1136
|
+
const { mergeAction } = await inquirer.prompt([{
|
|
1137
|
+
type: 'list', name: 'mergeAction', message: green('CI passed! Merge this PR?'),
|
|
1138
|
+
choices: [
|
|
1139
|
+
{ name: `${green('✅')} Squash & Merge`, value: 'squash' },
|
|
1140
|
+
{ name: `${cyan('🔀')} Merge Commit`, value: 'merge' },
|
|
1141
|
+
{ name: `${dim('⬅')} Skip`, value: 'skip' },
|
|
1142
|
+
]
|
|
1143
|
+
}]);
|
|
1144
|
+
if (mergeAction !== 'skip') {
|
|
1145
|
+
const mergeSpinner = ora('Merging...').start();
|
|
1146
|
+
await octokit.pulls.merge({
|
|
1147
|
+
owner, repo, pull_number: prNumber,
|
|
1148
|
+
merge_method: mergeAction,
|
|
1149
|
+
commit_title: `${pr.title} (#${prNumber})`,
|
|
1150
|
+
});
|
|
1151
|
+
mergeSpinner.succeed(green(`PR #${prNumber} merged successfully! 🎉`));
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
else {
|
|
1155
|
+
console.log(yellow(' ⏳ CI is still running. Try again later.'));
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
catch (e) {
|
|
1159
|
+
spinner.fail(e.message);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
417
1162
|
console.log('');
|
|
418
1163
|
}
|
|
419
1164
|
}
|
|
1165
|
+
// ── CI Actions Menu ────────────────────────────────────────────────────
|
|
1166
|
+
// Triggers GitHub Actions workflow_dispatch events from the terminal.
|
|
1167
|
+
// This makes npx gitpadi the primary interface for all CI operations.
|
|
1168
|
+
async function ciActionsMenu() {
|
|
1169
|
+
const WORKFLOW_FILE = 'gitpadi.yml';
|
|
1170
|
+
const owner = getOwner();
|
|
1171
|
+
const repo = getRepo();
|
|
1172
|
+
const octokit = getOctokit();
|
|
1173
|
+
// Detect default branch
|
|
1174
|
+
let ref = 'main';
|
|
1175
|
+
try {
|
|
1176
|
+
const { data: repoData } = await octokit.repos.get({ owner, repo });
|
|
1177
|
+
ref = repoData.default_branch || 'main';
|
|
1178
|
+
}
|
|
1179
|
+
catch { /* use main */ }
|
|
1180
|
+
while (true) {
|
|
1181
|
+
line('─');
|
|
1182
|
+
console.log(green(` 🤖 CI ACTIONS — ${owner}/${repo}`));
|
|
1183
|
+
console.log(dim(` Triggers .github/workflows/${WORKFLOW_FILE} via GitHub Actions API`));
|
|
1184
|
+
line('─');
|
|
1185
|
+
const { action } = await inquirer.prompt([{
|
|
1186
|
+
type: 'list',
|
|
1187
|
+
name: 'action',
|
|
1188
|
+
message: bold('Select CI action to trigger:'),
|
|
1189
|
+
choices: [
|
|
1190
|
+
{ name: `${green('✅')} ${bold('Review & Merge PR')} ${dim('— review + auto-merge a specific PR')}`, value: 'review-and-merge' },
|
|
1191
|
+
{ name: `${magenta('📊')} ${bold('Grade Assignment PR')} ${dim('— grade a student submission PR')}`, value: 'grade-assignment' },
|
|
1192
|
+
{ name: `${yellow('🏆')} ${bold('Score Applicants')} ${dim('— score contributors on an issue')}`, value: 'score-applicant' },
|
|
1193
|
+
{ name: `${cyan('🔔')} ${bold('Remind Contributors')} ${dim('— send escalating reminders now')}`, value: 'remind-contributors' },
|
|
1194
|
+
{ name: `${green('📋')} ${bold('Create Issues from File')} ${dim('— bulk-create from JSON/MD file')}`, value: 'create-issues' },
|
|
1195
|
+
new inquirer.Separator(dim(' ─────────────────────────────────────────')),
|
|
1196
|
+
{ name: `${dim('⬅')} ${dim('Back')}`, value: 'back' },
|
|
1197
|
+
],
|
|
1198
|
+
loop: false,
|
|
1199
|
+
}]);
|
|
1200
|
+
if (action === 'back')
|
|
1201
|
+
break;
|
|
1202
|
+
let inputs = { action };
|
|
1203
|
+
if (action === 'review-and-merge') {
|
|
1204
|
+
const { prNum } = await ask([{ type: 'input', name: 'prNum', message: cyan('PR number:'), validate: (v) => /^\d+$/.test(v) || 'Enter a number' }]);
|
|
1205
|
+
inputs.pr_number = prNum;
|
|
1206
|
+
}
|
|
1207
|
+
if (action === 'create-issues') {
|
|
1208
|
+
const { file } = await ask([{ type: 'input', name: 'file', message: cyan('Issues file path:'), default: 'issues.json' }]);
|
|
1209
|
+
inputs.issues_file = file;
|
|
1210
|
+
}
|
|
1211
|
+
await triggerWorkflow(action, inputs, ref, WORKFLOW_FILE);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
async function triggerWorkflow(action, extraInputs = {}, ref, workflowFile = 'gitpadi.yml') {
|
|
1215
|
+
const owner = getOwner();
|
|
1216
|
+
const repo = getRepo();
|
|
1217
|
+
const octokit = getOctokit();
|
|
1218
|
+
const ora = (await import('ora')).default;
|
|
1219
|
+
if (!ref) {
|
|
1220
|
+
try {
|
|
1221
|
+
const { data } = await octokit.repos.get({ owner, repo });
|
|
1222
|
+
ref = data.default_branch || 'main';
|
|
1223
|
+
}
|
|
1224
|
+
catch {
|
|
1225
|
+
ref = 'main';
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
const spinner = ora(` Triggering ${bold(action)} on ${cyan(`${owner}/${repo}`)}…`).start();
|
|
1229
|
+
try {
|
|
1230
|
+
await octokit.actions.createWorkflowDispatch({
|
|
1231
|
+
owner, repo,
|
|
1232
|
+
workflow_id: workflowFile,
|
|
1233
|
+
ref,
|
|
1234
|
+
inputs: { action, ...extraInputs },
|
|
1235
|
+
});
|
|
1236
|
+
spinner.succeed(` ✅ ${bold(action)} triggered on branch ${cyan(ref)}`);
|
|
1237
|
+
console.log(dim(` Monitor at: https://github.com/${owner}/${repo}/actions\n`));
|
|
1238
|
+
}
|
|
1239
|
+
catch (e) {
|
|
1240
|
+
spinner.fail(` Failed to trigger workflow: ${e.message}`);
|
|
1241
|
+
console.log(dim(` Make sure ${workflowFile} exists in .github/workflows/ and has workflow_dispatch enabled.\n`));
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
// ── My Score Menu ──────────────────────────────────────────────────────
|
|
1245
|
+
async function myScoreMenu() {
|
|
1246
|
+
const ora = (await import('ora')).default;
|
|
1247
|
+
const { fetchProfile, scoreApplicant, TIER_EMOJI } = await import('./core/scorer.js');
|
|
1248
|
+
const spinner = ora(' Fetching your GitHub profile…').start();
|
|
1249
|
+
try {
|
|
1250
|
+
const me = await getAuthenticatedUser();
|
|
1251
|
+
const profile = await fetchProfile(me, '');
|
|
1252
|
+
const scored = scoreApplicant(profile, []);
|
|
1253
|
+
spinner.succeed(` @${me} ${TIER_EMOJI[scored.tier]} Tier ${scored.tier} ${scored.score}/100`);
|
|
1254
|
+
console.log();
|
|
1255
|
+
console.log(bold(' 📊 Score Breakdown'));
|
|
1256
|
+
console.log(` ${'─'.repeat(40)}`);
|
|
1257
|
+
console.log(` Account Maturity ${magenta(`${scored.breakdown.accountMaturity}/15`)}`);
|
|
1258
|
+
console.log(` Repo Experience ${cyan(`${scored.breakdown.repoExperience}/30`)}`);
|
|
1259
|
+
console.log(` GitHub Presence ${green(`${scored.breakdown.githubPresence}/15`)}`);
|
|
1260
|
+
console.log(` Activity Level ${yellow(`${scored.breakdown.activityLevel}/15`)}`);
|
|
1261
|
+
console.log(` Language Relevance ${magenta(`${scored.breakdown.languageRelevance}/10`)}`);
|
|
1262
|
+
console.log(` ${'─'.repeat(40)}`);
|
|
1263
|
+
console.log(` ${bold('Total')} ${bold(`${scored.score}/100`)} ${TIER_EMOJI[scored.tier]} ${bold(`Tier ${scored.tier}`)}`);
|
|
1264
|
+
console.log();
|
|
1265
|
+
const tierMsg = {
|
|
1266
|
+
S: green('Exceptional — you qualify for auto-assign on Drips/GrantFox issues.'),
|
|
1267
|
+
A: green('Strong — most maintainers will assign you on application.'),
|
|
1268
|
+
B: yellow('Decent — you\'ll get considered. Keep contributing to improve.'),
|
|
1269
|
+
C: yellow('Building up — contribute more to boost your score.'),
|
|
1270
|
+
D: red('Early stage — focus on getting PRs merged to level up.'),
|
|
1271
|
+
};
|
|
1272
|
+
console.log(` ${tierMsg[scored.tier]}`);
|
|
1273
|
+
console.log();
|
|
1274
|
+
}
|
|
1275
|
+
catch (e) {
|
|
1276
|
+
spinner.fail(` Could not load profile: ${e.message}`);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
// ── My Applications Menu ───────────────────────────────────────────────
|
|
1280
|
+
async function myApplicationsMenu() {
|
|
1281
|
+
const ora = (await import('ora')).default;
|
|
1282
|
+
const { APPLICATION_PATTERNS } = await import('./core/scorer.js');
|
|
1283
|
+
const octokit = getOctokit();
|
|
1284
|
+
const { target } = await inquirer.prompt([{
|
|
1285
|
+
type: 'input',
|
|
1286
|
+
name: 'target',
|
|
1287
|
+
message: bold('Repo to check (owner/repo or leave blank for current):'),
|
|
1288
|
+
default: getOwner() && getRepo() ? `${getOwner()}/${getRepo()}` : '',
|
|
1289
|
+
}]);
|
|
1290
|
+
const [owner, repo] = (target || `${getOwner()}/${getRepo()}`).split('/');
|
|
1291
|
+
if (!owner || !repo) {
|
|
1292
|
+
console.log(yellow(' No repo selected.'));
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const spinner = ora(` Fetching your applications in ${cyan(`${owner}/${repo}`)}…`).start();
|
|
1296
|
+
const me = await getAuthenticatedUser();
|
|
1297
|
+
try {
|
|
1298
|
+
// Search issues where you commented with an application-style comment
|
|
1299
|
+
const { data: comments } = await octokit.search.issuesAndPullRequests({
|
|
1300
|
+
q: `commenter:${me} type:issue state:open repo:${owner}/${repo}`,
|
|
1301
|
+
per_page: 50, sort: 'updated',
|
|
1302
|
+
});
|
|
1303
|
+
const applied = [];
|
|
1304
|
+
for (const item of comments.items) {
|
|
1305
|
+
const { data: issueComments } = await octokit.issues.listComments({
|
|
1306
|
+
owner, repo, issue_number: item.number, per_page: 100,
|
|
1307
|
+
});
|
|
1308
|
+
const myComments = issueComments.filter((c) => c.user?.login === me &&
|
|
1309
|
+
APPLICATION_PATTERNS.some(p => p.test(c.body || '')));
|
|
1310
|
+
if (myComments.length > 0) {
|
|
1311
|
+
const assignees = item.assignees?.map((a) => a.login) || [];
|
|
1312
|
+
const isAssignedToMe = assignees.includes(me);
|
|
1313
|
+
applied.push({
|
|
1314
|
+
number: item.number,
|
|
1315
|
+
title: item.title,
|
|
1316
|
+
url: item.html_url,
|
|
1317
|
+
assignees,
|
|
1318
|
+
status: isAssignedToMe ? green('✅ Assigned to you') : assignees.length > 0 ? yellow(`⚠ Assigned to @${assignees[0]}`) : cyan('⏳ Pending'),
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
spinner.succeed(` ${applied.length} application(s) found in ${owner}/${repo}`);
|
|
1323
|
+
console.log();
|
|
1324
|
+
if (applied.length === 0) {
|
|
1325
|
+
console.log(dim(' You haven\'t applied for any open issues in this repo yet.'));
|
|
1326
|
+
console.log(dim(' Use "Bounty Hunter" or "Apply for Issue" to get started.'));
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
applied.forEach(a => {
|
|
1330
|
+
console.log(` ${cyan(`#${a.number}`)} ${bold(a.title)}`);
|
|
1331
|
+
console.log(` ${a.status} ${dim(a.url)}`);
|
|
1332
|
+
console.log();
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
catch (e) {
|
|
1337
|
+
spinner.fail(e.message);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
// ── My Open PRs Menu ───────────────────────────────────────────────────
|
|
1341
|
+
async function myOpenPRsMenu() {
|
|
1342
|
+
const ora = (await import('ora')).default;
|
|
1343
|
+
const octokit = getOctokit();
|
|
1344
|
+
const owner = getOwner();
|
|
1345
|
+
const repo = getRepo();
|
|
1346
|
+
const me = await getAuthenticatedUser();
|
|
1347
|
+
const spinner = ora(` Fetching your open PRs in ${cyan(`${owner}/${repo}`)}…`).start();
|
|
1348
|
+
try {
|
|
1349
|
+
const { data: prs } = await octokit.pulls.list({ owner, repo, state: 'open', per_page: 50 });
|
|
1350
|
+
const mine = prs.filter((p) => p.user?.login === me);
|
|
1351
|
+
spinner.succeed(` ${mine.length} open PR(s) as @${me}`);
|
|
1352
|
+
console.log();
|
|
1353
|
+
if (mine.length === 0) {
|
|
1354
|
+
console.log(dim(' No open PRs. Use "Submit PR" to open one.'));
|
|
1355
|
+
}
|
|
1356
|
+
else {
|
|
1357
|
+
mine.forEach((p) => {
|
|
1358
|
+
const age = Math.floor((Date.now() - new Date(p.updated_at).getTime()) / 86_400_000);
|
|
1359
|
+
const draft = p.draft ? yellow(' [draft]') : '';
|
|
1360
|
+
console.log(` ${cyan(`#${p.number}`)}${draft} ${bold(p.title)}`);
|
|
1361
|
+
console.log(` ${dim(`branch: ${p.head.ref}`)} ${dim(`updated ${age}d ago`)} ${dim(p.html_url)}`);
|
|
1362
|
+
console.log();
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
catch (e) {
|
|
1367
|
+
spinner.fail(e.message);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
// ── Repo Stats Menu ────────────────────────────────────────────────────
|
|
1371
|
+
async function repoStatsMenu() {
|
|
1372
|
+
const ora = (await import('ora')).default;
|
|
1373
|
+
const octokit = getOctokit();
|
|
1374
|
+
const owner = getOwner();
|
|
1375
|
+
const repo = getRepo();
|
|
1376
|
+
const spinner = ora(` Loading stats for ${cyan(`${owner}/${repo}`)}…`).start();
|
|
1377
|
+
try {
|
|
1378
|
+
const [repoData, openIssues, openPRs, closedPRs, contributors] = await Promise.all([
|
|
1379
|
+
octokit.repos.get({ owner, repo }),
|
|
1380
|
+
octokit.issues.listForRepo({ owner, repo, state: 'open', per_page: 1 }),
|
|
1381
|
+
octokit.pulls.list({ owner, repo, state: 'open', per_page: 1 }),
|
|
1382
|
+
octokit.pulls.list({ owner, repo, state: 'closed', per_page: 50 }),
|
|
1383
|
+
octokit.repos.listContributors({ owner, repo, per_page: 10 }),
|
|
1384
|
+
]);
|
|
1385
|
+
const merged = closedPRs.data.filter((p) => p.merged_at).length;
|
|
1386
|
+
const mergeRate = closedPRs.data.length > 0
|
|
1387
|
+
? Math.round((merged / closedPRs.data.length) * 100) : 0;
|
|
1388
|
+
spinner.succeed();
|
|
1389
|
+
console.log();
|
|
1390
|
+
console.log(bold(` 📊 ${owner}/${repo}`));
|
|
1391
|
+
console.log(` ${'─'.repeat(42)}`);
|
|
1392
|
+
console.log(` ⭐ Stars ${yellow(String(repoData.data.stargazers_count))}`);
|
|
1393
|
+
console.log(` 🍴 Forks ${cyan(String(repoData.data.forks_count))}`);
|
|
1394
|
+
console.log(` 📋 Open Issues ${magenta(String(repoData.data.open_issues_count))}`);
|
|
1395
|
+
console.log(` 🔀 Open PRs ${cyan(String(openPRs.data.length ? '1+' : '0'))}`);
|
|
1396
|
+
console.log(` ✅ Merge Rate ${mergeRate >= 70 ? green(`${mergeRate}%`) : yellow(`${mergeRate}%`)} (last 50 closed PRs)`);
|
|
1397
|
+
console.log(` 🌿 Default Branch ${dim(repoData.data.default_branch)}`);
|
|
1398
|
+
console.log(` 📝 Language ${dim(repoData.data.language || 'mixed')}`);
|
|
1399
|
+
console.log();
|
|
1400
|
+
console.log(` Top Contributors:`);
|
|
1401
|
+
contributors.data.slice(0, 5).forEach((c, i) => {
|
|
1402
|
+
const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : ' ';
|
|
1403
|
+
console.log(` ${medal} @${c.login} ${dim(`${c.contributions} commits`)}`);
|
|
1404
|
+
});
|
|
1405
|
+
console.log();
|
|
1406
|
+
}
|
|
1407
|
+
catch (e) {
|
|
1408
|
+
spinner.fail(e.message);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
420
1411
|
// ── Issue Menu ─────────────────────────────────────────────────────────
|
|
421
1412
|
async function issueMenu() {
|
|
422
1413
|
const { action } = await inquirer.prompt([{
|
|
@@ -852,6 +1843,26 @@ function setupCommander() {
|
|
|
852
1843
|
});
|
|
853
1844
|
});
|
|
854
1845
|
program.command('logs').description('📋 View Action logs').action(async () => { await contribute.viewLogs(); });
|
|
1846
|
+
program.command('hunt')
|
|
1847
|
+
.description('🎯 Bounty Hunter — auto-apply to Drips Wave & GrantFox issues')
|
|
1848
|
+
.option('-p, --platform <p>', 'Platform: drips | grantfox | all (default: all)', 'all')
|
|
1849
|
+
.option('-m, --max <n>', 'Max applications to post (default: 3)', '3')
|
|
1850
|
+
.option('-s, --skills <langs>', 'Comma-separated languages to filter by (e.g. typescript,rust)', '')
|
|
1851
|
+
.option('--min-points <n>', 'Minimum Drips points (e.g. 150)', '0')
|
|
1852
|
+
.option('--dry-run', 'Show what would be applied for without posting', false)
|
|
1853
|
+
.option('--include-assigned', 'Include already-assigned issues', false)
|
|
1854
|
+
.action(async (o) => {
|
|
1855
|
+
const platform = (['drips', 'grantfox', 'all'].includes(o.platform) ? o.platform : 'all');
|
|
1856
|
+
await runBountyHunter({
|
|
1857
|
+
platform,
|
|
1858
|
+
maxApplications: parseInt(o.max) || 3,
|
|
1859
|
+
skills: o.skills ? o.skills.split(',').map((s) => s.trim()).filter(Boolean) : [],
|
|
1860
|
+
minPoints: parseInt(o.minPoints) || 0,
|
|
1861
|
+
dryRun: !!o.dryRun,
|
|
1862
|
+
skipAssigned: !o.includeAssigned,
|
|
1863
|
+
verbose: false,
|
|
1864
|
+
});
|
|
1865
|
+
});
|
|
855
1866
|
return program;
|
|
856
1867
|
}
|
|
857
1868
|
// ── Entry Point ────────────────────────────────────────────────────────
|