@@ -48252,10 +48252,7 @@ class Execution {
4825248252 if (this.release.type === undefined) {
4825348253 return;
4825448254 }
48255- const lastTag = await branchRepository.getLatestTag();
48256- if (lastTag === undefined) {
48257- return;
48258- }
48255+ const lastTag = await branchRepository.getLatestTag() ?? version_utils_1.DEFAULT_BASE_VERSION;
4825948256 this.release.version = (0, version_utils_1.incrementVersion)(lastTag, this.release.type);
4826048257 }
4826148258 }
@@ -48269,10 +48266,7 @@ class Execution {
4826948266 this.hotfix.version = versionInfo.payload['hotfixVersion'];
4827048267 }
4827148268 else {
48272- this.hotfix.baseVersion = await branchRepository.getLatestTag();
48273- if (this.hotfix.baseVersion === undefined) {
48274- return;
48275- }
48269+ this.hotfix.baseVersion = await branchRepository.getLatestTag() ?? version_utils_1.DEFAULT_BASE_VERSION;
4827648270 this.hotfix.version = (0, version_utils_1.incrementVersion)(this.hotfix.baseVersion, 'Patch');
4827748271 }
4827848272 this.hotfix.branch = `${this.branches.hotfixTree}/${this.hotfix.version}`;
@@ -50413,6 +50407,7 @@ class IssueRepository {
5041350407 }
5041450408 const sanitizedTitle = issueTitle
5041550409 .replace(/\b\d+(\.\d+){2,}\b/g, '')
50410+ .replace(/\bUnknown Version\b/gi, '')
5041650411 .replace(/[^\p{L}\p{N}\p{P}\p{Z}^$\n]/gu, '')
5041750412 .replace(/\u200D/g, '')
5041850413 .replace(/[^\S\r\n]+/g, ' ')
@@ -52164,6 +52159,19 @@ class ProjectRepository {
5216452159 return undefined;
5216552160 }
5216652161 };
52162+ this.getDefaultBranch = async (owner, repo, token) => {
52163+ try {
52164+ const octokit = github.getOctokit(token);
52165+ const { data } = await octokit.rest.repos.get({ owner, repo });
52166+ const branch = data.default_branch;
52167+ (0, logger_1.logDebugInfo)(`Default branch for ${owner}/${repo}: ${branch}`);
52168+ return branch;
52169+ }
52170+ catch (error) {
52171+ (0, logger_1.logError)(`Error getting default branch for ${owner}/${repo}: ${error}`);
52172+ return undefined;
52173+ }
52174+ };
5216752175 this.createTag = async (owner, repo, branch, tag, token) => {
5216852176 const octokit = github.getOctokit(token);
5216952177 try {
@@ -54189,9 +54197,11 @@ exports.DeployedActionUseCase = DeployedActionUseCase;
5418954197
5419054198Object.defineProperty(exports, "__esModule", ({ value: true }));
5419154199exports.InitialSetupUseCase = void 0;
54200+ const branch_repository_1 = __nccwpck_require__(7701);
5419254201const issue_repository_1 = __nccwpck_require__(57);
5419354202const project_repository_1 = __nccwpck_require__(7917);
5419454203const result_1 = __nccwpck_require__(7305);
54204+ const version_utils_1 = __nccwpck_require__(9887);
5419554205const logger_1 = __nccwpck_require__(8836);
5419654206const task_emoji_1 = __nccwpck_require__(9785);
5419754207const setup_files_1 = __nccwpck_require__(1666);
@@ -54266,6 +54276,14 @@ class InitialSetupUseCase {
5426654276 else {
5426754277 steps.push(`✅ Issue types checked: ${issueTypesResult.created} created, ${issueTypesResult.existing} already existed`);
5426854278 }
54279+ // 4. Si no hay tags en el repo, crear versión por defecto v1.0.0
54280+ const defaultVersionResult = await this.ensureDefaultVersion(param);
54281+ if (defaultVersionResult.step) {
54282+ steps.push(defaultVersionResult.step);
54283+ }
54284+ if (defaultVersionResult.error) {
54285+ errors.push(defaultVersionResult.error);
54286+ }
5426954287 results.push(new result_1.Result({
5427054288 id: this.taskId,
5427154289 success: errors.length === 0,
@@ -54342,6 +54360,39 @@ class InitialSetupUseCase {
5434254360 return { success: false, created: 0, existing: 0, errors: [`Error asegurando tipos de Issue: ${error}`] };
5434354361 }
5434454362 }
54363+ /**
54364+ * If the repository has no version tags, create default tag v1.0.0 on the default branch.
54365+ * Used by "copilot setup" so release/hotfix issues get a base version.
54366+ */
54367+ async ensureDefaultVersion(param) {
54368+ try {
54369+ const branchRepository = new branch_repository_1.BranchRepository();
54370+ const existingTag = await branchRepository.getLatestTag();
54371+ if (existingTag !== undefined) {
54372+ (0, logger_1.logDebugInfo)(`Repository already has version tags (latest: ${existingTag}). Skipping default tag.`);
54373+ return {};
54374+ }
54375+ (0, logger_1.logInfo)(`🏷️ No version tags found. Creating default tag ${version_utils_1.DEFAULT_INITIAL_TAG}...`);
54376+ const projectRepository = new project_repository_1.ProjectRepository();
54377+ const defaultBranch = await projectRepository.getDefaultBranch(param.owner, param.repo, param.tokens.token);
54378+ if (!defaultBranch) {
54379+ const msg = 'Could not get default branch to create initial version tag.';
54380+ (0, logger_1.logError)(msg);
54381+ return { error: msg };
54382+ }
54383+ const sha = await projectRepository.createTag(param.owner, param.repo, defaultBranch, version_utils_1.DEFAULT_INITIAL_TAG, param.tokens.token);
54384+ if (sha) {
54385+ const step = `✅ Default version tag ${version_utils_1.DEFAULT_INITIAL_TAG} created on branch ${defaultBranch}. Run \`git fetch --tags\` to update local refs.`;
54386+ return { step };
54387+ }
54388+ return { error: `Failed to create tag ${version_utils_1.DEFAULT_INITIAL_TAG} on ${param.owner}/${param.repo}` };
54389+ }
54390+ catch (error) {
54391+ const msg = `Error ensuring default version: ${error}`;
54392+ (0, logger_1.logError)(msg);
54393+ return { error: msg };
54394+ }
54395+ }
5434554396}
5434654397exports.InitialSetupUseCase = InitialSetupUseCase;
5434754398
@@ -57720,10 +57771,10 @@ class UpdateTitleUseCase {
5772057771 const _title = await this.issueRepository.getTitle(param.owner, param.repo, param.issue.number, param.tokens.token) ?? param.issue.title;
5772157772 let _version = '';
5772257773 if (param.release.active) {
57723- _version = param.release.version ?? 'Unknown Version ';
57774+ _version = param.release.version ?? '';
5772457775 }
5772557776 else if (param.hotfix.active) {
57726- _version = param.hotfix.version ?? 'Unknown Version ';
57777+ _version = param.hotfix.version ?? '';
5772757778 }
5772857779 const title = await this.issueRepository.updateTitleIssueFormat(param.owner, param.repo, _version, _title, param.issue.number, param.issue.branchManagementAlways, param.emoji.branchManagementEmoji, param.labels, param.tokens.token);
5772957780 if (title) {
@@ -61018,8 +61069,12 @@ exports.extractIssueNumberFromPush = extractIssueNumberFromPush;
6101861069"use strict";
6101961070
6102061071Object.defineProperty(exports, "__esModule", ({ value: true }));
61021- exports.getLatestVersion = exports.incrementVersion = void 0;
61072+ exports.getLatestVersion = exports.incrementVersion = exports.DEFAULT_INITIAL_TAG = exports.DEFAULT_BASE_VERSION = void 0;
6102261073const logger_1 = __nccwpck_require__(8836);
61074+ /** Default base version when the repository has no existing tags (e.g. new repo). */
61075+ exports.DEFAULT_BASE_VERSION = '1.0.0';
61076+ /** Default initial tag name (with "v" prefix) for repos with no tags. Used by setup. */
61077+ exports.DEFAULT_INITIAL_TAG = `v${exports.DEFAULT_BASE_VERSION}`;
6102361078const incrementVersion = (version, releaseType) => {
6102461079 (0, logger_1.logDebugInfo)(`Incrementing version ${version}.`);
6102561080 const versionParts = version.split('.').map(Number);
0 commit comments