Skip to content

Commit dc896d4

Browse files
authored
Merge pull request #343 from DataRecce/bug/fetch_repo_in_the_cloud_mode
[Bug] Should get the repository name from the ci event object
2 parents 6f92730 + fc36da9 commit dc896d4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

recce/pull_request.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def fetch_pr_metadata(**kwargs):
1818
pr_info.id = metadata.get('github_pr_id')
1919
pr_info.url = metadata.get('github_pr_url')
2020
pr_info.title = metadata.get('github_pr_title')
21+
pr_info.repository = metadata.get('github_repository')
2122
else:
2223
repo = hosting_repo()
2324
pr = recce_pr_information(github_token=kwargs.get('github_token'))
@@ -53,15 +54,17 @@ def fetch_pr_metadata_from_event_path() -> Optional[dict]:
5354
Example:
5455
{
5556
"github_pr_id": 1,
56-
"github_pr_url": "https://github.com/xyz/abc/pull/1
57-
"github_pr_title": "Update README.md"
57+
"github_pr_url": "https://github.com/xyz/abc/pull/1,
58+
"github_pr_title": "Update README.md",
59+
"github_repository": "xyz/abc"
5860
}
5961
6062
:return: dict
6163
"""
6264

6365
# get the event json from the path in GITHUB_EVENT_PATH
6466
event_path = os.getenv("GITHUB_EVENT_PATH")
67+
github_repository = os.getenv("GITHUB_REPOSITORY")
6568
if event_path:
6669
try:
6770
with open(event_path, "r") as event_file:
@@ -73,7 +76,10 @@ def fetch_pr_metadata_from_event_path() -> Optional[dict]:
7376
pr_url = pull_request_data["_links"]["html"]["href"]
7477
pr_api = pull_request_data["_links"]["self"]["href"]
7578
pr_title = _fetch_pr_title(pr_api)
76-
return dict(github_pr_id=pr_id, github_pr_url=pr_url, github_pr_title=pr_title)
79+
return dict(github_pr_id=pr_id,
80+
github_pr_url=pr_url,
81+
github_pr_title=pr_title,
82+
github_repository=github_repository)
7783
else:
7884
print("Not a pull request event, skip.")
7985
except Exception as e:

tests/test_pull_request.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def mock_github_event(tmp_path, monkeypatch):
2323
json.dump(event_data, f)
2424

2525
monkeypatch.setenv("GITHUB_EVENT_PATH", str(event_file))
26+
monkeypatch.setenv("GITHUB_REPOSITORY", "abc/xyz")
2627

2728

2829
@pytest.fixture
@@ -62,6 +63,7 @@ def test_fetch_pr_metadata(mock_github_event, mock_github_token, mock_get_reques
6263
assert result["github_pr_id"] == 1
6364
assert result["github_pr_url"] == "https://github.com/xyz/abc/pull/1"
6465
assert result["github_pr_title"] == "Update README.md"
66+
assert result["github_repository"] == "abc/xyz"
6567

6668

6769
def test_fetch_pr_metadata_no_event(mock_get_request_success, monkeypatch):

0 commit comments

Comments
 (0)