<commit_before>import AWS from 'aws-sdk';
import check from 'check-types';
import config from '../../config/config.json';
import log from '../log';

AWS.config.update(config.AWS.credentials);

function publishToNewPostTopic(subject, message) {
  return new Promise((resolve, reject) => {
    const sns = new AWS.SNS();
    sns.publish({
      TargetArn: config.AWS.SNS.newPostARN,
      Subject: subject,
      Message: message
    }, (error, data) => {
      if (error) {
        log.error({ error }, 'Error publishing to new post SNS topic');
        reject(error);
      } else {
        log.info({ subject, message }, 'Posted to new post SNS Topic');
        resolve(data.MessageId);
      }
    });
  });
}

export default function notifyOfNewBlogs(usersToNewPosts) {
  return new Promise((resolve, reject) => {
    if (!check.array(usersToNewPosts) || usersToNewPosts.length === 0) {
      reject(new Error('Valid array of users with new posts required'));
    }

    if (usersToNewPosts.length === 1) {
      const singleAuthor = usersToNewPosts[0];
      if (singleAuthor.newPosts.length === 1) {
        return publishToNewPostTopic(`${singleAuthor.firstName} ${singleAuthor.lastName} published a new blog post`,
                                     singleAuthor.newPosts[0].title);
      }

      const intro = singleAuthor.newPosts.length > 2 ? 'Including:' : '';
      return publishToNewPostTopic(`${singleAuthor.firstName} ${singleAuthor.lastName} published ${singleAuthor.newPosts.length} new blog posts`,
                                    `${intro} "${singleAuthor.newPosts[0].title}" and "${singleAuthor.newPosts[1].title}"`);
    }

    const numberOfNewPosts = usersToNewPosts.reduce((total, user) => total + user.newPosts.length, 0);
    const intro = usersToNewPosts.length > 2 ? 'Including posts by' : 'Written by';
    return publishToNewPostTopic(`Read ${numberOfNewPosts} new posts by ${usersToNewPosts.length} authors`,
                                 `${intro} ${usersToNewPosts[0].firstName} ${usersToNewPosts[0].lastName} and ${usersToNewPosts[1].firstName} ${usersToNewPosts[1].lastName}`);
  });
}<commit_msg>The notifyOfNewBlogs function shouldn't return a Promise and then within that return a promise. Fixed.<commit_after>import AWS from 'aws-sdk';
import check from 'check-types';
import config from '../../config/config.json';
import log from '../log';

AWS.config.update(config.AWS.credentials);

function publishToNewPostTopic(subject, message) {
  return new Promise((resolve, reject) => {
    const sns = new AWS.SNS();
    sns.publish({
      TargetArn: config.AWS.SNS.newPostARN,
      Subject: subject,
      Message: message
    }, (error, data) => {
      if (error) {
        log.error({ error }, 'Error publishing to new post SNS topic');
        reject(error);
      } else {
        log.info({ subject, message }, 'Posted to new post SNS Topic');
        resolve(data.MessageId);
      }
    });
  });
}

export default function notifyOfNewBlogs(usersToNewPosts) {
  if (!check.array(usersToNewPosts) || usersToNewPosts.length === 0) {
    throw new Error('Valid array of users with new posts required');
  }

  if (usersToNewPosts.length === 1) {
    const singleAuthor = usersToNewPosts[0];
    if (singleAuthor.newPosts.length === 1) {
      return publishToNewPostTopic(`${singleAuthor.firstName} ${singleAuthor.lastName} published a new blog post`,
                                    singleAuthor.newPosts[0].title);
    }

    const intro = singleAuthor.newPosts.length > 2 ? 'Including:' : '';
    return publishToNewPostTopic(`${singleAuthor.firstName} ${singleAuthor.lastName} published ${singleAuthor.newPosts.length} new blog posts`,
                                  `${intro} "${singleAuthor.newPosts[0].title}" and "${singleAuthor.newPosts[1].title}"`);
  }

  const numberOfNewPosts = usersToNewPosts.reduce((total, user) => total + user.newPosts.length, 0);
  const intro = usersToNewPosts.length > 2 ? 'Including posts by' : 'Written by';
  return publishToNewPostTopic(`Read ${numberOfNewPosts} new posts by ${usersToNewPosts.length} authors`,
                                `${intro} ${usersToNewPosts[0].firstName} ${usersToNewPosts[0].lastName} and ${usersToNewPosts[1].firstName} ${usersToNewPosts[1].lastName}`);
}
{'fraction_non_alphanumeric': 0.13912840829643439, 'fraction_numerical': 0.0065252854812398045, 'mean_word_length': 3.245301681503462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2480538', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1235, 'n_words': 303}