Skip to content

Commit 8295513

Browse files
CTY-gitplon-Susk7
andauthored
Generatediagram test (#1029)
* added patchflow to generate architecture * added readme * added tests to CI * add test app * fixes * bump version * fix copilot user unhanded in scm client * simplify and reduce context usagr * restrict to steps * fix title --------- Co-authored-by: priyash7 <[email protected]>
1 parent 22a3f2e commit 8295513

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
id: setup-python
7171
uses: actions/setup-python@v5
7272
with:
73-
python-version: '3.8'
73+
python-version: '3.9'
7474

7575
- name: Install Poetry
7676
uses: snok/install-poetry@v1
@@ -123,7 +123,7 @@ jobs:
123123
id: setup-python
124124
uses: actions/setup-python@v5
125125
with:
126-
python-version: '3.8'
126+
python-version: '3.9'
127127

128128
- name: Install Poetry
129129
uses: snok/install-poetry@v1
@@ -166,7 +166,7 @@ jobs:
166166
id: setup-python
167167
uses: actions/setup-python@v5
168168
with:
169-
python-version: '3.8'
169+
python-version: '3.9'
170170

171171
- name: Install Poetry
172172
uses: snok/install-poetry@v1
@@ -201,12 +201,13 @@ jobs:
201201
--github_api_key=${{ secrets.SCM_GITHUB_KEY }} \
202202
--base_path=tests/cicd/generate_docstring \
203203
--disable_telemetry
204-
204+
205205
- name : Generate Diagram
206206
run: |
207207
poetry run patchwork GenerateDiagram --log debug \
208208
--patched_api_key=${{ secrets.PATCHED_API_KEY }} \
209209
--github_api_key=${{ secrets.SCM_GITHUB_KEY }} \
210+
--folder_path=patchwork/steps \
210211
--disable_telemetry
211212
212213
- name: Generate UnitTests

patchwork/common/client/scm.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gitlab.const
1111
from attrs import define
1212
from github import Auth, Consts, Github, GithubException, PullRequest
13+
from github.GithubException import UnknownObjectException
1314
from gitlab import Gitlab, GitlabAuthenticationError, GitlabError
1415
from gitlab.v4.objects import ProjectMergeRequest
1516
from giturlparse import GitUrlParsed, parse
@@ -333,13 +334,20 @@ def reset_comments(self) -> None:
333334
comment.delete()
334335

335336
def texts(self) -> PullRequestTexts:
337+
comments = []
338+
for comment in chain(self._pr.get_review_comments(), self._pr.get_issue_comments()):
339+
try:
340+
# Copilot user throws here
341+
user = comment.user.name
342+
except UnknownObjectException:
343+
user = comment.user.login
344+
345+
comments.append(dict(user=user, body=comment.body))
346+
336347
return dict(
337348
title=self._pr.title or "",
338349
body=self._pr.body or "",
339-
comments=[
340-
dict(user=comment.user.name, body=comment.body)
341-
for comment in itertools.chain(self._pr.get_comments(), self._pr.get_issue_comments())
342-
],
350+
comments=comments,
343351
# None checks for binary files
344352
diffs={file.filename: file.patch for file in self._pr.get_files() if file.patch is not None},
345353
)

patchwork/patchflows/GenerateDiagram/GenerateDiagram.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,23 @@ def __init__(self, inputs):
2525
final_inputs.update(inputs)
2626

2727
final_inputs["prompt_id"] = "GenerateDiagram"
28-
if "folder_path" not in final_inputs.keys():
29-
final_inputs["folder_path"] = Path.cwd()
30-
else:
31-
final_inputs["folder_path"] = Path(final_inputs["folder_path"])
32-
33-
print(final_inputs["folder_path"])
3428

3529
if "prompt_template_file" not in final_inputs:
3630
final_inputs["prompt_template_file"] = _DEFAULT_PROMPT_JSON
3731

38-
final_inputs["pr_title"] = f"PatchWork System Architecture Diagram generated"
32+
final_inputs["pr_title"] = f"PatchWork System Architecture Diagram"
3933
final_inputs["branch_prefix"] = f"{self.__class__.__name__.lower()}-"
4034

4135
validate_steps_with_inputs(
4236
set(final_inputs.keys()).union({"prompt_values","files_to_patch"}), LLM, CallCode2Prompt,ModifyCode,PR
4337
)
38+
39+
self.base_path = final_inputs["base_path"]
4440
self.inputs = final_inputs
4541

4642
def run(self):
4743
outputs = CallCode2Prompt(self.inputs).run()
48-
new_file_name = f"diagram.md"
49-
new_file_path = Path(outputs['uri']).with_name(new_file_name)
50-
Path(outputs['uri']).rename(new_file_path)
51-
outputs['uri'] = str(new_file_path)
44+
outputs['uri'] = self.base_path
5245
self.inputs["response_partitions"] = {"patch": ["```", "\n", "```"]}
5346
self.inputs["files_to_patch"] = self.inputs["prompt_values"] = [outputs]
5447
outputs = LLM(self.inputs).run()

patchwork/patchflows/GenerateDiagram/defaults.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# model_top_p: 0.95
1111
# model_max_tokens: 2000
1212

13-
# folder_path : path/to/folder/with/class
14-
13+
base_path: diagram.md
14+
folder_path: .
1515
# CommitChanges Inputs
1616
disable_branch: false
1717

tests/common/test_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_default_list_option_callback(runner):
4848
== """\
4949
AutoFix
5050
DependencyUpgrade
51+
GenerateDiagram
5152
GenerateDocstring
5253
GenerateREADME
5354
GenerateUnitTests
@@ -66,6 +67,7 @@ def test_config_list_option_callback(runner, config_dir, patchflow_file):
6667
== f"""\
6768
AutoFix
6869
DependencyUpgrade
70+
GenerateDiagram
6971
GenerateDocstring
7072
GenerateREADME
7173
GenerateUnitTests

0 commit comments

Comments
 (0)