Skip to content

Commit 4279679

Browse files
committed
chore(core): test bump commit msg version [patch candidate]
1 parent 029c5c9 commit 4279679

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

commit_msg_version_bump/main.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import subprocess
1717
import sys
1818
from logging.handlers import RotatingFileHandler
19-
from typing import List, Optional
19+
from typing import List, Optional, Tuple
2020

2121
import toml
2222

@@ -106,25 +106,25 @@ def configure_logger(log_level: str) -> None:
106106
logger.addHandler(console_handler)
107107

108108

109-
def get_pushed_refs() -> List[str]:
109+
def get_pushed_refs() -> List[Tuple[str, str]]:
110110
"""
111111
Retrieves the list of refs being pushed.
112112
113113
Returns:
114-
List[str]: List of refs being pushed.
114+
List[Tuple[str, str]]: List of tuples containing local_ref and remote_sha.
115115
"""
116116
refs = []
117117
try:
118118
# Read from stdin the refs being pushed
119119
for line in sys.stdin:
120120
parts = line.strip().split()
121-
if len(parts) >= 2:
122-
local_ref, local_sha = parts[0], parts[1]
123-
refs.append(local_ref)
124-
logging.debug(f"Refs being pushed: {refs}")
121+
if len(parts) >= 4:
122+
local_ref, local_sha, remote_ref, remote_sha = parts[:4]
123+
refs.append((local_ref, remote_sha))
124+
logger.debug(f"Refs being pushed: {refs}")
125125
return refs
126126
except Exception as e:
127-
logging.error(f"Error reading refs from stdin: {e}")
127+
logger.error(f"Error reading refs from stdin: {e}")
128128
sys.exit(1)
129129

130130

@@ -150,21 +150,21 @@ def get_upstream_branch() -> Optional[str]:
150150
return None
151151

152152

153-
def get_commits_being_pushed(local_ref: str, remote_ref: str) -> List[str]:
153+
def get_commits_being_pushed(remote_sha: str, local_sha: str) -> List[str]:
154154
"""
155-
Retrieves the list of commit hashes being pushed for a given ref.
155+
Retrieves the list of commit hashes being pushed for a given ref range.
156156
157157
Args:
158-
local_ref (str): The local ref being pushed.
159-
remote_ref (str): The remote ref being pushed to.
158+
remote_sha (str): The remote SHA before the push.
159+
local_sha (str): The local SHA being pushed.
160160
161161
Returns:
162162
List[str]: List of commit hashes being pushed.
163163
"""
164164
try:
165165
commits = (
166166
subprocess.run(
167-
["git", "rev-list", "--no-merges", f"{remote_ref}..{local_ref}"],
167+
["git", "rev-list", "--no-merges", f"{remote_sha}..{local_sha}"],
168168
check=True,
169169
stdout=subprocess.PIPE,
170170
stderr=subprocess.PIPE,
@@ -174,10 +174,10 @@ def get_commits_being_pushed(local_ref: str, remote_ref: str) -> List[str]:
174174
.split("\n")
175175
)
176176
commits = [commit for commit in commits if commit]
177-
logger.debug(f"Commits being pushed for {local_ref}..{remote_ref}: {commits}")
177+
logger.debug(f"Commits being pushed for {remote_sha}..{local_sha}: {commits}")
178178
return commits
179179
except subprocess.CalledProcessError as e:
180-
logger.error(f"Error retrieving commits for {local_ref}..{remote_ref}: {e.stderr}")
180+
logger.error(f"Error retrieving commits for {remote_sha}..{local_sha}: {e.stderr}")
181181
sys.exit(1)
182182

183183

@@ -350,13 +350,21 @@ def main() -> None:
350350
logger.info("No refs being pushed.")
351351
return
352352

353-
upstream_ref = get_upstream_branch()
354-
if not upstream_ref:
355-
logger.error("No upstream branch found. Aborting.")
356-
sys.exit(1)
353+
for local_ref, remote_sha in pushed_refs:
354+
try:
355+
local_sha = subprocess.run(
356+
["git", "rev-parse", local_ref],
357+
check=True,
358+
stdout=subprocess.PIPE,
359+
stderr=subprocess.PIPE,
360+
text=True,
361+
).stdout.strip()
362+
logger.debug(f"Local SHA for {local_ref}: {local_sha}")
363+
except subprocess.CalledProcessError as e:
364+
logger.error(f"Error retrieving local SHA for {local_ref}: {e.stderr}")
365+
continue
357366

358-
for local_ref in pushed_refs:
359-
commits = get_commits_being_pushed(local_ref, upstream_ref)
367+
commits = get_commits_being_pushed(remote_sha, local_sha)
360368
if not commits:
361369
logger.info(f"No new commits to process for {local_ref}.")
362370
continue

0 commit comments

Comments
 (0)