File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,3 +43,12 @@ export class InvalidManifestError extends CustomError {
4343 super ( message , 'InvalidManifestError' ) ;
4444 }
4545}
46+
47+ /**
48+ * Error thrown when the changelog file is not found.
49+ */
50+ export class ChangelogFileNotFoundError extends CustomError {
51+ constructor ( message : string ) {
52+ super ( message , 'ChangelogFileNotFoundError' ) ;
53+ }
54+ }
Original file line number Diff line number Diff line change 11import { FileHandler } from '../utils/fileHandler' ;
22import { GitService } from './gitService' ;
33import * as core from '@actions/core' ;
4+ import { FileNotFoundError } from '../errors' ;
45
56/**
67 * Service for managing the changelog file.
@@ -50,7 +51,18 @@ export class ChangelogService {
5051 */
5152 async updateChangelog ( changelogContent : string ) : Promise < void > {
5253 const changelogPath = this . _getChangelogPath ( ) ;
53- const existingChangelog = await this . fileHandler . readFile ( changelogPath ) ;
54+ let existingChangelog : string ;
55+ try {
56+ existingChangelog = await this . fileHandler . readFile ( changelogPath ) ;
57+ } catch ( error : any ) {
58+ if ( error . code === 'ENOENT' ) {
59+ throw new FileNotFoundError (
60+ `Changelog file not found at ${ changelogPath } ` ,
61+ ) ;
62+ }
63+ throw error ;
64+ }
65+
5466 const versionMatch = changelogContent . match ( / # # v ( \d + \. \d + \. \d + ) / ) ;
5567 if ( versionMatch ) {
5668 const newVersion = versionMatch [ 0 ] ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ChangelogService } from '../../src/services/changelogService';
33import { FileHandler } from '../../src/utils/fileHandler' ;
44import { GitService } from '../../src/services/gitService' ;
55import * as core from '@actions/core' ;
6+ import { FileNotFoundError } from '../../src/errors' ;
67
78vi . mock ( '@actions/exec' ) ;
89vi . mock ( '../../src/utils/fileHandler' ) ;
@@ -65,4 +66,15 @@ describe('ChangelogService', () => {
6566 'Changelog for version ## v1.1.0 already exists. Skipping.' ,
6667 ) ;
6768 } ) ;
69+
70+ it ( 'should throw FileNotFoundError if changelog file does not exist' , async ( ) => {
71+ const changelogPath = 'CHANGELOG.md' ;
72+ const error = new Error ( 'File not found' ) as any ;
73+ error . code = 'ENOENT' ;
74+ vi . spyOn ( fileHandler , 'readFile' ) . mockRejectedValue ( error ) ;
75+
76+ await expect ( changelogService . updateChangelog ( '## v1.1.0\n\n- New feature' ) ) . rejects . toThrow (
77+ new FileNotFoundError ( `Changelog file not found at ${ changelogPath } ` ) ,
78+ ) ;
79+ } ) ;
6880} ) ;
You can’t perform that action at this time.
0 commit comments