old_contents: import argparse
  import logging as log
  import yaml
  from datetime import datetime
  from git import *
  from pprint import pformat
  from pprint import pprint
  from pymongo import MongoClient, DESCENDING
  
  
  def release_hashes(repo):
      for ref in repo.remotes.origin.refs:
          if ref.name.startswith('origin/rc/'):
              yield ref.commit.hexsha
  
  def check_all(args):
      config = yaml.safe_load(open(args.config))
      client = MongoClient(uri_from(config['DOC_STORE_CONFIG']))
      repos = [Repo(repo_dir) for repo_dir in config['repos']]
      configuration_repo = Repo(config['configuration_repo'])
      configuration_secure = Repo(config['configuration_secure'])
  
      for repo in repos:
          for git_hash in release_hashes(repo):
              pass
  
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(
          description="Monitor git repos for new rc branches.")
      parser.add_argument('-c','--config', required=True,
          help="Config file.")
  
      args = parser.parse_args()
      check_all(args)
  
new_contents: import argparse
  import json
  import logging as log
  import pickle
  import requests
  import yaml
  from datetime import datetime
  from git import Repo
  from os import path
  from pprint import pformat
  from pymongo import MongoClient, DESCENDING
  from stage_release import flip_repos, uri_from
  
  def releases(repo):
      for ref in repo.refs:
          if ref.name.startswith('origin/rc/'):
              yield ref
  
  def candidates_since(repo, time):
      for rc in releases(repo):
          last_update = datetime.utcfromtimestamp(rc.commit.committed_date)
          if last_update > time:
              # New RC or updated RC
              yield rc
  
  def stage_release(url, token, repo, rc):
      params = []
      params.append({'name': "{}_REF".format(repo), 'value': True})
      params.append({'name': repo, 'value': rc.commit.hexsha})
      build_params = {'parameter': params}
      log.info("New rc found{}, staging new release.".format(rc.name))
      r = requests.post(url,
                        data={"token", token},
                        params={"json": json.dumps(build_params)})
      if r.status_code != 201:
          msg = "Failed to submit request with params: {}"
          raise Exception(msg.format(pformat(build_params)))
  
  if __name__ == "__main__":
      parser = argparse.ArgumentParser(
          description="Monitor git repos for new rc branches.")
      parser.add_argument('-c', '--config', required=True,
          help="Config file.")
      parser.add_argument('-p', '--pickle', default="data.pickle",
          help="Pickle of presistent data.")
  
      args = parser.parse_args()
  
      config = yaml.safe_load(open(args.config))
  
      if path.exists(args.pickle):
          data = pickle.load(open(args.pickle))
      else:
          data = {}
  
      if 'last_check' not in data:
          last_check = datetime.utcnow()
      else:
          last_check = data['last_check']
  
      data['last_check'] = datetime.utcnow()
  
      all_plays = flip_repos(config['repos'])
      # Find plays that are affected by this repo.
      repos_with_changes = {}
      for repo in config['repos']:
          # Check for new rc candidates.
          for rc in candidates_since(Repo(repo), last_check):
              # Notify stage-release to build for the new repo.
              stage_release(config['abby_url'], config['abby_token'], repo, rc)
  
      pickle.dump(data, open(args.pickle, 'w'))
  
subject: Add logic to be able to monitor RCs from jenkins.