@hypermode/hyp-cli
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -15,2 +15,4 @@ /* | ||
import open from "open"; | ||
import { execSync } from "child_process"; | ||
import path from "path"; | ||
import { ciStr } from "../../util/ci.js"; | ||
@@ -95,3 +97,30 @@ import { getProjectsByOrgReq, sendMapRepoAndFinishProjectCreationReq, sendCreateProjectReq, sendGetRepoIdReq } from "../../util/graphql.js"; | ||
} | ||
const gitUrl = await getGitRemoteUrl(gitConfigFilePath); | ||
// Check if the current branch is 'main' | ||
let currentBranch = ""; | ||
try { | ||
currentBranch = execSync("git symbolic-ref --short HEAD", { encoding: "utf-8" }).trim(); | ||
} | ||
catch (error) { | ||
this.log(chalk.red("Unable to determine the current branch.")); | ||
throw error; | ||
} | ||
if (currentBranch !== "main") { | ||
this.log(chalk.red("You must be on the 'main' branch to link your repository.")); | ||
this.log("Please switch to the 'main' branch:"); | ||
this.log(` > ${chalk.blue("git checkout main")}`); | ||
this.log("or rename your current branch to 'main'."); | ||
this.log(` > ${chalk.blue("git branch -m main")}`); | ||
this.exit(1); | ||
} | ||
const remoteUrl = await getGitRemoteUrl(gitConfigFilePath); | ||
if (!remoteUrl) { | ||
this.log(chalk.red("`hyp link` requires a git remote to work")); | ||
const gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim(); | ||
const projectName = path.basename(gitRoot); | ||
this.log(`Please create a GitHub repository: https://github.com/new?name=${projectName}`); | ||
this.log(`And push your code:`); | ||
this.log(` > ${chalk.blue("git remote add origin <GIT_URL>)")}`); | ||
this.log(` > ${chalk.blue("git push -u origin main")}`); | ||
this.exit(1); | ||
} | ||
// check the .hypermode/settings.json and see if there is a installationId with a key for the github owner. if there is, | ||
@@ -109,3 +138,3 @@ // continue, if not send them to github app installation page, and then go to callback server, and add installation id to settings.json | ||
} | ||
const { gitOwner, repoName } = parseGitUrl(gitUrl); | ||
const { gitOwner, repoName } = parseGitUrl(remoteUrl); | ||
const repoFullName = `${gitOwner}/${repoName}`; | ||
@@ -121,3 +150,3 @@ let installationId = null; | ||
// call hypermode getRepoId with the installationId and the git url, if it returns a repoId, continue, if not, throw an error | ||
const repoId = await sendGetRepoIdReq(settings.jwt, installationId, gitUrl); | ||
const repoId = await sendGetRepoIdReq(settings.jwt, installationId, remoteUrl); | ||
if (!repoId) { | ||
@@ -124,0 +153,0 @@ throw new Error("No repoId found for the given installationId and gitUrl"); |
@@ -15,3 +15,3 @@ import { Org, Project } from "../util/types.js"; | ||
export declare function getGitConfigFilePath(): string; | ||
export declare function getGitRemoteUrl(filePath: string): Promise<string>; | ||
export declare function getGitRemoteUrl(filePath: string): Promise<string | null>; | ||
export declare function readSettingsJson(filePath: string): Promise<{ | ||
@@ -18,0 +18,0 @@ content: string; |
@@ -111,3 +111,3 @@ /* | ||
if (!remoteMatch) { | ||
throw new Error(chalk.red("No remote origin found in .git/config, please set up a remote origin with `git remote add origin <url>`.")); | ||
return null; | ||
} | ||
@@ -114,0 +114,0 @@ return remoteMatch[1]; |
@@ -100,3 +100,3 @@ { | ||
}, | ||
"version": "0.1.11" | ||
"version": "0.1.12" | ||
} |
{ | ||
"name": "@hypermode/hyp-cli", | ||
"description": "The Hypermode CLI", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"author": "Hypermode Inc.", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97930
1265
2