Skip to content

Commit

Permalink
feat(file size limit): add file query ref param
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicWrege authored and Scriptkiddi committed Dec 28, 2024
1 parent dac9f73 commit f06de2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nixpkgs_merge_bot/github/GitHubClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def pull_request_files(self, owner: str, repo: str, pr_number: int) -> HttpRespo
return self.get(f"/repos/{owner}/{repo}/pulls/{pr_number}/files")

def get_request_file_content(
self, owner: str, repo: str, filepath: str
self, owner: str, repo: str, filepath: str, ref_quer_param: str
) -> HttpResponse:
return self.get(f"/repos/{owner}/{repo}/contents/{filepath}")
return self.get(f"/repos/{owner}/{repo}/contents/{filepath}?{ref_quer_param}")

def get_issue(self, owner: str, repo: str, issue_number: int) -> HttpResponse:
return self.get(f"/repos/{owner}/{repo}/issues/{issue_number}")
Expand Down
11 changes: 8 additions & 3 deletions nixpkgs_merge_bot/merging_strategies/merging_strategy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from urllib.parse import urlparse

from nixpkgs_merge_bot.github.GitHubClient import GithubClient
from nixpkgs_merge_bot.settings import Settings
Expand Down Expand Up @@ -41,7 +42,7 @@ def run_technical_limits_check(

for file in body:
filename = file["filename"]
file_size_bytes = self.get_file_size_bytes(pull_request, filename)
file_size_bytes = self.get_file_size_bytes(pull_request, file)
if file_size_bytes > self.settings.max_file_size_bytes:
result = False
message = f"{filename} exceeds the maximum allowed file size of {self.settings.max_file_size_mb} MB"
Expand All @@ -53,9 +54,13 @@ def run_technical_limits_check(
log.info(f"{pull_request.number}: {message}")
return result, decline_reasons

def get_file_size_bytes(self, pull_request, filename) -> int:
def get_file_size_bytes(self, pull_request, file) -> int:
file_contents_url = urlparse(file["contents_url"])
response = self.github_client.get_request_file_content(
pull_request.repo_owner, pull_request.repo_name, filename
pull_request.repo_owner,
pull_request.repo_name,
file["filename"],
file_contents_url.query,
)
return response.json()["size"]

Expand Down

0 comments on commit f06de2d

Please sign in to comment.