<commit_before>'use strict';

var List = require('immutable').List;
var Map = require('immutable').Map;
var Moment = require('moment');
var Promise = require('promise');

/**
 * Pure function that publish a set of metadata to an external service.
 *
 * @exports lib/publisher
 * @param {Object} service - An object implementing a `post` function
 */
var Publisher = function (service) {
  if (typeof service !== 'object' || typeof service.post !== 'function') {
    throw new TypeError(
      'service must be defined and implement a post function'
    );
  }

  this.service = service;

  Object.freeze(this);
};

/**
 * Publish the set of metadata using a POSTable service.
 *
 * @param {Map.<string, *>} metadata - The metadata of the document to publish
 * @returns Promise.<Array.<String>> A list of publication errors for this set of metadata
 */
Publisher.prototype.publish = function (metadata) {
  if (!(metadata instanceof Map)) throw new TypeError('metadata must be a Map');
  return this.service.post({
    specversion: {
      status: metadata.get('profile'),
      uri: metadata.get('thisVersion'),
      latestVersionUri: metadata.get('latestVersion'),
      previousVersionUri: metadata.get('previousVersion'),
      date: new Moment(metadata.get('docDate'), 'YYYY-MM-DD')
              .format('YYYY-MM-DD'),
      title: metadata.get('title'),
      deliverers: metadata.get('delivererIDs'),
      editors: metadata.get('editors'),
      rectrack: metadata.get('rectrack'),
      informative: metadata.get('informative'),
      editorDraft: metadata.get('editorDraft'),
      processRules: metadata.get('processRules'),
      cfe: metadata.get('cfe')
    }
  }).then(function (out) {
    var response = out.response;
    var body = out.body;

    switch (response.statusCode) {
      case 501: return Promise.reject(new Error(body.message));
      case 400: return Promise.resolve(new List(body.errors));
      case 201: return Promise.resolve(new List());
      default:
        return Promise.reject(new Error(
          'There was an error when publishing: code ' + response.statusCode
        ));
    }
  });
};

module.exports = Publisher;
<commit_msg>send implementation report and due date to the backend<commit_after>'use strict';

var List = require('immutable').List;
var Map = require('immutable').Map;
var Moment = require('moment');
var Promise = require('promise');

/**
 * Pure function that publish a set of metadata to an external service.
 *
 * @exports lib/publisher
 * @param {Object} service - An object implementing a `post` function
 */
var Publisher = function (service) {
  if (typeof service !== 'object' || typeof service.post !== 'function') {
    throw new TypeError(
      'service must be defined and implement a post function'
    );
  }

  this.service = service;

  Object.freeze(this);
};

/**
 * Publish the set of metadata using a POSTable service.
 *
 * @param {Map.<string, *>} metadata - The metadata of the document to publish
 * @returns Promise.<Array.<String>> A list of publication errors for this set of metadata
 */
Publisher.prototype.publish = function (metadata) {
  if (!(metadata instanceof Map)) throw new TypeError('metadata must be a Map');
  return this.service.post({
    specversion: {
      status: metadata.get('profile'),
      uri: metadata.get('thisVersion'),
      latestVersionUri: metadata.get('latestVersion'),
      previousVersionUri: metadata.get('previousVersion'),
      date: new Moment(metadata.get('docDate'), 'YYYY-MM-DD')
              .format('YYYY-MM-DD'),
      title: metadata.get('title'),
      deliverers: metadata.get('delivererIDs'),
      editors: metadata.get('editors'),
      rectrack: metadata.get('rectrack'),
      informative: metadata.get('informative'),
      editorDraft: metadata.get('editorDraft'),
      processRules: metadata.get('processRules'),
      implementationReport: metadata.get('implementationReport'),
      implementationFeedbackDue: new Moment(metadata.get('implementationFeedbackDue', 'YYYY-MM-DD')
              .format('YYYY-MM-DD'),
      cfe: metadata.get('cfe')
    }
  }).then(function (out) {
    var response = out.response;
    var body = out.body;

    switch (response.statusCode) {
      case 501: return Promise.reject(new Error(body.message));
      case 400: return Promise.resolve(new List(body.errors));
      case 201: return Promise.resolve(new List());
      default:
        return Promise.reject(new Error(
          'There was an error when publishing: code ' + response.statusCode
        ));
    }
  });
};

module.exports = Publisher;

{'fraction_non_alphanumeric': 0.13604701784936873, 'fraction_numerical': 0.00391815411406182, 'mean_word_length': 3.4916911045943304, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2079914', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1265, 'n_words': 373}