<commit_before>/* eslint new-cap: 0, no-loop-func: 0, max-nested-callbacks: [2, 2] */
/**
 * @module SeedGitRepository
 */
'use strict';

const NodeGit = require('nodegit');
const rimraf = require('rimraf');
const path = require('path');

const temporaryFolder = path.join(__dirname, 'temp');
const branchReference = 'refs/heads/master:refs/heads/master';

/**
 * Takes in a seed repository and a list of repositories to replicate to.
 * @function SeedGitRepository
 * @param {String} username - username for Git user
 * @param {String} password - password for Git <PASSWORD>
 * @param {String} seedRepositoryURL - remote Git url to use as seed for other repos
 * @param {Array} destinationRepositoryURLs - {Array} of {String} with repository URLs
 * @returns {Promise} promise will resolve when all repos have been seeded
 */
module.exports = function (username, password, seedRepositoryURL, destinationRepositoryURLs) {
    const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);

    // clear temporary folder
    return rmrf(temporaryFolder)
        // clone repository to temporary folder
        .then(function () {
            return NodeGit.Clone(seedRepositoryURL, temporaryFolder);
        })
        // open the repository
        .then(function () {
            return NodeGit.Repository.open(temporaryFolder);
        })
        // push the seed repository to all destination repositories
        .then(function (seedRepository) {
            const promises = [];

            // for each student
            for (let index = 0; index < destinationRepositoryURLs.length; index++) {
                // create a remote for destination
                NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
                // open remote for destination
                NodeGit.Remote.lookup(seedRepository, index.toString()).then(function (remote) {
                    // add Git authentication information
                    remote.setCallbacks({
                        credentials: function () {
                            return credentials;
                        }
                    });
                    // push to destination remote and collect resulting promise
                    promises.push(
                        remote.push([branchReference])
                    );
                });
            }<commit_msg>add credentials callback to clone<commit_after>/* eslint new-cap: 0, no-loop-func: 0, max-nested-callbacks: [2, 2] */
/**
 * @module SeedGitRepository
 */
'use strict';

const NodeGit = require('nodegit');
const rimraf = require('rimraf');
const path = require('path');

const temporaryFolder = path.join(__dirname, 'temp');
const branchReference = 'refs/heads/master:refs/heads/master';

/**
 * Takes in a seed repository and a list of repositories to replicate to.
 * @function SeedGitRepository
 * @param {String} username - username for Git user
 * @param {String} password - password for Git user
 * @param {String} seedRepositoryURL - remote Git url to use as seed for other repos
 * @param {Array} destinationRepositoryURLs - {Array} of {String} with repository URLs
 * @returns {Promise} promise will resolve when all repos have been seeded
 */
module.exports = function (username, password, seedRepositoryURL, destinationRepositoryURLs) {
    const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);

    // clear temporary folder
    return rmrf(temporaryFolder)
        // clone repository to temporary folder
        .then(function () {
            return NodeGit.Clone(seedRepositoryURL, temporaryFolder, {
                remoteCallbacks: {
                    credentials: function () {
                        return credentials;
                    }
                }
            });
        })
        // open the repository
        .then(function () {
            return NodeGit.Repository.open(temporaryFolder);
        })
        // push the seed repository to all destination repositories
        .then(function (seedRepository) {
            const promises = [];

            // for each student
            for (let index = 0; index < destinationRepositoryURLs.length; index++) {
                // create a remote for destination
                NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);
                // open remote for destination
                NodeGit.Remote.lookup(seedRepository, index.toString()).then(function (remote) {
                    // add Git authentication information
                    remote.setCallbacks({
                        credentials: function () {
                            return credentials;
                        }
                    });
                    // push to destination remote and collect resulting promise
                    promises.push(
                        remote.push([branchReference])
                    );
                });
            }
{'fraction_non_alphanumeric': 0.09474315410753548, 'fraction_numerical': 0.001998800719568259, 'mean_word_length': 2.0718232044198897, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '6340069', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1118, 'n_words': 363}