gitpadi 2.0.1 → 2.0.3
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/README.md +57 -225
- package/dist/cli.js +279 -146
- package/dist/commands/contribute.js +314 -0
- package/dist/commands/issues.js +107 -24
- package/dist/commands/repos.js +31 -21
- package/dist/core/github.js +47 -2
- package/package.json +2 -2
- package/src/cli.ts +312 -174
- package/src/commands/contribute.ts +354 -0
- package/src/commands/issues.ts +118 -26
- package/src/commands/repos.ts +41 -26
- package/src/core/github.ts +54 -2
package/src/core/github.ts
CHANGED
|
@@ -3,6 +3,7 @@ import chalk from 'chalk';
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import os from 'node:os';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
const CONFIG_DIR = path.join(os.homedir(), '.gitpadi');
|
|
@@ -33,12 +34,31 @@ export function saveConfig(config: GitPadiConfig): void {
|
|
|
33
34
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Attempts to detect owner/repo from local git remotes
|
|
39
|
+
*/
|
|
40
|
+
export function detectLocalRepo(): { owner: string, repo: string } | null {
|
|
41
|
+
try {
|
|
42
|
+
const remotes = execSync('git remote -v', { encoding: 'utf-8', stdio: 'pipe' });
|
|
43
|
+
const match = remotes.match(/github\.com[:/]([^/]+)\/([^/.]+)(?:\.git)?/);
|
|
44
|
+
if (match) {
|
|
45
|
+
return { owner: match[1], repo: match[2] };
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
// Not a git repo or git not found
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
export function initGitHub(token?: string, owner?: string, repo?: string): void {
|
|
37
54
|
const config = loadConfig();
|
|
55
|
+
const detected = detectLocalRepo();
|
|
38
56
|
|
|
39
57
|
_token = token || process.env.GITHUB_TOKEN || process.env.GITPADI_TOKEN || config?.token || '';
|
|
40
|
-
|
|
41
|
-
|
|
58
|
+
|
|
59
|
+
// Priority: Explicit > Env > Config > Local Git detection
|
|
60
|
+
_owner = owner || process.env.GITHUB_OWNER || config?.owner || detected?.owner || process.env.GITHUB_REPOSITORY?.split('/')[0] || '';
|
|
61
|
+
_repo = repo || process.env.GITHUB_REPO || config?.repo || detected?.repo || process.env.GITHUB_REPOSITORY?.split('/')[1] || '';
|
|
42
62
|
|
|
43
63
|
if (_token) {
|
|
44
64
|
_octokit = new Octokit({ auth: _token });
|
|
@@ -73,3 +93,35 @@ export function requireRepo(): void {
|
|
|
73
93
|
process.exit(1);
|
|
74
94
|
}
|
|
75
95
|
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* ── Phase 1: Contributor Support Helpers ──
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
export async function getAuthenticatedUser(): Promise<string> {
|
|
102
|
+
const { data } = await getOctokit().users.getAuthenticated();
|
|
103
|
+
return data.login;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function forkRepo(owner: string, repo: string): Promise<string> {
|
|
107
|
+
const octokit = getOctokit();
|
|
108
|
+
const { data } = await octokit.repos.createFork({ owner, repo });
|
|
109
|
+
return data.full_name; // e.g. "myuser/original-repo"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function getRepoDetails(owner: string, repo: string) {
|
|
113
|
+
const { data } = await getOctokit().repos.get({ owner, repo });
|
|
114
|
+
return data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function getLatestCheckRuns(owner: string, repo: string, ref: string) {
|
|
118
|
+
const octokit = getOctokit();
|
|
119
|
+
const { data: checks } = await octokit.checks.listForRef({ owner, repo, ref });
|
|
120
|
+
const { data: status } = await octokit.repos.getCombinedStatusForRef({ owner, repo, ref });
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
checkRuns: checks.check_runs,
|
|
124
|
+
combinedState: status.state, // 'success', 'failure', 'pending'
|
|
125
|
+
statuses: status.statuses
|
|
126
|
+
};
|
|
127
|
+
}
|