Skip to content

Commit

Permalink
compare branches (osmosis-labs#6698)
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic authored Oct 17, 2023
1 parent c54279d commit a9bcb69
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
"[proto3]": {
"editor.defaultFormatter": "xaver.clang-format"
},
"clang-format.style": "{BasedOnStyle: Google, IndentWidth: 2, ColumnLimit: 120, AlignConsecutiveAssignments: true, AlignConsecutiveDeclarations: true, SpacesInSquareBrackets: true}"
"clang-format.style": "{BasedOnStyle: Google, IndentWidth: 2, ColumnLimit: 120, AlignConsecutiveAssignments: true, AlignConsecutiveDeclarations: true, SpacesInSquareBrackets: true}",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none"
}
54 changes: 54 additions & 0 deletions scripts/compare_git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import re


def get_commits(branch):
try:
# Get the list of commits in the specified branch
commit_hashes = subprocess.check_output(
['git', 'log', '--oneline', 'origin/' + branch]).decode().splitlines()
return commit_hashes
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return []


def get_pr_number(commit_message):
# Extract PR number from commit message
pr_number = re.search(r'#\d+', commit_message)
return pr_number.group(0) if pr_number else None


def main():
release_branch = input("Enter the release branch name: ")
main_branch = input("Enter the main branch name (default: main): ")

if not main_branch:
main_branch = "main"

# Fetch the latest branches
subprocess.call(['git', 'fetch'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

main_commits = get_commits(main_branch)
release_commits = get_commits(release_branch)

main_pr_numbers = {get_pr_number(commit) for commit in main_commits}
release_pr_numbers = {get_pr_number(commit) for commit in release_commits}

# Find commits in main branch that are not backported to release branch
missing_commits = [commit for commit in main_commits if get_pr_number(
commit) not in release_pr_numbers]

if not missing_commits:
print(
f"All commits from {main_branch} are present in {release_branch}.")
else:
print(
f"\nCommits present in {main_branch} but missing in {release_branch}:")
for commit in missing_commits:
print(commit)


if __name__ == '__main__':
main()

0 comments on commit a9bcb69

Please sign in to comment.