<commit_before>'use strict';

const colors = require('colors/safe');

const AppConfig = require('../models/app_configuration.js');
const handleCommandStream = require('../command-stream-handler');
const Logger = require('../logger.js');
const Notification = require('../models/notification.js');
const Organisation = require('../models/organisation.js');
const User = require('../models/user.js');

function getOrgaIdOrUserId (api, orgIdOrName) {
  if (orgIdOrName == null) {
    return User.getCurrentId(api);
  }
  return Organisation.getId(api, orgIdOrName);
}

function getOwnerAndApp (api, params, useLinkedApp) {
  const { alias } = params.options;

  if (!useLinkedApp) {
    return getOrgaIdOrUserId(api, params.options.org)
      .flatMapLatest((ownerId) => ({ ownerId }));
  }

  return AppConfig.getAppData(alias)
    .flatMapLatest((appData) => {
      if (appData.org_id) {
        return { ownerId: appData.org_id, appId: appData.app_id };
      }
      return User.getCurrentId(api).flatMapLatest((id) => {
        return { ownerId: id, appId: appData.app_id };
      });
    });
}

function displayWebhook (hook) {
  Logger.println((hook.name && colors.bold(hook.name)) || hook.id);
  Logger.println(`  id: ${hook.id}`);
  Logger.println(`  services: ${(hook.scope && hook.scope.join(', ')) || hook.ownerId}`);
  Logger.println(`  events: ${(hook.events && hook.events.join(', ')) || colors.bold('ALL')}`);
  Logger.println('  hooks:');
  hook.urls.forEach((url) => Logger.println(`    ${url.url} (${url.format})`));
  Logger.println();
}

function displayEmailhook (hook) {
  Logger.println((hook.name && colors(hook.name)) || hook.id);
  Logger.println(`  id: ${hook.id}`);
  Logger.println(`  services: ${(hook.scope && hook.scope.join(', ')) || hook.ownerId}`);
  Logger.println(`  events: ${(hook.events && hook.events.join(', ')) || colors.bold('ALL')}`);<commit_msg>Fix bad usage of colors/safe in notification<commit_after>'use strict';

const colors = require('colors/safe');

const AppConfig = require('../models/app_configuration.js');
const handleCommandStream = require('../command-stream-handler');
const Logger = require('../logger.js');
const Notification = require('../models/notification.js');
const Organisation = require('../models/organisation.js');
const User = require('../models/user.js');

function getOrgaIdOrUserId (api, orgIdOrName) {
  if (orgIdOrName == null) {
    return User.getCurrentId(api);
  }
  return Organisation.getId(api, orgIdOrName);
}

function getOwnerAndApp (api, params, useLinkedApp) {
  const { alias } = params.options;

  if (!useLinkedApp) {
    return getOrgaIdOrUserId(api, params.options.org)
      .flatMapLatest((ownerId) => ({ ownerId }));
  }

  return AppConfig.getAppData(alias)
    .flatMapLatest((appData) => {
      if (appData.org_id) {
        return { ownerId: appData.org_id, appId: appData.app_id };
      }
      return User.getCurrentId(api).flatMapLatest((id) => {
        return { ownerId: id, appId: appData.app_id };
      });
    });
}

function displayWebhook (hook) {
  Logger.println((hook.name && colors.bold(hook.name)) || hook.id);
  Logger.println(`  id: ${hook.id}`);
  Logger.println(`  services: ${(hook.scope && hook.scope.join(', ')) || hook.ownerId}`);
  Logger.println(`  events: ${(hook.events && hook.events.join(', ')) || colors.bold('ALL')}`);
  Logger.println('  hooks:');
  hook.urls.forEach((url) => Logger.println(`    ${url.url} (${url.format})`));
  Logger.println();
}

function displayEmailhook (hook) {
  Logger.println((hook.name && colors.bold(hook.name)) || hook.id);
  Logger.println(`  id: ${hook.id}`);
  Logger.println(`  services: ${(hook.scope && hook.scope.join(', ')) || hook.ownerId}`);
  Logger.println(`  events: ${(hook.events && hook.events.join(', ')) || colors.bold('ALL')}`);
{'fraction_non_alphanumeric': 0.19979024646040902, 'fraction_numerical': 0.0, 'mean_word_length': 4.162381596752368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '750930', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1272, 'n_words': 229}