feat: extension detects project name from git remote URL (priority over folder name)
This commit is contained in:
@@ -24,21 +24,39 @@ let isActive = false;
|
|||||||
// Track pending approvals we've already sent
|
// Track pending approvals we've already sent
|
||||||
const sentPendingIds = new Set<string>();
|
const sentPendingIds = new Set<string>();
|
||||||
|
|
||||||
|
import * as cp from 'child_process';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect project name from workspace.
|
* Detect project name from workspace.
|
||||||
* Priority: settings > workspace folder name > fallback
|
* Priority: settings > git remote repo name > workspace folder name
|
||||||
*/
|
*/
|
||||||
function detectProjectName(): string {
|
function detectProjectName(): string {
|
||||||
const config = vscode.workspace.getConfiguration('gravityBridge');
|
const config = vscode.workspace.getConfiguration('gravityBridge');
|
||||||
const configName = config.get<string>('projectName');
|
const configName = config.get<string>('projectName');
|
||||||
if (configName) { return configName; }
|
if (configName) { return configName; }
|
||||||
|
|
||||||
// Use workspace folder name
|
// Try git remote URL → extract repo name
|
||||||
const folders = vscode.workspace.workspaceFolders;
|
const folders = vscode.workspace.workspaceFolders;
|
||||||
if (folders && folders.length > 0) {
|
if (folders && folders.length > 0) {
|
||||||
const folderName = folders[0].name;
|
const cwd = folders[0].uri.fsPath;
|
||||||
// Convert to snake_case: "antig_web" → "antig_web", "My Project" → "my_project"
|
try {
|
||||||
return folderName.toLowerCase().replace(/[\s\-]+/g, '_');
|
const remoteUrl = cp.execSync('git remote get-url origin', {
|
||||||
|
cwd, encoding: 'utf-8', timeout: 3000
|
||||||
|
}).trim();
|
||||||
|
// "https://gitea.example.com/Variet/gravity_control.git" → "gravity_control"
|
||||||
|
// "git@github.com:user/repo.git" → "repo"
|
||||||
|
const match = remoteUrl.match(/\/([^\/]+?)(?:\.git)?$/);
|
||||||
|
if (match && match[1]) {
|
||||||
|
const repoName = match[1].toLowerCase().replace(/[\s\-]+/g, '_');
|
||||||
|
console.log(`Gravity Bridge: project from git remote → "${repoName}"`);
|
||||||
|
return repoName;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// No git or no remote — fall through
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: workspace folder name
|
||||||
|
return folders[0].name.toLowerCase().replace(/[\s\-]+/g, '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'unknown_project';
|
return 'unknown_project';
|
||||||
|
|||||||
Reference in New Issue
Block a user