Skip to content

Commit

Permalink
fix: no candidate github repo passed to repo creation
Browse files Browse the repository at this point in the history
  • Loading branch information
maneike committed Nov 18, 2024
1 parent 6c3bc31 commit 50941e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/core/installMachine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
initializeRepositoryActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
await initializeRepository({ projectName: input.stateData.options.name, visibility: 'private' });
await initializeRepository({
projectName: input.stateData.options.name,
visibility: 'private',
stateData: input.stateData,
});
input.stateData.stepsCompleted.initializeRepository = true;
saveStateToRcFile(input.stateData, input.projectDir);
} catch (error) {
Expand All @@ -337,7 +341,7 @@ const createInstallMachine = (initialContext: InstallMachineContext) => {
pushToGitHubActor: createStepMachine(
fromPromise<void, InstallMachineContext, AnyEventObject>(async ({ input }) => {
try {
await pushToGitHub(input.stateData.options.name);
await pushToGitHub(input.stateData.githubCandidateName);
input.stateData.stepsCompleted.pushToGitHub = true;
saveStateToRcFile(input.stateData, input.projectDir);
} catch (error) {
Expand Down
8 changes: 5 additions & 3 deletions packages/core/installMachine/installSteps/github/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
isGitHubAuthenticated,
setupGitRepository,
} from './repositoryManager';
import { InstallMachineContext } from '../../../types';

interface ProjectRepositoryOptions {
projectName: string;
visibility: 'public' | 'private';
stateData: InstallMachineContext['stateData'];
}

// Helper function to check if GitHub CLI is installed
Expand Down Expand Up @@ -61,7 +63,7 @@ const ensureGitHubAuthentication = async () => {
};

export const initializeRepository = async (options: ProjectRepositoryOptions) => {
const { projectName, visibility } = options;
const { projectName, visibility, stateData } = options;

await checkGitHubCLI();
await ensureGitHubAuthentication();
Expand All @@ -74,7 +76,7 @@ export const initializeRepository = async (options: ProjectRepositoryOptions) =>
}

// Check if the repository exists and create it
const repoName = await createGitHubRepository(projectName, visibility, username);
await createGitHubRepository(projectName, visibility, username, stateData);

await setupGitRepository(repoName, username);
await setupGitRepository();
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import inquirer from 'inquirer';
import chalk from 'chalk';
import { logger } from '../../../utils/logger';
import { execAsync } from '../../../utils/execAsync';
import { InstallMachineContext } from '../../../types';

const generateUniqueRepoName = async (baseName: string): Promise<string> => {
const cleanBaseName = baseName.replace(/-\d+$/, ''); // Clean base name
Expand Down Expand Up @@ -69,6 +70,7 @@ export const createGitHubRepository = async (
projectName: string,
repositoryVisibility: 'public' | 'private',
username: string,
stateData: InstallMachineContext['stateData'],
) => {
let repoName = projectName;

Expand All @@ -90,6 +92,8 @@ export const createGitHubRepository = async (
},
]);
repoName = confirmedName;
// Update the state with the confirmed repository name in Xstate
stateData.githubCandidateName = confirmedName;
}
spinner.stop();
} catch (error) {
Expand Down Expand Up @@ -126,7 +130,7 @@ const executeCommands = async (commands: string[]) => {
}
};

export const setupGitRepository = async (projectName: string, username: string) => {
export const setupGitRepository = async () => {
await logger.withSpinner('github', `Setting up Git for the repository...`, async (spinner) => {
const commands = [`git init`, `git add .`];
await executeCommands(commands);
Expand Down
1 change: 1 addition & 0 deletions packages/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface StaplerState {
projectName: string;
stepsCompleted: StepsCompleted;
options: ProjectOptions;
githubCandidateName: string;
}

export interface InstallMachineContext {
Expand Down

0 comments on commit 50941e2

Please sign in to comment.