Skip to content

Commit 09d7c25

Browse files
committed
test: add integratin test of issue and json creation
1 parent 63cb7b3 commit 09d7c25

5 files changed

Lines changed: 47 additions & 23 deletions

File tree

pytest.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
addopts = -m "not manual"
44
markers =
55
manual: marks tests that should only run when manually triggered
6-
asyncio_mode = auto
6+
asyncio_mode = auto
7+
env_files =
8+
.env

src/application/services/integration/disambiguation/disambiguator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ async def process_conflict(key, conflict, instances_dict):
104104
else:
105105
## conflict file creation
106106
content, filename = generate_conflict_file(conflict, key)
107-
conflict_url = commit_conflict_json(content, filename)
107+
path = f"human_annotations/conflicts/{filename}"
108+
conflict_url = commit_conflict_json(content, path)
108109

109110
## issue creation
110111
context = generate_context(key, full_conflict, conflict_url)

src/application/services/integration/disambiguation/github_issue.jinja2

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
A conflict has been detected between two software metadata entries with the same name but no shared repository or website. Please review the metadata and provide your decision using the format below.
44

5-
**Annotation Guidelines**: refer to the [annotation guidelines](https://link-to-guidelines.example.com) if needed.
5+
**Annotation Guidelines**: refer to the [annotation guidelines](https://link-to-guidelines.example.com) if needed.
6+
7+
**Conflict** (for reference): [{{conflict_url}}]({{conflict_url}})
68

79
---
810

@@ -52,10 +54,6 @@ Use the **exact format shown** in a single comment, replacing the values as need
5254
}
5355
```
5456

55-
### Conflict annotation
56-
57-
- JSON file: [{{conflict_url}}]({{conflict_url}})
58-
5957
---
6058

6159
Thank you! Your annotation will be automatically ingested and logged.

src/application/services/integration/disambiguation/issues.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
GITHUB_API = "https://api.github.com"
1313
BRANCH = "main"
1414

15-
def commit_conflict_json(conflict: dict, filename: str) -> str:
15+
def commit_conflict_json(conflict: dict, path: str, branch=BRANCH, repo=REPO) -> str:
1616
"""
1717
Commit a conflict JSON file to human_annotations/conflicts/.
1818
@@ -23,19 +23,18 @@ def commit_conflict_json(conflict: dict, filename: str) -> str:
2323
Returns:
2424
str: GitHub URL to the committed file
2525
"""
26-
path = f"human_annotations/conflicts/{filename}"
27-
url = f"{GITHUB_API}/repos/{REPO}/contents/{path}"
26+
27+
url = f"{GITHUB_API}/repos/{repo}/contents/{path}"
2828

2929
# prepare content
3030
content = json.dumps(conflict, indent=2, sort_keys=True)
3131
encoded = base64.b64encode(content.encode("utf-8")).decode("utf-8")
3232

3333
payload = {
34-
"message": f"Add conflict annotation: {filename}",
34+
"message": f"Add conflict annotation: {path}",
3535
"content": encoded,
36-
"branch": BRANCH,
36+
"branch": branch,
3737
}
38-
3938
headers = {
4039
"Authorization": f"Bearer {GITHUB_TOKEN}",
4140
"Accept": "application/vnd.github+json",
@@ -259,7 +258,7 @@ def generate_conflict_file(conflict, conflict_name):
259258

260259

261260

262-
def create_github_issue(title, body, labels=None):
261+
def create_github_issue(title, body, labels=None, repo=REPO):
263262
"""
264263
Create a GitHub issue and commit associated conflict JSON.
265264
@@ -281,7 +280,7 @@ def create_github_issue(title, body, labels=None):
281280

282281
print(f"Making Github issue ... ")
283282

284-
url = f"{GITHUB_API}/repos/{REPO}/issues"
283+
url = f"{GITHUB_API}/repos/{repo}/issues"
285284
headers = {
286285
"Authorization": f"Bearer {GITHUB_TOKEN}",
287286
"Accept": "application/vnd.github+json",

tests/application/services/integration/test_github_issue.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
22
import random
33
import pytest
4+
import uuid
5+
46
from pprint import pprint
5-
from src.application.services.integration.disambiguation.issues import generate_context, generate_conflict_file, generate_github_body, stable_hash
7+
from src.application.services.integration.disambiguation.issues import generate_context, generate_conflict_file, commit_conflict_json, generate_github_body, stable_hash, create_github_issue
68

79

810
full_conflict ={
@@ -364,7 +366,8 @@ def test_stable_hash_list_order_matters_by_default():
364366
# --------------------------------------------------------------------------------
365367

366368
def test_generate_conflict_file():
367-
# This function requires "conflict" and "conflict name". conflict is the original conflict, without any processing
369+
# The function "generate_conflict_file" requires "conflict" and "conflict name" as arguments.
370+
# "conflict" is the full conflict, without any processing
368371
conflict_name = "ale/cmd"
369372

370373
content, filename = generate_conflict_file(full_conflict, conflict_name)
@@ -374,12 +377,33 @@ def test_generate_conflict_file():
374377

375378
assert "ale/cmd_" in filename
376379
assert type(content) == dict
377-
378380

379381

380-
# Push issue
381-
## In a test branch
382+
# --------------- Full Integration Test --------------------------------------------
383+
#
384+
# Run with: PYTHONPATH=$(pwd) pytest -v -s -m manual tests/application/services/integration/test_github_issue.py
385+
#
386+
# It creates an issue and adds the conflict file to https://github.com/EvaMart/test-integrations/
387+
388+
@pytest.mark.manual
389+
def test_create_github_issue():
390+
# Push issue
391+
conflict_name = "ale/cmd"
392+
REPO = 'EvaMart/test-integrations'
393+
GITHUB_API = "https://api.github.com"
394+
# -------- generating URL --------
395+
content, filename = generate_conflict_file(full_conflict, conflict_name)
396+
397+
random_suffix = uuid.uuid4().hex
398+
filename = f"human_annotations/conflicts/test_{random_suffix}.json"
399+
400+
conflict_url = commit_conflict_json(content, filename, 'main', REPO)
401+
context = generate_context(conflict_name, full_conflict, conflict_url)
402+
body = generate_github_body(context)
403+
404+
title = f"Manual resolution needed for {conflict_name}"
405+
labels = ['test']
406+
repo = 'evamart/test-integrations'
407+
response = create_github_issue(title, body, labels, repo)
408+
382409

383-
# commit JSON file -> This requires making changes to the code
384-
## commit to a test branch
385-
## assert the URL is correct

0 commit comments

Comments
 (0)