Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 9689d19

Browse files
authored
use project name as slug (#34)
1 parent 7a128d2 commit 9689d19

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

package-lock.json

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@oclif/core": "^4",
1717
"@oclif/plugin-help": "^6",
1818
"@oclif/plugin-plugins": "^5",
19+
"@sindresorhus/slugify": "^2.2.1",
1920
"@typescript-eslint/eslint-plugin": "^8.11.0",
2021
"@typescript-eslint/utils": "^8.11.0",
2122
"chalk": "^5.3.0",

src/util/graphql.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fetch from 'node-fetch'
22

33
import {Org, Project} from '../util/types.js'
4+
import { getSlugFromName } from './index.js'
45

56
export async function sendGraphQLReqToHypermode(jwt: string, query: string): Promise<any> {
67
const url = 'https://api.hypermode.com/graphql'
@@ -38,9 +39,10 @@ export async function sendCreateProjectRepoReq(jwt: string, id: string, repoId:
3839
}
3940

4041
export async function sendCreateProjectReq(jwt: string, orgId: string, projectName: string, repoId: string, repoName: string): Promise<Project> {
42+
const slug = getSlugFromName(projectName)
4143
const query = `
4244
mutation CreateProjectBranchBackend {
43-
createProjectBranchBackend(input: {orgId: "${orgId}", clusterId: "clu-018f07d5-2446-7dbe-a766-dfab00c726de", name: "${projectName}", repoId: "${repoId}", repoName: "${repoName}", sourceType: CUSTOM, defaultBranchName: "main"}
45+
createProjectBranchBackend(input: {orgId: "${orgId}", clusterId: "clu-018f07d5-2446-7dbe-a766-dfab00c726de", name: "${projectName}", slug: "${slug}", repoId: "${repoId}", repoName: "${repoName}", sourceType: CUSTOM, defaultBranchName: "main"}
4446
) {
4547
id
4648
name

src/util/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {ExitPromptError} from '@inquirer/core'
22
import * as inquirer from '@inquirer/prompts'
33
import chalk from 'chalk'
4+
import slugify from "@sindresorhus/slugify"
45
import * as fs from 'node:fs'
56
import * as path from 'node:path'
67
import {Interface} from 'node:readline'
@@ -56,6 +57,11 @@ export async function promptProjectName(projects: Project[]): Promise<string> {
5657
message: 'Creating a new project. Please enter a project name:',
5758
})
5859

60+
if (!validateProjectName(projectName)) {
61+
console.log(chalk.red('Project name must be longer than 3 characters.'))
62+
return promptProjectName(projects)
63+
}
64+
5965
// check if project name already exists in projects
6066
const projectNames = projects.map(project => project.name)
6167
if (projectNames.includes(projectName)) {
@@ -67,6 +73,14 @@ export async function promptProjectName(projects: Project[]): Promise<string> {
6773
return projectName
6874
}
6975

76+
function validateProjectName(projectName: string): boolean {
77+
return projectName.length > 3
78+
}
79+
80+
export function getSlugFromName(name: string): string {
81+
return slugify(name)
82+
}
83+
7084
export async function confirmOverwriteCiHypFile(): Promise<boolean> {
7185
return inquirer.confirm({
7286
default: true,

0 commit comments

Comments
 (0)