-
Notifications
You must be signed in to change notification settings - Fork 36
Bug 1968280 - Draft: Landoscript should fetch file modes for newly added or files being removed. #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Bug 1968280 - Draft: Landoscript should fetch file modes for newly added or files being removed. #1292
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,7 @@ async def run( | |
| files = [bump_config.path, *platform_config_files] | ||
| try: | ||
| log.info(f"fetching bump files from github: {files}") | ||
| orig_files = await github_client.get_files(files, branch) | ||
| orig_files = await github_client.get_files(files, branch, mode=None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This specific change should not be needed (see my comment elsewhere about the interface of |
||
| except TransportError as e: | ||
| raise LandoscriptError("couldn't retrieve bump files from github") from e | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| NO_NEWLINE_SUFFIX = "\\ No newline at end of file" | ||
|
|
||
|
|
||
| def diff_contents(orig, modified, file): | ||
| def diff_contents(orig, modified, file, mode=None): | ||
| """Create a git-style unified diff of `orig` and `modified` with the filename `file`.""" | ||
| add_remove_metadata = "" | ||
| if orig: | ||
|
|
@@ -14,7 +14,7 @@ def diff_contents(orig, modified, file): | |
| # orig does not exist yet; ie: it will be added | ||
| orig_contents = "" | ||
| fromfile = "/dev/null" | ||
| add_remove_metadata = "new file mode 100644\n" | ||
| add_remove_metadata = f"new file mode {mode or 100644}\n" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than having a default here, this function should raise an error if |
||
| if modified: | ||
| # modified exists already | ||
| modified_contents = modified.splitlines() | ||
|
|
@@ -23,7 +23,7 @@ def diff_contents(orig, modified, file): | |
| # modified does not exist yet; ie: it will be added | ||
| modified_contents = "" | ||
| tofile = "/dev/null" | ||
| add_remove_metadata = "deleted file mode 100644\n" | ||
| add_remove_metadata = f"deleted file mode {mode or 100644}\n" | ||
|
|
||
| diff_lines = [line for line in unified_diff(orig_contents, modified_contents, fromfile=fromfile, tofile=tofile, lineterm="")] | ||
| if not diff_lines: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,9 @@ async def _execute(): | |
|
|
||
| await retry_async(_execute, attempts=3, retry_exceptions=(TransportQueryError,), sleeptime_kwargs={"delay_factor": 0}) | ||
|
|
||
| async def get_files(self, files: Union[str, List[str]], branch: Optional[str] = None, files_per_request: int = 200) -> Dict[str, Union[str, None]]: | ||
| async def get_files( | ||
| self, files: Union[str, List[str]], branch: Optional[str] = None, files_per_request: int = 200, mode: Optional[str] = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not quite right - we want a boolean argument called something like
|
||
| ) -> Dict[str, Union[str, Dict[str, Optional[str]]]]: | ||
| """Get the contents of the specified files. | ||
|
|
||
| Args: | ||
|
|
@@ -127,10 +129,18 @@ async def get_files(self, files: Union[str, List[str]], branch: Optional[str] = | |
| dedent( | ||
| """ | ||
| $name: object(expression: "$branch:$file") { | ||
| ... on Blob { | ||
| text | ||
| } | ||
| ... on Tree { | ||
| entries { | ||
| name | ||
| mode | ||
| object { | ||
| ... on Blob { | ||
| text | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
| ) | ||
| ) | ||
|
|
@@ -140,7 +150,7 @@ async def get_files(self, files: Union[str, List[str]], branch: Optional[str] = | |
| # file paths to their hashes, and use the hashes as the key names | ||
| # in the query. | ||
| aliases = {} | ||
| ret: Dict[str, Union[str, None]] = {} | ||
| ret: Dict[str, Union[str, Dict[str, Optional[str]]]] = {} | ||
|
|
||
| # yields the starting index for each batch | ||
| for i in range(0, len(files), files_per_request): | ||
|
|
@@ -165,7 +175,10 @@ async def get_files(self, files: Union[str, List[str]], branch: Optional[str] = | |
| if v is None: | ||
| ret[name] = None | ||
| else: | ||
| ret[name] = v["text"] | ||
| if mode: | ||
| ret[name] = {"mode": v.get("mode"), "text": v.get("text")} | ||
| else: | ||
| ret[name] = v.get("text") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's update the value for each file to always be a dict; that will make things easier for callers, and make the function more comprehensible (especially the type signatures). |
||
|
|
||
| return ret | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you've updated
get_filesas noted below, thel10n_github_client.get_filescalls in this function andandroid_l10n_sync.pywill need to be updated to setfetch_mode=True.You will also need changes to actually pass the modes along to
diff_contentsfor each file.