mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-14 11:14:45 +00:00
Rewrite/refactor for v5, migrate to TypeScript (MAJOR)
Set Jest config file in package script Include module path Include tests in project folders Remove index module exports Hardcode configuration parameters Move parameter binding into main run function Use alias imports Run test sequentially Remove cleanup (async conflict) Revert Jest option Increase test timeout to 15 seconds
This commit is contained in:
parent
dc8f0c5755
commit
31f4e3fdf0
74 changed files with 9422 additions and 4342 deletions
67
src/action.ts
Normal file
67
src/action.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { ConfigurationProvider } from './ConfigurationProvider';
|
||||
import { VersionResult } from './VersionResult';
|
||||
import { VersionType } from './providers/VersionType';
|
||||
import { UserInfo } from './providers/UserInfo';
|
||||
import { VersionInformation } from './providers/VersionInformation';
|
||||
|
||||
export async function runAction(configurationProvider: ConfigurationProvider): Promise<VersionResult> {
|
||||
|
||||
const currentCommitResolver = configurationProvider.GetCurrentCommitResolver();
|
||||
const lastReleaseResolver = configurationProvider.GetLastReleaseResolver();
|
||||
const commitsProvider = configurationProvider.GetCommitsProvider();
|
||||
const versionClassifier = configurationProvider.GetVersionClassifier();
|
||||
const versionFormatter = configurationProvider.GetVersionFormatter();
|
||||
const tagFormmater = configurationProvider.GetTagFormatter();
|
||||
const userFormatter = configurationProvider.GetUserFormatter();
|
||||
|
||||
if (await currentCommitResolver.IsEmptyRepoAsync()) {
|
||||
let versionInfo = new VersionInformation(0, 0, 0, 0, VersionType.None, [], false);
|
||||
return new VersionResult(
|
||||
versionInfo.major,
|
||||
versionInfo.minor,
|
||||
versionInfo.patch,
|
||||
versionInfo.increment,
|
||||
versionFormatter.Format(versionInfo),
|
||||
tagFormmater.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
userFormatter.Format('author', []),
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
const currentCommit = await currentCommitResolver.ResolveAsync();
|
||||
const lastRelease = await lastReleaseResolver.ResolveAsync(currentCommit, tagFormmater);
|
||||
const commitSet = await commitsProvider.GetCommitsAsync(lastRelease.hash, currentCommit);
|
||||
const classification = await versionClassifier.ClassifyAsync(lastRelease, commitSet);
|
||||
|
||||
const { major, minor, patch, increment, type, changed } = classification;
|
||||
|
||||
// At this point all necessary data has been pulled from the database, create
|
||||
// version information to be used by the formatters
|
||||
let versionInfo = new VersionInformation(major, minor, patch, increment, type, commitSet.commits, changed);
|
||||
|
||||
// Group all the authors together, count the number of commits per author
|
||||
const allAuthors = versionInfo.commits
|
||||
.reduce((acc: any, commit) => {
|
||||
const key = `${commit.author} <${commit.authorEmail}>`;
|
||||
acc[key] = acc[key] || { n: commit.author, e: commit.authorEmail, c: 0 };
|
||||
acc[key].c++;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const authors = Object.values(allAuthors)
|
||||
.map((u: any) => new UserInfo(u.n, u.e, u.c))
|
||||
.sort((a: UserInfo, b: UserInfo) => b.commits - a.commits);
|
||||
|
||||
return new VersionResult(
|
||||
versionInfo.major,
|
||||
versionInfo.minor,
|
||||
versionInfo.patch,
|
||||
versionInfo.increment,
|
||||
versionFormatter.Format(versionInfo),
|
||||
tagFormmater.Format(versionInfo),
|
||||
versionInfo.changed,
|
||||
userFormatter.Format('author', authors),
|
||||
currentCommit
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue