<commit_before>chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {

    chrome.storage.sync.get({
        server: '',
        projectId: null,
        issueTypeId: null
    }, function(configuration) {
        let server = configuration.server;

        if (!(server && configuration.projectId && configuration.issueTypeId)) {
            chrome.runtime.openOptionsPage();
            return sendResponse(JSON.stringify({
                error: 'Server not defined',
                showSettings: true
            }));
        }

        server = server.replace(/\/$/, "");

        const method = {
            getTicket: function(parameter) {

                const jql = 'summary ~ "\\"' + parameter.summary + '\\""';

                fetch(server + '/rest/api/2/search?jql=' + jql + '&maxResults=1', {
                    credentials: 'include'
                })
                .then(response => response.json())
                .then(json => {
                    debugger;

                    if (json.total >= 1) {
                        sendResponse({
                            meta: {
                                server: server,
                                issue: json.issues[0].key
                            }
                        });
                    } else {
                        sendResponse({
                            meta: {
                                server: server,
                                issue: undefined
                            }
                        });
                    }
                })
                .catch(err => {
                    sendResponse(JSON.stringify({
                        error: err
                    }))
                });

            },
            createIssue: function(parameter) {

                var xhr = new XMLHttpRequest();

                xhr.open('POST', server + '/rest/api/2/issue/', true);
                xhr.setRequestHeader('Content-Type', 'application/json');

                xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 201) {
                            var jiraData = JSON.parse(xhr.responseText);
                            jiraData["meta"] = {
                                server: server,
                                projectId: jiraData.projectId,
                                issueTypeId: jiraData.issueTypeId
                            };

                            sendResponse(jiraData);

                            if (parameter.screenshot) {
                                attachScreenshot(jiraData.key, parameter.screenshot);
                            }

                            if (parameter.har) {
                                attachHar(jiraData.key, parameter.har);
                            }

                        } else {
                            sendResponse({
                                error: xhr.responseText || xhr.status || true
                            });
                        }
                    }
                };

                const fields = {
                    project: {
                        key: configuration.projectId
                    },
                    summary: parameter.summary,
                    description: parameter.description,
                    issuetype: {
                        id: configuration.issueTypeId
                    }
                };

                const component = parameter.component;
                if (component) {
                    fields.components = [{
                        name: component
                    }];
                }

                xhr.send(JSON.stringify({
                    fields: fields
                }));


                function attachData(blob, fileName, issueId) {

                    var xhr = new XMLHttpRequest();
                    xhr.open('POST', server + '/rest/api/2/issue/' + issueId + '/attachments', true);
                    xhr.setRequestHeader('X-Atlassian-Token', '<PASSWORD>');

                    var formData = new FormData();
                    formData.append("file", blob, fileName);

                    xhr.send(formData);
                }

                function attachScreenshot(issueId, screenshot) {
                    attachData(base64toBlob(screenshot.replace(/^data.*?,\s*/i, ""), "image/png"), "screenshot.png", issueId);
                }

                function attachHar(issueId, harFile) {

                    var xhr = new XMLHttpRequest();
                    xhr.open("GET", harFile, true);
                    xhr.responseType = "arraybuffer";

                    xhr.onload = function() {<commit_msg>assign ticket directly to creator<commit_after>chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {

    chrome.storage.sync.get({
        server: '',
        projectId: null,
        issueTypeId: null,
        user: null
    }, function(configuration) {
        let server = configuration.server;

        if (!(server && configuration.projectId && configuration.issueTypeId)) {
            chrome.runtime.openOptionsPage();
            return sendResponse(JSON.stringify({
                error: 'Server not defined',
                showSettings: true
            }));
        }

        server = server.replace(/\/$/, "");

        const method = {
            getTicket: function(parameter) {

                const jql = 'summary ~ "\\"' + parameter.summary + '\\""';

                fetch(server + '/rest/api/2/search?jql=' + jql + '&maxResults=1', {
                    credentials: 'include'
                })
                .then(response => response.json())
                .then(json => {
                    debugger;

                    if (json.total >= 1) {
                        sendResponse({
                            meta: {
                                server: server,
                                issue: json.issues[0].key
                            }
                        });
                    } else {
                        sendResponse({
                            meta: {
                                server: server,
                                issue: undefined
                            }
                        });
                    }
                })
                .catch(err => {
                    sendResponse(JSON.stringify({
                        error: err
                    }))
                });

            },
            createIssue: function(parameter) {

                var xhr = new XMLHttpRequest();

                xhr.open('POST', server + '/rest/api/2/issue/', true);
                xhr.setRequestHeader('Content-Type', 'application/json');

                xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 201) {
                            var jiraData = JSON.parse(xhr.responseText);
                            jiraData["meta"] = {
                                server: server,
                                projectId: jiraData.projectId,
                                issueTypeId: jiraData.issueTypeId
                            };

                            sendResponse(jiraData);

                            if (parameter.screenshot) {
                                attachScreenshot(jiraData.key, parameter.screenshot);
                            }

                            if (parameter.har) {
                                attachHar(jiraData.key, parameter.har);
                            }

                        } else {
                            sendResponse({
                                error: xhr.responseText || xhr.status || true
                            });
                        }
                    }
                };

                var postIssue = function() {
                const fields = {
                    project: {
                        key: configuration.projectId
                    },
                    summary: parameter.summary,
                    description: parameter.description,
                    issuetype: {
                        id: configuration.issueTypeId
                        },
                        assignee: {
                            name: configuration.user
                    }
                };

                const component = parameter.component;
                if (component) {
                    fields.components = [{
                        name: component
                    }];
                }

                xhr.send(JSON.stringify({
                    fields: fields
                }));

                };

                if (configuration.user === null) {
                    fetch(server + '/rest/auth/latest/session', {
                        credentials: 'include'
                    })
                        .then(response => response.json())
                        .then(json => {
                            configuration.user = json.name;
                            postIssue();
                        });
                } else {
                    postIssue();
                }

                function attachData(blob, fileName, issueId) {

                    var xhr = new XMLHttpRequest();
                    xhr.open('POST', server + '/rest/api/2/issue/' + issueId + '/attachments', true);
                    xhr.setRequestHeader('X-Atlassian-Token', '<PASSWORD>');

                    var formData = new FormData();
                    formData.append("file", blob, fileName);

                    xhr.send(formData);
                }

                function attachScreenshot(issueId, screenshot) {
                    attachData(base64toBlob(screenshot.replace(/^data.*?,\s*/i, ""), "image/png"), "screenshot.png", issueId);
                }

                function attachHar(issueId, harFile) {

                    var xhr = new XMLHttpRequest();
                    xhr.open("GET", harFile, true);
                    xhr.responseType = "arraybuffer";

                    xhr.onload = function() {
{'fraction_non_alphanumeric': 0.09931640625, 'fraction_numerical': 0.00234375, 'mean_word_length': 0.8674325309992706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7409036', 'n_tokens_mistral': 2386, 'n_tokens_neox': 2137, 'n_words': 385}