<commit_before>
// Show commands in textarea
function updateCommands() {
    var value = "";
    // Configure git
    if (user.name.changed() && user.name.isValid()) {
        value += "git config --global user.name \"" + user.get("name") + "\"\n";
    }
    if (user.email.changed() && user.email.isValid()) {
        value += "git config --global user.email " + user.get("email") + "\n";
    }
    // Create public/private SSH keypair
    if (!user.key.isValid()) {
        value += "printf \"\\n\" | ssh-keygen -t rsa -N ''\n"
    }
    // Enter home directory
    value += "cd ~";
    // Create repository
    if ($("#cloned").val() != "true") {
        value += "\ngit init " + model.repo();
    }
    // Enter repository
    value += "\ncd " + model.repo();
    // Configure upstream
    if (!model.hasRemote('upstream')) {
        value += "\ngit remote add upstream \\";
        value += "\n" + model.upstream() + ".git";
    }
    if (Bitbucket.existingUser() && !model.hasRemote('bitbucket')) {
        value += "\ngit remote add bitbucket \\";
        value += "\<EMAIL>:" + ((Bitbucket.getUsername() == null) ? user.get("login") : Bitbucket.getUsername()) + "/" + model.repo() + ".git";
    }
    // Add origin
    var origin = host.getOrigin();
    if (origin && !model.hasRemote('origin')) {
        value += "\ngit remote add origin \\";
        value += "\ngit@" + origin.getHostname() + ":" + ((origin.getUsername() == null) ? user.get("login") : origin.getUsername()) + "/" + model.repo() + ".git";
    }
    
    // Configure remotes
    for (var key in Gitlab.collaborators) {
        if (!model.hasRemote(key + "-gitlab")) {
            value += "\ngit remote add " + key + "-gitlab \\\<EMAIL>:" + key + "/" + model.repo().toLowerCase() + ".git";
        }
    }
    for (var key in Github.collaborators) {
        if (!model.hasRemote(key + "-github")) {
            value += "\ngit remote add " + key + "-github \\\<EMAIL>:" + key + "/" + model.repo() + ".git";
        }
    }
    // Fetch everything
    value += "\ngit fetch --all";
    value += "\ngit merge upstream/master";
    value += "\ngit submodule update --init --recursive < /dev/null"
    // Push to origin
    if (origin) {
        value += "\ngit push -u origin master\n";
    }
    $("#command-line").val(value);
}

// Quick and dirty: get the platform (operating system)
// Courtesy: http://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript
function getPlatform() {
    var platform="unknown";
    if (navigator.appVersion.indexOf("Win")!=-1) platform="windows";
    if (navigator.appVersion.indexOf("Mac")!=-1) platform="mac";
    if (navigator.appVersion.indexOf("X11")!=-1) platform="linux";
    if (navigator.appVersion.indexOf("Linux")!=-1) platform="linux";
    return platform;
}

function showPlatform() {
    $(".unknown").hide();
    $(".windows").hide();
    $(".mac").hide();
    $(".linux").hide();
    $("." + getPlatform()).show();
}

// Validate profile, outlining broken fields in red
function validateUser() {
    var fields = [ user.name, user.email, user.key, user.gravatar ];
    var id = [ "#name", "#email", "#public-key", "#gravatar" ];
    var i;
    var allValid = true;
    for (i = 0; i < fields.length; i++) {
        if (fields[i].isValid()) {
            $(id[i]).removeAttr('style');
            allValid = false;
        }
        else {
            $(id[i]).css('border-color','red');
        }
    }
    return allValid;
}

// Setup all accounts
function setupAccounts() {
    var hosts = [ Github, Gitlab ];
    var settings = {
        title: user.get("login") + "@" + user.get("host"),
        key: user.get("key"),
        name: user.get("name"),
        email: user.get("email"),
        callback: controller.update,
    };
    for (var i = 0; i < hosts.length; i++) {
        hosts[i].setupAccount(settings);
    }
}

