mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 09:04:19 +01:00
Fix merge_pr.py script to avoid marking contributor PRs as closed
This commit is contained in:
@@ -92,7 +92,7 @@ def wrap_text(text, width=72):
|
|||||||
return "\n".join(wrapped_lines)
|
return "\n".join(wrapped_lines)
|
||||||
|
|
||||||
|
|
||||||
def merge_pr(pr_number):
|
def merge_pr(pr_number, use_api=True):
|
||||||
# GitHub authentication
|
# GitHub authentication
|
||||||
token = os.getenv("GITHUB_TOKEN")
|
token = os.getenv("GITHUB_TOKEN")
|
||||||
g = Github(token)
|
g = Github(token)
|
||||||
@@ -120,6 +120,32 @@ def merge_pr(pr_number):
|
|||||||
# Add Closes line
|
# Add Closes line
|
||||||
commit_message += f"\n\nCloses #{pr_info['number']}"
|
commit_message += f"\n\nCloses #{pr_info['number']}"
|
||||||
|
|
||||||
|
if use_api:
|
||||||
|
# Merge using GitHub API
|
||||||
|
try:
|
||||||
|
pr = pr_info["pr_object"]
|
||||||
|
# Check if PR is mergeable
|
||||||
|
if not pr.mergeable:
|
||||||
|
print(f"Error: PR #{pr_number} is not mergeable. State: {pr.mergeable_state}")
|
||||||
|
sys.exit(1)
|
||||||
|
result = pr.merge(
|
||||||
|
commit_title=commit_title,
|
||||||
|
commit_message=commit_message.replace(commit_title + "\n\n", ""),
|
||||||
|
merge_method="merge",
|
||||||
|
)
|
||||||
|
if result.merged:
|
||||||
|
print(f"Pull request #{pr_number} merged successfully via GitHub API!")
|
||||||
|
print(f"Merge commit SHA: {result.sha}")
|
||||||
|
print(f"\nMerge commit message:\n{commit_message}")
|
||||||
|
else:
|
||||||
|
print(f"Error: Failed to merge PR #{pr_number}")
|
||||||
|
print(f"Message: {result.message}")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error merging PR via API: {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
else:
|
||||||
# Create a temporary file for the commit message
|
# Create a temporary file for the commit message
|
||||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file:
|
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_file:
|
||||||
temp_file.write(commit_message)
|
temp_file.write(commit_message)
|
||||||
@@ -149,6 +175,7 @@ def merge_pr(pr_number):
|
|||||||
|
|
||||||
print("Pull request merged successfully!")
|
print("Pull request merged successfully!")
|
||||||
print(f"Merge commit message:\n{commit_message}")
|
print(f"Merge commit message:\n{commit_message}")
|
||||||
|
print("\nNote: You'll need to push this merge to mark the PR as merged on GitHub")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Clean up the temporary file
|
# Clean up the temporary file
|
||||||
@@ -165,4 +192,8 @@ if __name__ == "__main__":
|
|||||||
print("Error: PR number must be a positive integer")
|
print("Error: PR number must be a positive integer")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
merge_pr(pr_number)
|
use_api = True
|
||||||
|
if len(sys.argv) == 3 and sys.argv[2] == "--local":
|
||||||
|
use_api = False
|
||||||
|
|
||||||
|
merge_pr(pr_number, use_api)
|
||||||
|
|||||||
Reference in New Issue
Block a user