code: def find_upstream_base_branch(base_branch: str):
      if base_branch in repo.refs:
          # Use the tracking branch of the local reference if it exists. This
          # returns None if no tracking branch is set.
          return repo.refs[base_branch]
  
      else:
          candidate_branches = [
              remote.refs[base_branch]
              for remote in repo.remotes
              if base_branch in remote.refs
          ]
          if len(candidate_branches) > 0:
              return sorted(
                  candidate_branches,
                  key=lambda branch: branch.commit.committed_datetime,
              )[-1]
  
      raise RuntimeError(f"Unable to find ref for '{base_branch}'.")
  
imports: import argparse
  import datetime
  import logging
  import os
  import re
  import sys
  from pathlib import Path
  from typing import Optional
  import git
label_desc: Use image node_id 1 for calling a global function with example usage: find_upstream_base_branch(base_branch) and returns: repo, sorted