function updateView(event) {
    validateUser();
    setupAccounts();

    // Gravatar
    $("#gravatar").attr('src', 'http://www.gravatar.com/avatar/' + user.gravatar.value() + '?d=retro&s=140');
    user.gravatar.checkValid(function(status) {
        controller.update('gravatar-account',status);
    });

    // Don't allow sign-in unless their email is valid
    $("#github-signin").prop("disabled", !user.email.isValid());
    $("#gitlab-signin").prop("disabled", !user.email.isValid());
//    $("#bitbucket-signin").prop("disabled", !user.email.isValid());

    // Update repository URLs
    if (Github.existingUser()) {
        $('#github-login').text(Github.getUsername());
        $(".github-repo-href").attr("href", Github.repoURL());
        $("#github-collaborator-href").attr("href", Github.repoURL() + "/settings/collaboration");
        $("#github-private-href").attr("href", Github.repoURL() + "/settings");
    }
    if (Gitlab.existingUser()) {
        $('#gitlab-login').text(Gitlab.getUsername());
        $(".gitlab-repo-href").attr("href", Gitlab.repoURL());
        $("#gitlab-collaborator-href").attr("href", Gitlab.repoURL() + "/project_members");
        $("#gitlab-private-href").attr("href", Gitlab.repoURL() + "/edit");
    }
    if (Bitbucket.existingUser()) {
        controller.update('bitbucket-repository', true);
        $("#bitbucket-user").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/");
        $("#bitbucket-email").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/email/");
        $("#bitbucket-ssh").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/ssh-keys/");
        $(".bitbucket-repo-href").attr("href", Bitbucket.repoURL());
        $("#bitbucket-collaborator-href").attr("href", Bitbucket.repoURL() + "/admin/access");
        $("#bitbucket-private-href").attr("href", Bitbucket.repoURL() + "/admin");
    }
    Github.getCollaborators({
        page: 1,
        success: function(collaborators) {
            for (var key in collaborators) {
                $("#repositories").append("<li><i class=\"fa fa-li fa-lg fa-github\"></i><a id=\"github-collaborator-"+ key +"\" href=\"https://github.com/"+ key + "/" + model.repo() + "\" target=\"_blank\">" + collaborators[key] + "'s repository</a></li>");
            }
            updateCommands();
        },
        callback: function(key, value) {
            $("#github-collaborator-" + key).text(value + "'s repository");
        },
        fail: function() {}
    });
    Gitlab.getCollaborators({
        success: function(collaborators) {
            for (var key in collaborators) {
                $("#repositories").append("<li><i class=\"fa fa-li fa-lg fa-git-square\"></i><a href=\"https://gitlab.com/"+ key + "/" + model.repo() + "\" target=\"_blank\">" + collaborators[key] + "'s repository</a></li>");
            }
            updateCommands();
        },
        fail: function() {}
    });
    
    updateCommands();
};

$( "#name" ).on( "change", updateView );
$( "#email" ).on( "change", updateView );
$( "#github-password" ).on( "change", updateView );
$( "#gitlab-password" ).on( "change", updateView );<commit_msg>Fixed another broken gitlab link.<commit_after>
// Show commands in textarea
function updateCommands() {
    var value = "";
    // Configure git
    if (user.name.changed() && user.name.isValid()) {
        value += "git config --global user.name \"" + user.get("name") + "\"\n";
    }
    if (user.email.changed() && user.email.isValid()) {
        value += "git config --global user.email " + user.get("email") + "\n";
    }
    // Create public/private SSH keypair
    if (!user.key.isValid()) {
        value += "printf \"\\n\" | ssh-keygen -t rsa -N ''\n"
    }
    // Enter home directory
    value += "cd ~";
    // Create repository
    if ($("#cloned").val() != "true") {
        value += "\ngit init " + model.repo();
    }
    // Enter repository
    value += "\ncd " + model.repo();
    // Configure upstream
    if (!model.hasRemote('upstream')) {
        value += "\ngit remote add upstream \\";
        value += "\n" + model.upstream() + ".git";
    }
    if (Bitbucket.existingUser() && !model.hasRemote('bitbucket')) {
        value += "\ngit remote add bitbucket \\";
        value += "\<EMAIL>:" + ((Bitbucket.getUsername() == null) ? user.get("login") : Bitbucket.getUsername()) + "/" + model.repo() + ".git";
    }
    // Add origin
    var origin = host.getOrigin();
    if (origin && !model.hasRemote('origin')) {
        value += "\ngit remote add origin \\";
        value += "\ngit@" + origin.getHostname() + ":" + ((origin.getUsername() == null) ? user.get("login") : origin.getUsername()) + "/" + model.repo() + ".git";
    }
    
    // Configure remotes
    for (var key in Gitlab.collaborators) {
        if (!model.hasRemote(key + "-gitlab")) {
            value += "\ngit remote add " + key + "-gitlab \\\<EMAIL>:" + key + "/" + model.repo().toLowerCase() + ".git";
        }
    }
    for (var key in Github.collaborators) {
        if (!model.hasRemote(key + "-github")) {
            value += "\ngit remote add " + key + "-github \\\<EMAIL>:" + key + "/" + model.repo() + ".git";
        }
    }
    // Fetch everything
    value += "\ngit fetch --all";
    value += "\ngit merge upstream/master";
    value += "\ngit submodule update --init --recursive < /dev/null"
    // Push to origin
    if (origin) {
        value += "\ngit push -u origin master\n";
    }
    $("#command-line").val(value);
}

// Quick and dirty: get the platform (operating system)
// Courtesy: http://stackoverflow.com/questions/11219582/how-to-detect-my-browser-version-and-operating-system-using-javascript
function getPlatform() {
    var platform="unknown";
    if (navigator.appVersion.indexOf("Win")!=-1) platform="windows";
    if (navigator.appVersion.indexOf("Mac")!=-1) platform="mac";
    if (navigator.appVersion.indexOf("X11")!=-1) platform="linux";
    if (navigator.appVersion.indexOf("Linux")!=-1) platform="linux";
    return platform;
}

