<commit_before>"use strict";

ckan.module('post_related_gist', function ($, _) {
    return {
        initialize: function () {
            $.proxyAll(this, /_on/);
            this.el.on('click', this._onClick);
        },

        _onClick: function(event) {
            var editor = ace.edit("editor_div");
            this.options.gistdesc = $('#gist-description').val();
            if (this.options.gistdesc == ''){
                var outhtml = '<h3><font color="red">Fill in description field.</font></h3>';
                $('#ace_output').html(outhtml);
                $('#gist-description').focus();
                return;
            }
            var textgist = editor.getSession().getValue();
            $('#ace_output').html('<div id="loader"><img src="/loader.gif" alt="loading..."></div>');
            var apiurl   = 'https://github.cfpb.gov/api/v3/gists';
            
            this._postGIST(apiurl,textgist, function(json) {
                if (!("html_url" in json)){
                    $('#ace_output').html("<h2>GitHub post failed</h2><br>",json);
                }else {
                    this.options.gistlink = json.html_url;
                    var outhtml = '<h3>Posted a <a href="'+json.html_url+'">Gist</a></h3>';
                    $('#ace_output').html(outhtml);
                    var option = $('<option></option>').attr("value", Encoder.htmlEncode(this.options.gistlink)).text(this.options.gistdesc);
                    $('#gistselect').append(option); 
                    
                    if (!this._snippetReceived) {
                        this.sandbox.client.getTemplate(this.options.html,
                                                        this.options,
                                                        null);
                        this._snippetReceived = true;
                    }
                } 
            });
        },

        _postGIST: function(apiurl, basecontent, callback) {
            var mythis=this; // code review?
            var description = mythis.options.gistdesc;
            var ext = $.parseJSON($('#gistType').val());
            ext = ext.ext;
            var fp= "file."+ext;
            var filedata = {"description": description, "public": true,
                            "files": {"file" : {"filename" : fp, "content": basecontent}}}; <commit_msg>adds error on no github access, and gist resource name for unnamed<commit_after>"use strict";

ckan.module('post_related_gist', function ($, _) {
    return {
        initialize: function () {
            $.proxyAll(this, /_on/);
            this.el.on('click', this._onClick);
        },

        _onClick: function(event) {
            var editor = ace.edit("editor_div");
            this.options.gistdesc = $('#gist-description').val();
            if (this.options.gistdesc == ''){
                var outhtml = '<h3><font color="red">Fill in description field.</font></h3>';
                $('#ace_output').html(outhtml);
                $('#gist-description').focus();
                return;
            }
            if (this.options.resource_name == true){
                // module change '' to  true so this corresponds to an unnamed resource
                this.options.resource_name = 'Unnamed'; 
            }
            var textgist = editor.getSession().getValue();
            $('#ace_output').html('<div id="loader"><img src="/loader.gif" alt="loading..."></div>');
            var apiurl   = 'https://github.cfpb.gov/api/v3/gists';
            
            this._postGIST(apiurl,textgist, function(json) {
                if (!json) {
                    $('#ace_output').html("<h2>GitHub failed to connect</h2><br>");
                }else if (!("html_url" in json)){
                    $('#ace_output').html("<h2>GitHub post failed</h2><br>",json);
                }else {
                    this.options.gistlink = json.html_url;
                    var outhtml = '<h4>Posted a <a href="'+json.html_url+'">Gist</a></h4>';
                    $('#ace_output').html(outhtml);
                    var option = $('<option></option>').attr("value", Encoder.htmlEncode(this.options.gistlink)).text(this.options.gistdesc);
                    $('#gistselect').append(option); 
                    
                    if (!this._snippetReceived) {
                        this.sandbox.client.getTemplate(this.options.html,
                                                        this.options,
                                                        null);
                        this._snippetReceived = true;
                    }
                } 
            });
        },

        _postGIST: function(apiurl, basecontent, callback) {
            var mythis=this; // code review?
            var description = mythis.options.gistdesc;
            var ext = $.parseJSON($('#gistType').val());
            ext = ext.ext;
            var fp= "file."+ext;
            var filedata = {"description": description, "public": true,
                            "files": {"file" : {"filename" : fp, "content": basecontent}}}; 
{'fraction_non_alphanumeric': 0.15509803921568627, 'fraction_numerical': 0.003137254901960784, 'mean_word_length': 1.4798249878463783, 'pattern_counts': {'":': 8, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6812268', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1316, 'n_words': 238}