<commit_before>#!/bin/bash -eu

echo "Code stats for $REPO_NAME"
STATSJSON=/tmp/codestats.json
cloc code-repo --json | tee $STATSJSON

python -c "
import json


from datadog import initialize, api

options = {
    'api_key': '$DATADOG_API_KEY',
    'app_key': '$DATADOG_APP_KEY'
}

initialize(**options)

stats = json.load(open('$STATSJSON'))

del stats['header']

metrics = []

metric_name = 'codestat.$REPO_NAME'
for lang in stats:
  if lang == 'SUM':
    continue
  for attr in stats[lang]:
    count = stats[lang].get(attr)
    metrics.append({'metric': metric_name, 'points': count, 'tags': [lang, attr], 'host': 'ci'})

print metrics

api.Metric.send(metrics)
"<commit_msg>Publish total pipeline count<commit_after>#!/bin/bash -eu

echo "Code stats for $REPO_NAME"
STATSJSON=/tmp/codestats.json
cloc code-repo --json | tee $STATSJSON

python -c "
import json


from datadog import initialize, api

options = {
    'api_key': '$DATADOG_API_KEY',
    'app_key': '$DATADOG_APP_KEY'
}

initialize(**options)

stats = json.load(open('$STATSJSON'))

del stats['header']

metrics = []

metric_name = 'codestat.$REPO_NAME'
for lang in stats:
  if lang == 'SUM':
    continue
  for attr in stats[lang]:
    count = stats[lang].get(attr)
    metrics.append({'metric': metric_name, 'points': count, 'tags': [lang, attr], 'host': 'ci'})

pipelines_count = 0

for dir, subdirs, files in os.walk('code-repo'):
  if 'pipeline.yml' in files:
    pipelines_count +=1

metrics.append({'metric': metric_name + '.pipelines_total', 'points': pipelines_count, 'tags': [], 'host': 'ci'})

api.Metric.send(metrics)
"
{'fraction_non_alphanumeric': 0.1639549436795995, 'fraction_numerical': 0.0012515644555694619, 'mean_word_length': 4.552083333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7355293', 'n_tokens_mistral': 599, 'n_tokens_neox': 580, 'n_words': 145}