Skip to content

Commit

Permalink
fix: Updated script with logger
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmiravalir committed Aug 26, 2021
1 parent a262359 commit ec964c7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
19 changes: 10 additions & 9 deletions scripts/change-log-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChangeLogHelper {
}

async getAllReleaseVersionsFromGivenDate(date) {
this.logger.debug(`Started detecting the versions from the date: ${date}`);
this.logger.info(`Started detecting the versions from the date: ${date}`);
const versions = [];
const readLine = await this.getReadLiner(this.oaiChangelogFilename);
for await (const line of readLine) {
Expand All @@ -36,38 +36,38 @@ class ChangeLogHelper {
}
}
}
this.logger.debug(`Detected Versions: ${versions}`);
this.logger.info(`Detected Versions: ${versions}`);
return versions;
}

async getLatestChangelogGeneratedDate() {
this.logger.debug('Started detecting the latest date in cli core changelog');
this.logger.info('Started detecting the latest date in cli core changelog');
let latestDate;
const readLine = await this.getReadLiner(this.cliCoreChangelogFilename);
for await (const line of readLine) {
latestDate = this.dateRegex.exec(line);
if (latestDate) {
latestDate = latestDate[0];
this.logger.debug(`Detected the latest Date: ${latestDate}`);
this.logger.info(`Detected the latest Date: ${latestDate}`);
break;
}
}
return latestDate;
}

async getChangesAfterGivenDate(date) {
this.logger.debug(`Started getting the changelog from given date: ${date}`);
this.logger.info(`Started getting the changelog from given date: ${date}`);
let readLines = false;
let fileData = '';
const readLine = await this.getReadLiner(this.oaiChangelogFilename);
for await (const line of readLine) {
const currentDate = this.dateRegex.exec(line);
if (currentDate) {
if (currentDate[0] > date) {
this.logger.debug('Reading the lines');
this.logger.info('Reading the lines');
readLines = true;
} else {
this.logger.debug(`Changes from OpenAPI specs: ${fileData}`);
this.logger.info(`Changes from OpenAPI specs: ${fileData}`);
break;
}
} else if (readLines) {
Expand All @@ -78,13 +78,13 @@ class ChangeLogHelper {
}

async getAndAppendChangesToChangelog() {
this.logger.debug('Started getAndAppendChangesToChangelog');
this.logger.info('Started getAndAppendChangesToChangelog');
const latestDate = await this.getLatestChangelogGeneratedDate(); // changes.md
if (latestDate) {
const changeLog = await this.getChangesAfterGivenDate(latestDate); // oai_changes.md
if (changeLog) {
try {
this.logger.debug('Updating the CHANGES.md');
this.logger.info('Updating the CHANGES.md');
const data = fs.readFileSync(this.cliCoreChangelogFilename);
const fd = fs.openSync(this.cliCoreChangelogFilename, 'w+');
const insert = Buffer.from(changeLog);
Expand All @@ -93,6 +93,7 @@ class ChangeLogHelper {
fs.close(fd, (err) => {
if (err) throw err;
});
fs.writeFileSync('changeLog.md', changeLog);
} catch (error) {
this.logger.error(`Error while updating the changelog: ${error}`);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-version-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ const getVersionType = async () => {
return -1;
};
(async () => {
console.log(await getVersionType());
return getVersionType();
})();
6 changes: 4 additions & 2 deletions scripts/updateApiDefinitions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
echo "Copying api-definitions"
cp -R ~/oai_definitions/json/. src/services/twilio-api/
echo "Running update changelog script"
changeLog=$(node scripts/update-api-definitions.js)
node update-api-definitions.js
changeLog=$(cat changeLog.md)
rm -rf changeLog.md
if [ "$changeLog" != '' ]; then
changeLog="${changeLog//'%'/'%25'}"
changeLog="${changeLog//$'\n'/'%0A'}"
changeLog="${changeLog//$'\r'/'%0D'}"
fi
echo "Changelog: $changeLog"
versionType=$(node scripts/get-version-type.js)
versionType=$(node scripts/get-version-type.js | tail -n -1)
echo "Version type: $versionType"
rm -rf OAI_CHANGES.md
echo "Git configurations"
Expand Down

0 comments on commit ec964c7

Please sign in to comment.