function showPlatform() {
    $(".unknown").hide();
    $(".windows").hide();
    $(".mac").hide();
    $(".linux").hide();
    $("." + getPlatform()).show();
}

// Validate profile, outlining broken fields in red
function validateUser() {
    var fields = [ user.name, user.email, user.key, user.gravatar ];
    var id = [ "#name", "#email", "#public-key", "#gravatar" ];
    var i;
    var allValid = true;
    for (i = 0; i < fields.length; i++) {
        if (fields[i].isValid()) {
            $(id[i]).removeAttr('style');
            allValid = false;
        }
        else {
            $(id[i]).css('border-color','red');
        }
    }
    return allValid;
}

// Setup all accounts
function setupAccounts() {
    var hosts = [ Github, Gitlab ];
    var settings = {
        title: user.get("login") + "@" + user.get("host"),
        key: user.get("key"),
        name: user.get("name"),
        email: user.get("email"),
        callback: controller.update,
    };
    for (var i = 0; i < hosts.length; i++) {
        hosts[i].setupAccount(settings);
    }
}

function updateView(event) {
    validateUser();
    setupAccounts();

    // Gravatar
    $("#gravatar").attr('src', 'http://www.gravatar.com/avatar/' + user.gravatar.value() + '?d=retro&s=140');
    user.gravatar.checkValid(function(status) {
        controller.update('gravatar-account',status);
    });

    // Don't allow sign-in unless their email is valid
    $("#github-signin").prop("disabled", !user.email.isValid());
    $("#gitlab-signin").prop("disabled", !user.email.isValid());
//    $("#bitbucket-signin").prop("disabled", !user.email.isValid());

    // Update repository URLs
    if (Github.existingUser()) {
        $('#github-login').text(Github.getUsername());
        $(".github-repo-href").attr("href", Github.repoURL());
        $("#github-collaborator-href").attr("href", Github.repoURL() + "/settings/collaboration");
        $("#github-private-href").attr("href", Github.repoURL() + "/settings");
    }
    if (Gitlab.existingUser()) {
        $('#gitlab-login').text(Gitlab.getUsername());
        $(".gitlab-repo-href").attr("href", Gitlab.repoURL());
        $("#gitlab-collaborator-href").attr("href", Gitlab.repoURL() + "/project_members");
        $("#gitlab-private-href").attr("href", Gitlab.repoURL() + "/edit");
    }
    if (Bitbucket.existingUser()) {
        controller.update('bitbucket-repository', true);
        $("#bitbucket-user").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/");
        $("#bitbucket-email").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/email/");
        $("#bitbucket-ssh").attr("href", "https://bitbucket.org/account/user/" + Bitbucket.getUsername() + "/ssh-keys/");
        $(".bitbucket-repo-href").attr("href", Bitbucket.repoURL());
        $("#bitbucket-collaborator-href").attr("href", Bitbucket.repoURL() + "/admin/access");
        $("#bitbucket-private-href").attr("href", Bitbucket.repoURL() + "/admin");
    }
    Github.getCollaborators({
        page: 1,
        success: function(collaborators) {
            for (var key in collaborators) {
                $("#repositories").append("<li><i class=\"fa fa-li fa-lg fa-github\"></i><a id=\"github-collaborator-"+ key +"\" href=\"https://github.com/"+ key + "/" + model.repo() + "\" target=\"_blank\">" + collaborators[key] + "'s repository</a></li>");
            }
            updateCommands();
        },
        callback: function(key, value) {
            $("#github-collaborator-" + key).text(value + "'s repository");
        },
        fail: function() {}
    });
    Gitlab.getCollaborators({
        success: function(collaborators) {
            for (var key in collaborators) {
                $("#repositories").append("<li><i class=\"fa fa-li fa-lg fa-git-square\"></i><a href=\"https://gitlab.com/"+ key + "/" + model.repo().toLowerCase() + "\" target=\"_blank\">" + collaborators[key] + "'s repository</a></li>");
            }
            updateCommands();
        },
        fail: function() {}
    });
    
    updateCommands();
};

$( "#name" ).on( "change", updateView );
$( "#email" ).on( "change", updateView );
$( "#github-password" ).on( "change", updateView );
$( "#gitlab-password" ).on( "change", updateView );
{'fraction_non_alphanumeric': 0.21717877094972068, 'fraction_numerical': 0.002793296089385475, 'mean_word_length': 2.6430933604680744, 'pattern_counts': {'":': 2, '<': 39, '<?xml version=': 0, '>': 33, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, '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': '989986', 'n_tokens_mistral': 4474, 'n_tokens_neox': 4451, 'n_words': 874}