package com.saltstack.jenkins

import groovy.json.*
import java.util.logging.Level
import java.util.logging.Logger

class PushHooksRecorder {

    def cachefile;
    private static final Logger LOGGER = Logger.getLogger(Project.class.getName());

    PushHooksRecorder(build) {
        this.cachefile = build.getWorkspace().child('push-hooks.cache')
    }

    def load() {
        try {
            return new JsonSlurper().parseText(this.cachefile.readToString())
        } catch (Throwable e) {
            return [:]
        }
    }

    def record(project_name, job_name) {
        LOGGER.log(Level.INFO, "Recording job name '${job_name}' for project '${project_name}'")
        data = load()
        if ( ! data.contains(project_name) ) {
            data[project_name] = new HashSet()
        }
        data[project_name].add(job_name)
        this.cachefile.write(new JsonBuilder(data).toString(), 'UTF-8')
    }

}

package com.saltstack.jenkins

import groovy.json.*
import java.util.logging.Level
import java.util.logging.Logger

class PushHooksRecorder {

    def cachefile;
    private static final Logger LOGGER = Logger.getLogger(Project.class.getName());

    PushHooksRecorder(build) {
        this.cachefile = build.getWorkspace().child('push-hooks.cache')
    }

    def load() {
        try {
            return new JsonSlurper().parseText(this.cachefile.readToString()) as Set
        } catch (Throwable e) {
            return [] as Set
        }
    }

    def record(job_name) {
        data = load()
        data.add(job_name.split('/'))
        this.cachefile.write(new JsonBuilder(data).toString(), 'UTF-8')
    }

}

Revert "We now need the project name"
Revert "We now need the project name"

This reverts commit bee047729708eefaa647b2dfd2bc66303273a6d5.
