Skip to content

Instantly share code, notes, and snippets.

@dirk-thomas
Last active August 29, 2015 14:04
Show Gist options
  • Save dirk-thomas/dda7a63e0d6faa58def8 to your computer and use it in GitHub Desktop.
Save dirk-thomas/dda7a63e0d6faa58def8 to your computer and use it in GitHub Desktop.
identify repositories with different release branch and doc/source branch
import subprocess
import yaml
from catkin_pkg.package import parse_package_string
import rosdistro
i = rosdistro.get_index(rosdistro.get_index_url())
for distro in reversed(sorted(i.distributions.keys())):
print(distro)
d = rosdistro.get_cached_distribution(i, distro)
f = d._distribution_file
for repo_name in sorted(f.repositories.keys()):
repo = f.repositories[repo_name]
if not repo.release_repository:
continue
if not repo.doc_repository and not repo.source_repository:
continue
release_repo = repo.release_repository
if release_repo.version is None:
continue
url = release_repo.url
prefix = 'https://github.com/'
if not url.startswith(prefix):
raise RuntimeError('wrong prefix')
suffix = '.git'
if not url.endswith(suffix):
raise RuntimeError('wrong suffix')
tracks_url = 'https://raw.githubusercontent.com/' + url[len(prefix):]
tracks_url = tracks_url[:-len(suffix)] + '/master/tracks.yaml'
#print(repo_name, tracks_url)
tracks_yaml = rosdistro.loader.load_url(tracks_url)
#print(tracks_yaml)
tracks_data = yaml.load(tracks_yaml)
release_branch = tracks_data['tracks'][distro]['devel_branch']
if release_branch is None:
upstream_url = tracks_data['tracks'][distro]['vcs_uri']
# ignore local upstream path
if upstream_url.startswith('/'):
continue
remotes = subprocess.check_output(['git', 'ls-remote', upstream_url])
lines = remotes.splitlines()
lines = [l.split('\t') for l in lines]
head_hash = [l[0] for l in lines if l[1] == 'HEAD'][0]
default_ref = [l[1] for l in lines if l[0] == head_hash and l[1] != 'HEAD'][0]
release_branch = default_ref.split('/')[-1]
if repo.doc_repository:
doc_branch = repo.doc_repository.version
if doc_branch != release_branch:
print(repo_name, 'doc', doc_branch, 'vs.', 'rel', release_branch)
if repo.source_repository:
source_branch = repo.source_repository.version
if source_branch != release_branch:
print(repo_name, 'source', source_branch, 'vs.', 'rel', release_branch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment