original_docstring: 
      Background Cloud Function to be triggered by Pub/Sub.
  
      Updates repository build badge. Triggered by incoming
      pubsub messages from Google Cloud Build.
      
docstring: Background Cloud Function to be triggered by Pub/Sub.
  Updates repository build badge. Triggered by incoming
  pubsub messages from Google Cloud Build.
docstring_tokens: Background Cloud Function to be triggered by Pub / Sub . Updates repository build badge . Triggered by incoming pubsub messages from Google Cloud Build .
code: def build_badge(event, context):
      """
      Background Cloud Function to be triggered by Pub/Sub.
  
      Updates repository build badge. Triggered by incoming
      pubsub messages from Google Cloud Build.
      """
  
      decoded = base64.b64decode(event['data']).decode('utf-8')
      data = json.loads(decoded)
  
      bucket = os.environ['BADGES_BUCKET']
      try:
          repo = data['source']['repoSource']['repoName']
          branch = data['source']['repoSource']['branchName']
  
          if repo.startswith('github_'):
              # mirrored repo format: (github)_<owner>_<repo>
              repo = repo.split('_', 2)[-1]
      except KeyError:
          # GitHub app sets these values. 
          repo = data['substitutions']['REPO_NAME']
          branch = data['substitutions']['BRANCH_NAME']
      finally:
          if repo != 'arcs' and branch != 'master':
              return
          tmpl = os.environ.get('TEMPLATE_PATH',
                  'builds/${repo}/branches/${branch}.svg')
          src = 'badges/{}.svg'.format(data['status'].lower())
          dest = Template(tmpl).substitute(repo=repo, branch=branch)
          copy_badge(bucket, src, dest)
          return
code_tokens: def build_badge ( event , context ) : decoded = base64 . b64decode ( event [ 'data' ] ) . decode ( 'utf-8' ) data = json . loads ( decoded ) bucket = os . environ [ 'BADGES_BUCKET' ] try : repo = data [ 'source' ] [ 'repoSource' ] [ 'repoName' ] branch = data [ 'source' ] [ 'repoSource' ] [ 'branchName' ] if repo . startswith ( 'github_' ) : repo = repo . split ( '_' , 2 ) [ - 1 ] except KeyError : repo = data [ 'substitutions' ] [ 'REPO_NAME' ] branch = data [ 'substitutions' ] [ 'BRANCH_NAME' ] finally : if repo != 'arcs' and branch != 'master' : return tmpl = os . environ . get ( 'TEMPLATE_PATH' , 'builds/${repo}/branches/${branch}.svg' ) src = 'badges/{}.svg' . format ( data [ 'status' ] . lower ( ) ) dest = Template ( tmpl ) . substitute ( repo = repo , branch = branch ) copy_badge ( bucket , src , dest ) return
short_docstring: Background Cloud Function to be triggered by Pub/Sub.
short_docstring_tokens: Background Cloud Function to be triggered by Pub / Sub .
comment: """
      Background Cloud Function to be triggered by Pub/Sub.
  
      Updates repository build badge. Triggered by incoming
      pubsub messages from Google Cloud Build.
      """$SEP$# mirrored repo format: (github)_<owner>_<repo>$SEP$# GitHub app sets these values. 