MCPcopy Index your code
hub / github.com/faker-js/faker / commitEntry

Method commitEntry

src/modules/git/index.ts:47–111  ·  view source on GitHub ↗

* Generates a random commit entry as printed by `git log`. * * @param options Options for the commit entry. * @param options.merge Whether to generate a merge message line. Defaults to 20% `true` and 80% `false`. * @param options.eol Choose the end of line character to use. Defaults to `

(
    options: {
      /**
       * Set to `true` to generate a merge message line.
       *
       * @default faker.datatype.boolean({ probability: 0.2 })
       */
      merge?: boolean;
      /**
       * Choose the end of line character to use.
       *
       * - 'LF' = '\n',
       * - 'CRLF' = '\r\n'
       *
       * @default 'CRLF'
       */
      eol?: 'LF' | 'CRLF';
      /**
       * The date to use as reference point for the commit.
       *
       * @default new Date()
       */
      refDate?: string | Date | number;
    } = {}
  )

Source from the content-addressed store, hash-verified

45 * @since 5.0.0
46 */
47 commitEntry(
48 options: {
49 /**
50 * Set to `true` to generate a merge message line.
51 *
52 * @default faker.datatype.boolean({ probability: 0.2 })
53 */
54 merge?: boolean;
55 /**
56 * Choose the end of line character to use.
57 *
58 * - 'LF' = '\n',
59 * - 'CRLF' = '\r\n'
60 *
61 * @default 'CRLF'
62 */
63 eol?: 'LF' | 'CRLF';
64 /**
65 * The date to use as reference point for the commit.
66 *
67 * @default new Date()
68 */
69 refDate?: string | Date | number;
70 } = {}
71 ): string {
72 const {
73 merge = this.faker.datatype.boolean({ probability: 0.2 }),
74 eol = 'CRLF',
75 refDate,
76 } = options;
77
78 const lines = [`commit ${this.faker.git.commitSha()}`];
79
80 if (merge) {
81 lines.push(
82 `Merge: ${this.commitSha({ length: 7 })} ${this.commitSha({
83 length: 7,
84 })}`
85 );
86 }
87
88 const firstName = this.faker.person.firstName();
89 const lastName = this.faker.person.lastName();
90 const fullName = this.faker.person.fullName({ firstName, lastName });
91 const username = this.faker.internet.username({ firstName, lastName });
92 let user = this.faker.helpers.arrayElement([fullName, username]);
93 const email = this.faker.internet.email({ firstName, lastName });
94
95 // Normalize user according to https://github.com/libgit2/libgit2/issues/5342
96 user = user.replaceAll(/^[.,:;"\\']|[<>\n]|[.,:;"\\']$/g, '');
97
98 lines.push(
99 `Author: ${user} <${email}>`,
100 `Date: ${this.commitDate({ refDate })}`,
101 '',
102 `${nbsp.repeat(4)}${this.commitMessage()}`,
103 // to end with a eol char
104 ''

Callers 1

git.spec.tsFile · 0.80

Calls 10

commitShaMethod · 0.95
commitDateMethod · 0.95
commitMessageMethod · 0.95
booleanMethod · 0.80
firstNameMethod · 0.80
lastNameMethod · 0.80
fullNameMethod · 0.80
usernameMethod · 0.80
arrayElementMethod · 0.80
emailMethod · 0.80

Tested by

no test coverage detected