Skip to content

Commit

Permalink
Add package action to change
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 24, 2023
1 parent dbe622c commit 6fed1c0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/codemodder/change.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
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,
"result": self.result.value,
"package": self.package,
}


@dataclass
class Change:
lineNumber: int
description: str
properties: dict = field(default_factory=dict)
packageActions: list = field(default_factory=list)
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": self.packageActions,
"packageActions": [pa.to_json() for pa in self.packageActions],
}


Expand Down
5 changes: 4 additions & 1 deletion src/codemodder/dependency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import difflib
from packaging.requirements import Requirement

from codemodder.change import Change, ChangeSet
from codemodder.change import Action, Change, ChangeSet, PackageAction, Result
from codemodder.dependency import Dependency


Expand Down Expand Up @@ -48,6 +48,9 @@ def write(self, dry_run: bool = False) -> Optional[ChangeSet]:
lineNumber=len(self._lines) + i + 1,
description=dep.build_description(),
properties={"contextual_description": True},
packageActions=[
PackageAction(Action.ADD, Result.COMPLETED, str(dep.requirement))
],
)
for i, dep in enumerate(self._new_requirements)
]
Expand Down

0 comments on commit 6fed1c0

Please sign in to comment.