-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathchange.py
More file actions
60 lines (46 loc) · 1.29 KB
/
change.py
File metadata and controls
60 lines (46 loc) · 1.29 KB
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
from dataclasses import dataclass, field
from enum import Enum
class Action(Enum):
ADD = "add"
REMOVE = "remove"
class Result(Enum):
COMPLETED = "completed"
FAILED = "failed"
SKIPPED = "skipped"
@dataclass
class PackageAction:
action: Action
result: Result
package: str
def to_json(self):
return {
"action": self.action.value.upper(),
"result": self.result.value.upper(),
"package": self.package,
}
@dataclass
class Change:
lineNumber: int
description: str
properties: dict = field(default_factory=dict)
packageActions: list[PackageAction] = field(default_factory=list)
def to_json(self):
return {
# Not sure why this is a string but it's in the spec
"lineNumber": str(self.lineNumber),
"description": self.description,
"properties": self.properties,
"packageActions": [pa.to_json() for pa in self.packageActions],
}
@dataclass
class ChangeSet:
"""A set of changes made to a file at `path`"""
path: str
diff: str
changes: list[Change]
def to_json(self):
return {
"path": self.path,
"diff": self.diff,
"changes": [x.to_json() for x in self.changes],
}