From 2581eaaa35e889b88a42835f97c85fa3294c7b84 Mon Sep 17 00:00:00 2001 From: Katie Worton Date: Mon, 9 Oct 2023 11:25:48 +0100 Subject: [PATCH 1/2] read-skipfile-results: bug fix base patch name Bug fix for the name of the base patch of the PR for the case where there are no formatting changes. When "origin/master" is specified as the base, the following error occurs: Traceback (most recent call last): File "/builds/Linaro/lkft/mirrors/skipfile-testing/squad-client-utils/read-skipfile-results", line 433, in exit(run()) ^^^^^ File "/builds/Linaro/lkft/mirrors/skipfile-testing/squad-client-utils/read-skipfile-results", line 411, in run push_pr( File "/builds/Linaro/lkft/mirrors/skipfile-testing/squad-client-utils/read-skipfile-results", line 142, in push_pr pr = github_repo.create_pull( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/github/Repository.py", line 1526, in create_pull headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/pulls", input=post_parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 494, in requestJsonAndCheck return self.__check(*self.requestJson(verb, url, parameters, headers, input, self.__customConnection(url))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/github/Requester.py", line 525, in __check raise self.createException(status, responseHeaders, data) github.GithubException.GithubException: 422 {"message": "Validation Failed", "errors": [{"resource": "PullRequest", "field": "base", "code": "invalid"}], "documentation_url": "https://docs.github.com/rest/pulls/pulls#create-a-pull-request"} The fix is to change the base patch location from "origin/master" to "master". Signed-off-by: Katie Worton --- read-skipfile-results | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/read-skipfile-results b/read-skipfile-results index 7129a1e..c55c4e4 100755 --- a/read-skipfile-results +++ b/read-skipfile-results @@ -218,7 +218,7 @@ def run(raw_args=None): github_repo = g.get_repo(f"{username}/{repo_name}") # Base patch - base patch for PRs - base_patch = "origin/master" + base_patch = "master" # If there are any formatting updates, make these if repo.index.diff("HEAD"): From 8bd79a16ef7caccc48c7cf7fe520e85bce2398db Mon Sep 17 00:00:00 2001 From: Katie Worton Date: Mon, 9 Oct 2023 11:32:39 +0100 Subject: [PATCH 2/2] read-skipfile-results: rename variables for PR base patch Rename `base` to `pr_base_patch` and `base_patch` to `next_pr_base_patch` to give more descriptive names for these variables. Signed-off-by: Katie Worton --- read-skipfile-results | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/read-skipfile-results b/read-skipfile-results index c55c4e4..3b47db7 100755 --- a/read-skipfile-results +++ b/read-skipfile-results @@ -218,15 +218,15 @@ def run(raw_args=None): github_repo = g.get_repo(f"{username}/{repo_name}") # Base patch - base patch for PRs - base_patch = "master" + next_pr_base_patch = "master" # If there are any formatting updates, make these if repo.index.diff("HEAD"): summary = "Skipfile formatting updates" message = "Clean up skipfile formatting." - base = "master" + pr_base_patch = next_pr_base_patch head = f"formatting-update-{date_str}-{patch_count}" - base_patch = head + next_pr_base_patch = head logger.debug( "branches:" + "\n".join([str(b.name) for b in github_repo.get_branches()]) @@ -249,7 +249,7 @@ def run(raw_args=None): github_repo, summary, message, - base, + pr_base_patch, head, ) @@ -363,8 +363,9 @@ def run(raw_args=None): # head name for update head = f"skipfile-update-{date_str}-{patch_count}" - # Check out the base patch - repo.git.checkout(base_patch) + # Check out the base patch - this doesn't move since we want to + # create the different PRs in parallel after applying formatter + repo.git.checkout(next_pr_base_patch) skipfile["skiplist"] = new_skiplist @@ -392,7 +393,7 @@ def run(raw_args=None): + f"{squad_build_urls}" ) # set base patch for PR - base = base_patch + pr_base_patch = next_pr_base_patch if len(summary) > 50: # Truncate the commit summary to < 50 characters for git commit @@ -414,7 +415,7 @@ def run(raw_args=None): github_repo, summary, message, - base, + pr_base_patch, head, ) @@ -423,7 +424,7 @@ def run(raw_args=None): new_skipitem = None # Log commit to file with open(f"{head}.diff", "w") as file: - diff = popen(f"git diff {base} {head}").read() + diff = popen(f"git diff {pr_base_patch} {head}").read() file.write(f"{summary}\n{message}\n{diff}") return 0