Skip to content

Commit da62b2f

Browse files
Get ros2.repos file using GitHub API with authentication (#26)
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
1 parent 1ab7e44 commit da62b2f

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

ros_github_scripts/ci_for_pr.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
logger = logging.getLogger(__name__)
3030

3131
DEFAULT_JOB = 'ci_launcher'
32-
REPOS_URL = 'https://raw.githubusercontent.com/ros2/ros2/{}/ros2.repos'
32+
ROS2_REPO = 'ros2/ros2'
33+
ROS2_REPOS_FILE = 'ros2.repos'
3334
DEFAULT_TARGET = 'rolling'
3435
CI_SERVER = 'https://ci.ros2.org'
3536
SERVER_RETRIES = 2
@@ -55,14 +56,11 @@ def panic(msg: str) -> None:
5556
raise RuntimeError('Panic: ' + msg)
5657

5758

58-
def fetch_repos(target_release: str) -> dict:
59+
def fetch_repos(github_instance: Github, target_release: str) -> dict:
5960
"""Fetch the repos file for the specific release."""
60-
branch = target_release
61-
if branch == 'rolling':
62-
branch = 'master'
63-
repos_response = requests.get(REPOS_URL.format(branch))
64-
65-
repos_text = repos_response.text
61+
ros2_repo = github_instance.get_repo(ROS2_REPO)
62+
repos_file_contents = ros2_repo.get_contents(ROS2_REPOS_FILE, target_release)
63+
repos_text = repos_file_contents.decoded_content.decode('utf-8')
6664
toplevel_dict = yaml.safe_load(repos_text)
6765
return toplevel_dict['repositories']
6866

@@ -74,7 +72,7 @@ def create_ci_gist(
7472
) -> github.Gist.Gist:
7573
"""Create gist for the list of pull requests."""
7674
logger.info('Creating ros2.repos Gist for PRs')
77-
master_repos = fetch_repos(target_release)
75+
master_repos = fetch_repos(github_instance, target_release)
7876
shortnames = []
7977
for github_pr in pulls:
8078
pr_ref = github_pr.head.ref

0 commit comments

Comments
 (0)