-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get regular expression from a command flag instead of a file
- Loading branch information
Showing
8 changed files
with
35 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
'use strict' | ||
'use strict'; | ||
import { execSync } from 'node:child_process'; | ||
import * as fs from 'node:fs'; | ||
|
||
export function retrieveCommitMessages(fromCommit: string, toCommit: string, regexFilePath: string): string[] { | ||
const gitLogCommand = `git log --format=%s ${fromCommit}..${toCommit}`; | ||
let commitMessages: string; | ||
try { | ||
commitMessages = execSync(gitLogCommand, { encoding: 'utf-8' }); | ||
} catch (err) { | ||
throw Error('The git diff failed to run due to the above error.'); | ||
} | ||
export function retrieveCommitMessages(fromCommit: string, toCommit: string, regexPattern: string): string[] { | ||
const gitLogCommand = `git log --format=%s ${fromCommit}..${toCommit}`; | ||
let commitMessages: string; | ||
try { | ||
commitMessages = execSync(gitLogCommand, { encoding: 'utf-8' }); | ||
} catch (err) { | ||
throw Error('The git diff failed to run due to the above error.'); | ||
} | ||
|
||
let regexPattern = ''; | ||
try { | ||
regexPattern = fs.readFileSync(regexFilePath, 'utf-8').trim(); | ||
} catch (err) { | ||
throw Error(`The regular expression was unable to be extracted from ${regexFilePath}`); | ||
} | ||
let regex: RegExp; | ||
try { | ||
regex = new RegExp(regexPattern, 'g'); | ||
} catch (err) { | ||
throw Error(`The regular expression '${regexPattern}' is invalid.`); | ||
} | ||
|
||
const regex = new RegExp(regexPattern, 'g'); | ||
const matchedMessages: string[] = []; | ||
let match; | ||
while ((match = regex.exec(commitMessages)) !== null) { | ||
if (match[1]) { | ||
matchedMessages.push(match[1]); | ||
} | ||
const matchedMessages: string[] = []; | ||
let match; | ||
while ((match = regex.exec(commitMessages)) !== null) { | ||
if (match[1]) { | ||
matchedMessages.push(match[1]); | ||
} | ||
} | ||
|
||
return matchedMessages; | ||
return matchedMessages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters