Skip to content

Commit

Permalink
Merge pull request #343 from DataRecce/bug/fetch_repo_in_the_cloud_mode
Browse files Browse the repository at this point in the history
[Bug] Should get the repository name from the ci event object
  • Loading branch information
popcornylu authored Jun 17, 2024
2 parents 6f92730 + fc36da9 commit dc896d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions recce/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def fetch_pr_metadata(**kwargs):
pr_info.id = metadata.get('github_pr_id')
pr_info.url = metadata.get('github_pr_url')
pr_info.title = metadata.get('github_pr_title')
pr_info.repository = metadata.get('github_repository')
else:
repo = hosting_repo()
pr = recce_pr_information(github_token=kwargs.get('github_token'))
Expand Down Expand Up @@ -53,15 +54,17 @@ def fetch_pr_metadata_from_event_path() -> Optional[dict]:
Example:
{
"github_pr_id": 1,
"github_pr_url": "https://github.com/xyz/abc/pull/1
"github_pr_title": "Update README.md"
"github_pr_url": "https://github.com/xyz/abc/pull/1,
"github_pr_title": "Update README.md",
"github_repository": "xyz/abc"
}
:return: dict
"""

# get the event json from the path in GITHUB_EVENT_PATH
event_path = os.getenv("GITHUB_EVENT_PATH")
github_repository = os.getenv("GITHUB_REPOSITORY")
if event_path:
try:
with open(event_path, "r") as event_file:
Expand All @@ -73,7 +76,10 @@ def fetch_pr_metadata_from_event_path() -> Optional[dict]:
pr_url = pull_request_data["_links"]["html"]["href"]
pr_api = pull_request_data["_links"]["self"]["href"]
pr_title = _fetch_pr_title(pr_api)
return dict(github_pr_id=pr_id, github_pr_url=pr_url, github_pr_title=pr_title)
return dict(github_pr_id=pr_id,
github_pr_url=pr_url,
github_pr_title=pr_title,
github_repository=github_repository)
else:
print("Not a pull request event, skip.")
except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def mock_github_event(tmp_path, monkeypatch):
json.dump(event_data, f)

monkeypatch.setenv("GITHUB_EVENT_PATH", str(event_file))
monkeypatch.setenv("GITHUB_REPOSITORY", "abc/xyz")


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


def test_fetch_pr_metadata_no_event(mock_get_request_success, monkeypatch):
Expand Down

0 comments on commit dc896d4

Please sign in to comment.