-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (47 loc) · 1.05 KB
/
index.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
const diff = require('diff')
module.exports = class Patch {
constructor (options = {}) {
Object.assign(this, options)
}
static fromUnidiff (unidiff) {
const patches = diff.parsePatch(unidiff)
if (patches.length > 1) {
throw new Error('Only one one patch per file is currently supported')
}
patches[0].oldRelativeFilePath = patches[0].oldFileName
delete patches[0].oldFileName
patches[0].newRelativeFilePath = patches[0].newFileName
delete patches[0].newFileName
patches[0].type = 'unidiff-object'
return new Patch(patches[0])
}
get unidiff () {
}
get object () {
const {
type,
oldHeader,
oldRelativeFilePath,
newHeader,
newRelativeFilePath,
hunks,
} = this
return {
type,
oldHeader,
oldRelativeFilePath,
newHeader,
newRelativeFilePath,
hunks,
}
}
toJSON () {
return this.object
}
get string () {
return `${this.type} to fix ${this.relativeFilePath}`
}
toString () {
return this.string
}
}