Skip to content

Commit 4b6384b

Browse files
committed
Refactor initial setup process: Consolidate setup file copying and directory creation into the InitialSetupUseCase, updating return values to include skipped files for better logging.
1 parent 8d4757f commit 4b6384b

File tree

8 files changed

+53
-57
lines changed

8 files changed

+53
-57
lines changed

build/cli/index.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46418,7 +46418,6 @@ const constants_1 = __nccwpck_require__(8593);
4641846418
const chalk_1 = __importDefault(__nccwpck_require__(7037));
4641946419
const boxen_1 = __importDefault(__nccwpck_require__(4506));
4642046420
const queue_utils_1 = __nccwpck_require__(9800);
46421-
const setup_files_1 = __nccwpck_require__(1666);
4642246421
async function mainRun(execution) {
4642346422
const results = [];
4642446423
await execution.setup();
@@ -46459,19 +46458,6 @@ async function mainRun(execution) {
4645946458
title: constants_1.TITLE,
4646046459
titleAlignment: 'center'
4646146460
}));
46462-
if (execution.isSingleAction && execution.singleAction.currentSingleAction === constants_1.ACTIONS.INITIAL_SETUP) {
46463-
const cwd = process.cwd();
46464-
(0, logger_1.logInfo)('📁 Ensuring .github and .github/workflows exist...');
46465-
(0, setup_files_1.ensureGitHubDirs)(cwd);
46466-
(0, logger_1.logInfo)('📋 Copying setup files from setup/ to .github/ (skipping existing)...');
46467-
const copied = (0, setup_files_1.copySetupFiles)(cwd);
46468-
if (copied > 0) {
46469-
(0, logger_1.logInfo)(`✅ Copied ${copied} file(s).`);
46470-
}
46471-
else {
46472-
(0, logger_1.logInfo)('ℹ️ No setup/ folder found or all files already exist; nothing to copy.');
46473-
}
46474-
}
4647546461
}
4647646462
try {
4647746463
if (execution.isSingleAction) {
@@ -52873,6 +52859,7 @@ const issue_repository_1 = __nccwpck_require__(57);
5287352859
const project_repository_1 = __nccwpck_require__(7917);
5287452860
const result_1 = __nccwpck_require__(7305);
5287552861
const logger_1 = __nccwpck_require__(8836);
52862+
const setup_files_1 = __nccwpck_require__(1666);
5287652863
class InitialSetupUseCase {
5287752864
constructor() {
5287852865
this.taskId = 'InitialSetupUseCase';
@@ -52883,6 +52870,11 @@ class InitialSetupUseCase {
5288352870
const steps = [];
5288452871
const errors = [];
5288552872
try {
52873+
// 0. Setup files (.github/workflows, pull_request_template.md, .env)
52874+
(0, logger_1.logInfo)('📋 Ensuring .github and copying setup files...');
52875+
(0, setup_files_1.ensureGitHubDirs)(process.cwd());
52876+
const filesResult = (0, setup_files_1.copySetupFiles)(process.cwd());
52877+
steps.push(`✅ Setup files: ${filesResult.copied} copied, ${filesResult.skipped} already existed`);
5288652878
// 1. Verificar acceso a GitHub con Personal Access Token
5288752879
(0, logger_1.logInfo)('🔐 Checking GitHub access...');
5288852880
const githubAccessResult = await this.verifyGitHubAccess(param);
@@ -57994,13 +57986,14 @@ function ensureGitHubDirs(cwd) {
5799457986
* Skips files that already exist at destination (no overwrite).
5799557987
* Logs each file copied or skipped. No-op if setup/ does not exist.
5799657988
* @param cwd - Repo root
57997-
* @returns Number of files copied
57989+
* @returns { copied, skipped }
5799857990
*/
5799957991
function copySetupFiles(cwd) {
5800057992
const setupDir = path.join(cwd, 'setup');
5800157993
if (!fs.existsSync(setupDir))
58002-
return 0;
57994+
return { copied: 0, skipped: 0 };
5800357995
let copied = 0;
57996+
let skipped = 0;
5800457997
const workflowsSrc = path.join(setupDir, 'workflows');
5800557998
const workflowsDst = path.join(cwd, '.github', 'workflows');
5800657999
if (fs.existsSync(workflowsSrc)) {
@@ -58011,6 +58004,7 @@ function copySetupFiles(cwd) {
5801158004
if (fs.statSync(src).isFile()) {
5801258005
if (fs.existsSync(dst)) {
5801358006
(0, logger_1.logInfo)(` ⏭️ .github/workflows/${f} already exists; skipping.`);
58007+
skipped += 1;
5801458008
}
5801558009
else {
5801658010
fs.copyFileSync(src, dst);
@@ -58025,6 +58019,7 @@ function copySetupFiles(cwd) {
5802558019
if (fs.existsSync(prTemplateSrc)) {
5802658020
if (fs.existsSync(prTemplateDst)) {
5802758021
(0, logger_1.logInfo)(' ⏭️ .github/pull_request_template.md already exists; skipping.');
58022+
skipped += 1;
5802858023
}
5802958024
else {
5803058025
fs.copyFileSync(prTemplateSrc, prTemplateDst);
@@ -58037,14 +58032,15 @@ function copySetupFiles(cwd) {
5803758032
if (fs.existsSync(envSrc) && fs.statSync(envSrc).isFile()) {
5803858033
if (fs.existsSync(envDst)) {
5803958034
(0, logger_1.logInfo)(' ⏭️ .env already exists; skipping.');
58035+
skipped += 1;
5804058036
}
5804158037
else {
5804258038
fs.copyFileSync(envSrc, envDst);
5804358039
(0, logger_1.logInfo)(' ✅ Copied setup/.env → .env');
5804458040
copied += 1;
5804558041
}
5804658042
}
58047-
return copied;
58043+
return { copied, skipped };
5804858044
}
5804958045

5805058046

build/cli/src/utils/setup_files.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export declare function ensureGitHubDirs(cwd: string): void;
88
* Skips files that already exist at destination (no overwrite).
99
* Logs each file copied or skipped. No-op if setup/ does not exist.
1010
* @param cwd - Repo root
11-
* @returns Number of files copied
11+
* @returns { copied, skipped }
1212
*/
13-
export declare function copySetupFiles(cwd: string): number;
13+
export declare function copySetupFiles(cwd: string): {
14+
copied: number;
15+
skipped: number;
16+
};

build/github_action/index.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41936,7 +41936,6 @@ const constants_1 = __nccwpck_require__(8593);
4193641936
const chalk_1 = __importDefault(__nccwpck_require__(7037));
4193741937
const boxen_1 = __importDefault(__nccwpck_require__(4506));
4193841938
const queue_utils_1 = __nccwpck_require__(9800);
41939-
const setup_files_1 = __nccwpck_require__(1666);
4194041939
async function mainRun(execution) {
4194141940
const results = [];
4194241941
await execution.setup();
@@ -41977,19 +41976,6 @@ async function mainRun(execution) {
4197741976
title: constants_1.TITLE,
4197841977
titleAlignment: 'center'
4197941978
}));
41980-
if (execution.isSingleAction && execution.singleAction.currentSingleAction === constants_1.ACTIONS.INITIAL_SETUP) {
41981-
const cwd = process.cwd();
41982-
(0, logger_1.logInfo)('📁 Ensuring .github and .github/workflows exist...');
41983-
(0, setup_files_1.ensureGitHubDirs)(cwd);
41984-
(0, logger_1.logInfo)('📋 Copying setup files from setup/ to .github/ (skipping existing)...');
41985-
const copied = (0, setup_files_1.copySetupFiles)(cwd);
41986-
if (copied > 0) {
41987-
(0, logger_1.logInfo)(`✅ Copied ${copied} file(s).`);
41988-
}
41989-
else {
41990-
(0, logger_1.logInfo)('ℹ️ No setup/ folder found or all files already exist; nothing to copy.');
41991-
}
41992-
}
4199341979
}
4199441980
try {
4199541981
if (execution.isSingleAction) {
@@ -47952,6 +47938,7 @@ const issue_repository_1 = __nccwpck_require__(57);
4795247938
const project_repository_1 = __nccwpck_require__(7917);
4795347939
const result_1 = __nccwpck_require__(7305);
4795447940
const logger_1 = __nccwpck_require__(8836);
47941+
const setup_files_1 = __nccwpck_require__(1666);
4795547942
class InitialSetupUseCase {
4795647943
constructor() {
4795747944
this.taskId = 'InitialSetupUseCase';
@@ -47962,6 +47949,11 @@ class InitialSetupUseCase {
4796247949
const steps = [];
4796347950
const errors = [];
4796447951
try {
47952+
// 0. Setup files (.github/workflows, pull_request_template.md, .env)
47953+
(0, logger_1.logInfo)('📋 Ensuring .github and copying setup files...');
47954+
(0, setup_files_1.ensureGitHubDirs)(process.cwd());
47955+
const filesResult = (0, setup_files_1.copySetupFiles)(process.cwd());
47956+
steps.push(`✅ Setup files: ${filesResult.copied} copied, ${filesResult.skipped} already existed`);
4796547957
// 1. Verificar acceso a GitHub con Personal Access Token
4796647958
(0, logger_1.logInfo)('🔐 Checking GitHub access...');
4796747959
const githubAccessResult = await this.verifyGitHubAccess(param);
@@ -53469,13 +53461,14 @@ function ensureGitHubDirs(cwd) {
5346953461
* Skips files that already exist at destination (no overwrite).
5347053462
* Logs each file copied or skipped. No-op if setup/ does not exist.
5347153463
* @param cwd - Repo root
53472-
* @returns Number of files copied
53464+
* @returns { copied, skipped }
5347353465
*/
5347453466
function copySetupFiles(cwd) {
5347553467
const setupDir = path.join(cwd, 'setup');
5347653468
if (!fs.existsSync(setupDir))
53477-
return 0;
53469+
return { copied: 0, skipped: 0 };
5347853470
let copied = 0;
53471+
let skipped = 0;
5347953472
const workflowsSrc = path.join(setupDir, 'workflows');
5348053473
const workflowsDst = path.join(cwd, '.github', 'workflows');
5348153474
if (fs.existsSync(workflowsSrc)) {
@@ -53486,6 +53479,7 @@ function copySetupFiles(cwd) {
5348653479
if (fs.statSync(src).isFile()) {
5348753480
if (fs.existsSync(dst)) {
5348853481
(0, logger_1.logInfo)(` ⏭️ .github/workflows/${f} already exists; skipping.`);
53482+
skipped += 1;
5348953483
}
5349053484
else {
5349153485
fs.copyFileSync(src, dst);
@@ -53500,6 +53494,7 @@ function copySetupFiles(cwd) {
5350053494
if (fs.existsSync(prTemplateSrc)) {
5350153495
if (fs.existsSync(prTemplateDst)) {
5350253496
(0, logger_1.logInfo)(' ⏭️ .github/pull_request_template.md already exists; skipping.');
53497+
skipped += 1;
5350353498
}
5350453499
else {
5350553500
fs.copyFileSync(prTemplateSrc, prTemplateDst);
@@ -53512,14 +53507,15 @@ function copySetupFiles(cwd) {
5351253507
if (fs.existsSync(envSrc) && fs.statSync(envSrc).isFile()) {
5351353508
if (fs.existsSync(envDst)) {
5351453509
(0, logger_1.logInfo)(' ⏭️ .env already exists; skipping.');
53510+
skipped += 1;
5351553511
}
5351653512
else {
5351753513
fs.copyFileSync(envSrc, envDst);
5351853514
(0, logger_1.logInfo)(' ✅ Copied setup/.env → .env');
5351953515
copied += 1;
5352053516
}
5352153517
}
53522-
return copied;
53518+
return { copied, skipped };
5352353519
}
5352453520

5352553521

build/github_action/src/data/repository/branch_repository.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export declare class BranchRepository {
3333
totalCommits: number;
3434
files: {
3535
filename: string;
36-
status: "modified" | "added" | "removed" | "renamed" | "copied" | "changed" | "unchanged";
36+
status: "added" | "removed" | "modified" | "renamed" | "copied" | "changed" | "unchanged";
3737
additions: number;
3838
deletions: number;
3939
changes: number;

build/github_action/src/utils/setup_files.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export declare function ensureGitHubDirs(cwd: string): void;
88
* Skips files that already exist at destination (no overwrite).
99
* Logs each file copied or skipped. No-op if setup/ does not exist.
1010
* @param cwd - Repo root
11-
* @returns Number of files copied
11+
* @returns { copied, skipped }
1212
*/
13-
export declare function copySetupFiles(cwd: string): number;
13+
export declare function copySetupFiles(cwd: string): {
14+
copied: number;
15+
skipped: number;
16+
};

src/actions/common_action.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import { PullRequestReviewCommentUseCase } from '../usecase/pull_request_review_
88
import { PullRequestUseCase } from '../usecase/pull_request_use_case';
99
import { SingleActionUseCase } from '../usecase/single_action_use_case';
1010
import { logError, logInfo } from '../utils/logger';
11-
import { ACTIONS, TITLE } from '../utils/constants';
11+
import { TITLE } from '../utils/constants';
1212
import chalk from 'chalk';
1313
import boxen from 'boxen';
1414
import { waitForPreviousRuns } from '../utils/queue_utils';
15-
import { copySetupFiles, ensureGitHubDirs } from '../utils/setup_files';
1615

1716
export async function mainRun(execution: Execution): Promise<Result[]> {
1817
const results: Result[] = []
@@ -64,18 +63,6 @@ export async function mainRun(execution: Execution): Promise<Result[]> {
6463
}
6564
)
6665
);
67-
if (execution.isSingleAction && execution.singleAction.currentSingleAction === ACTIONS.INITIAL_SETUP) {
68-
const cwd = process.cwd();
69-
logInfo('📁 Ensuring .github and .github/workflows exist...');
70-
ensureGitHubDirs(cwd);
71-
logInfo('📋 Copying setup files from setup/ to .github/ (skipping existing)...');
72-
const copied = copySetupFiles(cwd);
73-
if (copied > 0) {
74-
logInfo(`✅ Copied ${copied} file(s).`);
75-
} else {
76-
logInfo('ℹ️ No setup/ folder found or all files already exist; nothing to copy.');
77-
}
78-
}
7966
}
8067

8168
try {

src/usecase/actions/initial_setup_use_case.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ProjectRepository } from "../../data/repository/project_repository";
44
import { Result } from "../../data/model/result";
55
import { ParamUseCase } from "../base/param_usecase";
66
import { logError, logInfo } from "../../utils/logger";
7+
import { copySetupFiles, ensureGitHubDirs } from "../../utils/setup_files";
78

89
export class InitialSetupUseCase implements ParamUseCase<Execution, Result[]> {
910
taskId: string = 'InitialSetupUseCase';
@@ -16,6 +17,12 @@ export class InitialSetupUseCase implements ParamUseCase<Execution, Result[]> {
1617
const errors: string[] = [];
1718

1819
try {
20+
// 0. Setup files (.github/workflows, pull_request_template.md, .env)
21+
logInfo('📋 Ensuring .github and copying setup files...');
22+
ensureGitHubDirs(process.cwd());
23+
const filesResult = copySetupFiles(process.cwd());
24+
steps.push(`✅ Setup files: ${filesResult.copied} copied, ${filesResult.skipped} already existed`);
25+
1926
// 1. Verificar acceso a GitHub con Personal Access Token
2027
logInfo('🔐 Checking GitHub access...');
2128
const githubAccessResult = await this.verifyGitHubAccess(param);

src/utils/setup_files.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ export function ensureGitHubDirs(cwd: string): void {
2424
* Skips files that already exist at destination (no overwrite).
2525
* Logs each file copied or skipped. No-op if setup/ does not exist.
2626
* @param cwd - Repo root
27-
* @returns Number of files copied
27+
* @returns { copied, skipped }
2828
*/
29-
export function copySetupFiles(cwd: string): number {
29+
export function copySetupFiles(cwd: string): { copied: number; skipped: number } {
3030
const setupDir = path.join(cwd, 'setup');
31-
if (!fs.existsSync(setupDir)) return 0;
31+
if (!fs.existsSync(setupDir)) return { copied: 0, skipped: 0 };
3232

3333
let copied = 0;
34+
let skipped = 0;
3435
const workflowsSrc = path.join(setupDir, 'workflows');
3536
const workflowsDst = path.join(cwd, '.github', 'workflows');
3637
if (fs.existsSync(workflowsSrc)) {
@@ -41,6 +42,7 @@ export function copySetupFiles(cwd: string): number {
4142
if (fs.statSync(src).isFile()) {
4243
if (fs.existsSync(dst)) {
4344
logInfo(` ⏭️ .github/workflows/${f} already exists; skipping.`);
45+
skipped += 1;
4446
} else {
4547
fs.copyFileSync(src, dst);
4648
logInfo(` ✅ Copied setup/workflows/${f} → .github/workflows/${f}`);
@@ -54,6 +56,7 @@ export function copySetupFiles(cwd: string): number {
5456
if (fs.existsSync(prTemplateSrc)) {
5557
if (fs.existsSync(prTemplateDst)) {
5658
logInfo(' ⏭️ .github/pull_request_template.md already exists; skipping.');
59+
skipped += 1;
5760
} else {
5861
fs.copyFileSync(prTemplateSrc, prTemplateDst);
5962
logInfo(' ✅ Copied setup/pull_request_template.md → .github/pull_request_template.md');
@@ -65,11 +68,12 @@ export function copySetupFiles(cwd: string): number {
6568
if (fs.existsSync(envSrc) && fs.statSync(envSrc).isFile()) {
6669
if (fs.existsSync(envDst)) {
6770
logInfo(' ⏭️ .env already exists; skipping.');
71+
skipped += 1;
6872
} else {
6973
fs.copyFileSync(envSrc, envDst);
7074
logInfo(' ✅ Copied setup/.env → .env');
7175
copied += 1;
7276
}
7377
}
74-
return copied;
78+
return { copied, skipped };
7579
}

0 commit comments

Comments
 (0)