Skip to content

Commit c93ea20

Browse files
committed
Nits and renames
Pull Request: #28 (main)
1 parent d923073 commit c93ea20

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

git-grok

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Main:
127127
login: str
128128
remote: str
129129
remote_base_branch: str = "master"
130+
in_rebase_interactive: InRebaseInteractiveData | None = None
130131

131132
#
132133
# Main entry point.
@@ -151,14 +152,14 @@ class Main:
151152
)
152153
args = parser.parse_args()
153154

154-
in_rebase_interactive = InRebaseInteractiveData.parse(
155+
self.in_rebase_interactive = InRebaseInteractiveData.parse(
155156
os.environ.get(INTERNAL_IN_REBASE_INTERACTIVE_VAR, "")
156157
)
157158

158159
self.debug = args.debug
159160
self.debug_force_push_branches = args.debug_force_push_branches
160161

161-
if not in_rebase_interactive:
162+
if not self.in_rebase_interactive:
162163
self.gh_verify_version()
163164
self.git_verify_version()
164165
self.self_update()
@@ -179,10 +180,10 @@ class Main:
179180
"git_get_current_remote_base_branch",
180181
self.git_get_current_remote_base_branch,
181182
)
182-
if not in_rebase_interactive:
183+
if not self.in_rebase_interactive:
183184
self.run_all()
184185
else:
185-
self.run_in_rebase_interactive(data=in_rebase_interactive)
186+
self.run_in_rebase_interactive(data=self.in_rebase_interactive)
186187

187188
#
188189
# Assuming all PRs in the stack already have PR URLs in their description,
@@ -227,6 +228,8 @@ class Main:
227228
commit_with_no_url = commit
228229
break
229230
else:
231+
# Push this branch and see whether GitHub says whether it
232+
# was up to date or not.
230233
commit_hashes_to_push_branch.append(commit.hash)
231234

232235
# Some commits have no related PRs (no GitHub URLs in the message)?
@@ -342,11 +345,11 @@ class Main:
342345
commits: list[Commit],
343346
prs_by_url: dict[str, Pr],
344347
):
345-
commits_chronological = list(reversed(commits))
346-
for i, commit in list(enumerate(commits_chronological))[1:]:
348+
commits_old_to_new = list(reversed(commits))
349+
for i, commit in list(enumerate(commits_old_to_new))[1:]:
347350
pr = prs_by_url.get(commit.url, None) if commit.url else None
348351
if pr and pr.auto_merge_status == "ENABLED":
349-
prev_commit = commits_chronological[i - 1]
352+
prev_commit = commits_old_to_new[i - 1]
350353
prev_pr = (
351354
prs_by_url.get(prev_commit.url, None) if prev_commit.url else None
352355
)
@@ -426,8 +429,8 @@ class Main:
426429
):
427430
# We must iterate from the oldest commit to the newest one, because
428431
# previous commit PR's branch becomes the next commit PR's base branch.
429-
commits_chronological = list(reversed(commits))
430-
for i, commit in enumerate(commits_chronological):
432+
commits_old_to_new = list(reversed(commits))
433+
for i, commit in enumerate(commits_old_to_new):
431434
self.print_header(f"Updating PR: {self.clean_title(commit.title)}")
432435

433436
if commit.hash in commit_hashes_to_push_branch:
@@ -438,13 +441,10 @@ class Main:
438441
branch=str(commit.branch),
439442
result=result,
440443
)
441-
commits_chronological[i] = commit
444+
commits_old_to_new[i] = commit
442445

443-
assert (
444-
commit.url is not None
445-
), f"commit {commit.hash} PR url is expected to be in the message at this point"
446446
pr, result = self.process_update_pr(
447-
prev_commit=commits_chronological[i - 1] if i > 0 else None,
447+
prev_commit=commits_old_to_new[i - 1] if i > 0 else None,
448448
commit=commit,
449449
commits=commits,
450450
)
@@ -453,7 +453,7 @@ class Main:
453453
result=result,
454454
review_decision=pr.review_decision,
455455
)
456-
commits_chronological[i].branch = pr.head_branch
456+
commits_old_to_new[i].branch = pr.head_branch
457457

458458
#
459459
# Pushes an existing branch (it we know this commit's PR URL by querying
@@ -495,16 +495,12 @@ class Main:
495495
pr_numbers: list[int] = []
496496
pr_number_current: int | None = None
497497
for c in commits:
498-
assert (
499-
c.url is not None
500-
), f"commit {c.hash} PR URL is expected to be in the message at this point"
498+
assert c.url is not None
501499
if m := re.search(r"/(\d+)$", c.url):
502500
pr_numbers.append(int(m.group(1)))
503501
if c.hash == commit.hash:
504502
pr_number_current = int(m.group(1))
505-
assert (
506-
commit.url is not None
507-
), f"commit {commit.hash} PR URL is expected to be in the message at this point"
503+
assert commit.url is not None
508504
return self.gh_update_pr(
509505
url=commit.url,
510506
base_branch=prev_commit.branch if prev_commit else None,
@@ -1147,7 +1143,7 @@ class Main:
11471143
# Prints a status after a commit message was updated locally.
11481144
#
11491145
def print_commit_message_updated(self):
1150-
print(f" ── updated commit message")
1146+
print(f" ── added PR URL to commit's message to bind them")
11511147
sys.stdout.flush()
11521148

11531149
#
@@ -1282,7 +1278,15 @@ class Main:
12821278
def debug_log_text(self, *, text: str):
12831279
try:
12841280
with open(DEBUG_FILE, "a+") as file:
1285-
file.write(f"=== {datetime.now()}\n")
1281+
file.write(
1282+
f"=== {datetime.now()}"
1283+
+ (
1284+
f" (in rebase interactive, {self.in_rebase_interactive.commit_index_one_based}/{self.in_rebase_interactive.total_commits_in_stack})"
1285+
if self.in_rebase_interactive
1286+
else ""
1287+
)
1288+
+ "\n"
1289+
)
12861290
file.write(f"{text.rstrip()}\n")
12871291
file.write("\n")
12881292
except:

0 commit comments

Comments
 (0)