Skip to content

Commit

Permalink
fix: use last release md in webhooks (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianiy committed Nov 2, 2021
1 parent c5d536d commit c53e58d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/plugins/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CliParams } from 'commander/options';
import { TeamsWebhook } from './webhooks/teams';
import { Webhook } from './webhooks/webhook';
import inquirer from 'inquirer';
import path from 'path';
import fs from 'fs';

export class PluginLoader {
Expand Down Expand Up @@ -61,14 +62,26 @@ export class PluginLoader {
}

private _setFilePath(): void {
const { out, name, split, suffix } = this._configuration;
const { out, name, split } = this._configuration;
const outDir = split ? `${out}/release-notes` : out;
const fileName = split ? `${name}-${suffix}` : name;
const fileName = split ? this._getLatestFile(outDir!) : `${name}.md`;

if (!fs.existsSync(outDir!)) {
fs.mkdirSync(outDir!);
}

this._filePath = `${outDir}/${fileName}.md`;
this._filePath = `${outDir}/${fileName}`;
}

private _getLatestFile(outDir: string): string {
const files = fs.readdirSync(outDir);

const creationDates = files.map(file => ({
file,
creationTime: fs.statSync(path.join(outDir, file)).ctime.getTime(),
}));
const lastFile = creationDates.sort((a, b) => b.creationTime - a.creationTime)[0];

return lastFile.file;
}
}

0 comments on commit c53e58d

Please sign in to comment.