This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathcommit.js
76 lines (62 loc) · 1.66 KB
/
commit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import moment from 'moment';
import Commit from '../../lib/models/commit';
import Author from '../../lib/models/author';
import {multiFilePatchBuilder} from './patch';
class CommitBuilder {
constructor() {
this._sha = '0123456789abcdefghij0123456789abcdefghij';
this._author = new Author('[email protected]', 'Tilde Ann Thurium');
this._authorDate = moment('2018-11-28T12:00:00', moment.ISO_8601).unix();
this._coAuthors = [];
this._messageSubject = 'subject';
this._messageBody = 'body';
this._multiFileDiff = null;
}
sha(newSha) {
this._sha = newSha;
return this;
}
addAuthor(newEmail, newName) {
this._author = new Author(newEmail, newName);
return this;
}
authorDate(timestamp) {
this._authorDate = timestamp;
return this;
}
messageSubject(subject) {
this._messageSubject = subject;
return this;
}
messageBody(body) {
this._messageBody = body;
return this;
}
setMultiFileDiff(block = () => {}) {
const builder = multiFilePatchBuilder();
block(builder);
this._multiFileDiff = builder.build().multiFilePatch;
return this;
}
addCoAuthor(email, name) {
this._coAuthors.push(new Author(email, name));
return this;
}
build() {
const commit = new Commit({
sha: this._sha,
author: this._author,
authorDate: this._authorDate,
coAuthors: this._coAuthors,
messageSubject: this._messageSubject,
messageBody: this._messageBody,
});
if (this._multiFileDiff !== null) {
commit.setMultiFileDiff(this._multiFileDiff);
}
return commit;
}
}
export function commitBuilder() {
return new CommitBuilder();
}