MCPcopy Create free account
hub / github.com/angular/dev-infra / RenderContext

Class RenderContext

ng-dev/release/notes/context.ts:49–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48/** Context class used for rendering release notes. */
49export class RenderContext {
50 /** An array of group names in sort order if defined. */
51 private readonly groupOrder = this.data.groupOrder || [];
52 /** An array of scopes to hide from the release entry output. */
53 private readonly hiddenScopes = this.data.hiddenScopes || [];
54 /** The title of the release, or `false` if no title should be used. */
55 readonly title = this.data.title;
56 /** The version of the release. */
57 readonly version = this.data.version;
58 /** The date stamp string for use in the release notes entry. */
59 readonly dateStamp = buildDateStamp(this.data.date);
60 /** URL fragment that is used to create an anchor for the release. */
61 readonly urlFragmentForRelease = this.data.version;
62 /** List of categorized commits in the release period. */
63 readonly commits = this._categorizeCommits(this.data.commits);
64
65 constructor(private readonly data: RenderContextData) {}
66
67 /** Gets a list of categorized commits from all commits in the release period. */
68 _categorizeCommits(commits: CommitFromGitLog[]): CategorizedCommit[] {
69 return commits.map((commit) => {
70 const {description, groupName} = this.data.categorizeCommit?.(commit) ?? {};
71 const escapedBreakingChanges = commit.breakingChanges.map((bc) => ({
72 ...bc,
73 text: escapeHtml(bc.text),
74 }));
75 const escapedDeprecations = commit.deprecations.map((dep) => ({
76 ...dep,
77 text: escapeHtml(dep.text),
78 }));
79 return {
80 ...commit,
81 type: escapeHtml(commit.type),
82 groupName: escapeHtml(groupName ?? commit.scope),
83 description: escapeHtml(description ?? commit.subject),
84 breakingChanges: escapedBreakingChanges,
85 deprecations: escapedDeprecations,
86 };
87 });
88 }
89
90 /**
91 * Comparator used for sorting commits within a release notes group. Commits
92 * are sorted alphabetically based on their type. Commits having the same type
93 * will be sorted alphabetically based on their determined description
94 */
95 private _commitsWithinGroupComparator = (a: CategorizedCommit, b: CategorizedCommit): number => {
96 const typeCompareOrder = compareString(a.type, b.type);
97 if (typeCompareOrder === 0) {
98 return compareString(a.description, b.description);
99 }
100 return typeCompareOrder;
101 };
102
103 /**
104 * Organizes and sorts the commits into groups of commits.
105 *
106 * Groups are sorted either by default `Array.sort` order, or using the provided group order from

Callers

nothing calls this directly

Calls 9

_categorizeCommitsMethod · 0.95
buildDateStampFunction · 0.85
compareStringFunction · 0.85
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
entriesMethod · 0.45
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected