<commit_before>window.jobStatusNotifier = (function(){

    function _constructJobStatusQueryUrl(items){
        var serverUrl = items['serverUrl'];
        var jobName = items['jobName'];

        return "http://" + serverUrl + "/job/" + jobName + "/api/json?depth=0";
    }

    function _hasCurrentJobRunFailed(currentJobColor){
        return currentJobColor != 'blue' && currentJobColor != 'blue_anime';
    }

    function _getJobStatus(currentJobColor){
        if(currentJobColor == 'blue')
            return 'success';
        else if(currentJobColor == 'blue_anime')
            return 'success_building';
        else
            return 'failure';
    }

    function _queryJobStatus(queryParams, postQueryCallback){
        var url = _constructJobStatusQueryUrl(queryParams);

        $.ajax({
            type: "GET",
            url: url,
            dataType: "json",
            headers: {
                "Authorization": "Basic " + window.btoa(queryParams.userName + ":" + queryParams.apiKey)
            }
        }).done(function(response){
            var hasLatestRunFailed = _hasCurrentJobRunFailed(response['color']);
            var jobName = response['displayName'];
            var imagePath = hasLatestRunFailed ? "../images/red_info.png": "../images/green_info.png";
            postQueryCallback({
                jobName: jobName,
                isLatestRunSuccessful: !hasLatestRunFailed,
                imagePath: imagePath,
                jobStatus: _getJobStatus(response['color'])
            });
        });
    }

    function getConfiguredJobsStatuses(postQueryCallback){
        chrome.storage.sync.get({
             serverUrl: null,
             userName: null,
             apiKey: null,
             jobs: null
        }, function(items){
            var jobList = items['jobs'];
            var jobs = jobList.split(",");
            $.each(jobs, function(index, job){
                var queryParams = {
                    userName: items['userName'],
                    apiKey: items['apiKey'],
                    serverUrl: items['serverUrl'],
                    jobName: job
                };
                _queryJobStatus(queryParams, postQueryCallback);
            });

        });

    }

    function _alarmEventHandler(){
        var _createNotificationHandler = function(jobResult){
            var statusMessage = jobResult.isLatestRunSuccessful ? " is Green" : " is Red";

            console.log(jobResult.jobName + " last run successful: " + jobResult.isLatestRunSuccessful);

            !jobResult.isLatestRunSuccessful && chrome.notifications.create(jobResult.jobName, {
                type: "basic",
                title: jobResult.jobName,
                message: jobResult.jobName + statusMessage,
                iconUrl: jobResult.imagePath
            }, function(notificationId){
                console.log("Created notification with id:" + notificationId);
            });

        };
        getConfiguredJobsStatuses(_createNotificationHandler);
    }

    function checkAndInitializeAlarm(){
        chrome.alarms.clear("jobStatusTimer");
        chrome.alarms.onAlarm.removeListener(_alarmListener);

        chrome.storage.sync.get({
             pollingFrequency: "1",
             enableNotifications: false
        }, function(result){
                if(!result['enableNotifications']){
                    console.log("Notifications not enabled.");
                    return;
                }

                var pollingFrequencyInMinutes = parseFloat(result['pollingFrequency']);
                chrome.alarms.create("jobStatusTimer", {
                            delayInMinutes: pollingFrequencyInMinutes,
                            periodInMinutes: pollingFrequencyInMinutes
                });
                _initializeAlarmEventHandler();
           });

    }

    function _initializeAlarmEventHandler(){
        chrome.alarms.onAlarm.addListener(_alarmListener);
    }

    function _alarmListener(alarm){
        console.log("Alarm triggered!");
        if(alarm.name != 'jobStatusTimer'){
            console.log("Skipping unwanted alarm event");
            return;
        }
        _alarmEventHandler();
    }

    return {
        checkAndInitializeAlarm: checkAndInitializeAlarm,
        getConfiguredJobStatuses: getConfiguredJobsStatuses
    };
}());<commit_msg>Create notifications with unique id - for some reason reusing id causes notifications not to show up<commit_after>window.jobStatusNotifier = (function(){

    function _constructJobStatusQueryUrl(items){
        var serverUrl = items['serverUrl'];
        var jobName = items['jobName'];

        return "http://" + serverUrl + "/job/" + jobName + "/api/json?depth=0";
    }

    function _hasCurrentJobRunFailed(currentJobColor){
        return currentJobColor != 'blue' && currentJobColor != 'blue_anime';
    }

    function _getJobStatus(currentJobColor){
        if(currentJobColor == 'blue')
            return 'success';
        else if(currentJobColor == 'blue_anime')
            return 'success_building';
        else
            return 'failure';
    }

    function _queryJobStatus(queryParams, postQueryCallback){
        var url = _constructJobStatusQueryUrl(queryParams);

        $.ajax({
            type: "GET",
            url: url,
            dataType: "json",
            headers: {
                "Authorization": "Basic " + window.btoa(queryParams.userName + ":" + queryParams.apiKey)
            }
        }).done(function(response){
            var hasLatestRunFailed = _hasCurrentJobRunFailed(response['color']);
            var jobName = response['displayName'];
            var imagePath = hasLatestRunFailed ? "../images/red_info.png": "../images/green_info.png";
            postQueryCallback({
                jobName: jobName,
                isLatestRunSuccessful: !hasLatestRunFailed,
                imagePath: imagePath,
                jobStatus: _getJobStatus(response['color'])
            });
        });
    }

    function getConfiguredJobsStatuses(postQueryCallback){
        chrome.storage.sync.get({
             serverUrl: null,
             userName: null,
             apiKey: null,
             jobs: null
        }, function(items){
            var jobList = items['jobs'];
            var jobs = jobList.split(",");
            $.each(jobs, function(index, job){
                var queryParams = {
                    userName: items['userName'],
                    apiKey: items['apiKey'],
                    serverUrl: items['serverUrl'],
                    jobName: job
                };
                _queryJobStatus(queryParams, postQueryCallback);
            });

        });

    }

    function _alarmEventHandler(){
        var _createNotificationHandler = function(jobResult){
            var statusMessage = jobResult.isLatestRunSuccessful ? " is Green" : " is Red";

            console.log(jobResult.jobName + " last run successful: " + jobResult.isLatestRunSuccessful);

            !jobResult.isLatestRunSuccessful && chrome.notifications.create("", {
                type: "basic",
                title: jobResult.jobName,
                message: jobResult.jobName + statusMessage,
                iconUrl: jobResult.imagePath
            }, function(notificationId){
                console.log("Created notification with id:" + notificationId);
            });

        };
        getConfiguredJobsStatuses(_createNotificationHandler);
    }

    function checkAndInitializeAlarm(){
        chrome.alarms.clear("jobStatusTimer");
        chrome.alarms.onAlarm.removeListener(_alarmListener);

        chrome.storage.sync.get({
             pollingFrequency: "1",
             enableNotifications: false
        }, function(result){
                if(!result['enableNotifications']){
                    console.log("Notifications not enabled.");
                    return;
                }

                var pollingFrequencyInMinutes = parseFloat(result['pollingFrequency']);
                chrome.alarms.create("jobStatusTimer", {
                            delayInMinutes: pollingFrequencyInMinutes,
                            periodInMinutes: pollingFrequencyInMinutes
                });
                _initializeAlarmEventHandler();
           });

    }

    function _initializeAlarmEventHandler(){
        chrome.alarms.onAlarm.addListener(_alarmListener);
    }

    function _alarmListener(alarm){
        console.log("Alarm triggered!");
        if(alarm.name != 'jobStatusTimer'){
            console.log("Skipping unwanted alarm event");
            return;
        }
        _alarmEventHandler();
    }

    return {
        checkAndInitializeAlarm: checkAndInitializeAlarm,
        getConfiguredJobStatuses: getConfiguredJobsStatuses
    };
}());
{'fraction_non_alphanumeric': 0.10502489814395655, 'fraction_numerical': 0.0004526935264825713, 'mean_word_length': 1.936856098371552, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '7082426', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2174, 'n_words': 391}