<commit_before>package net.nemerosa.ontrack.dsl

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import net.nemerosa.ontrack.dsl.doc.DSL
import net.nemerosa.ontrack.dsl.doc.DSLMethod
import net.nemerosa.ontrack.dsl.http.OTHttpClient
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity

/**
 * Entry point for the DSL.
 */
@DSL(value = "An Ontrack instance is usually bound to the `ontrack` identifier and is the root for all DSL calls.")
class Ontrack {

    /**
     * HTTP client
     */
    private final OTHttpClient httpClient
    private final JsonSlurper jsonSlurper = new JsonSlurper()

    /**
     * Construction of the Ontrack client, based on a raw HTTP client
     */
    Ontrack(OTHttpClient httpClient) {
        this.httpClient = httpClient
    }

    /**
     * Gets the list of projects
     */
    @DSLMethod("Gets the list of projects")
    List<Project> getProjects() {
        return get('structure/projects').resources
    }

    /**
     * Looks for a project by its name
     * @param name Name of the project
     * @return Project or null is not found
     */
    @DSLMethod("Finds a project using its name. Returns null if not found.")
    Project findProject(String name) {
        def projectNode = get("structure/projects").resources.find {
            it.name == name
        }
        if (projectNode) {
            return new Project(this, get(projectNode._self))
        } else {
            return null
        }
    }

    @DSLMethod(value = "Finds or creates a project.", id = "project", count = 2)
    Project project(String name, String description = '') {
        def project = findProject(name)
        if (project) {
            return project
        }
        // If it does not exist, creates it
        else {
            new Project(
                    this,
                    post(<commit_msg>#465 Removed redundant calls - we still need a project object<commit_after>package net.nemerosa.ontrack.dsl

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import net.nemerosa.ontrack.dsl.doc.DSL
import net.nemerosa.ontrack.dsl.doc.DSLMethod
import net.nemerosa.ontrack.dsl.http.OTHttpClient
import org.apache.http.entity.ContentType
import org.apache.http.entity.StringEntity

/**
 * Entry point for the DSL.
 */
@DSL(value = "An Ontrack instance is usually bound to the `ontrack` identifier and is the root for all DSL calls.")
class Ontrack {

    /**
     * HTTP client
     */
    private final OTHttpClient httpClient
    private final JsonSlurper jsonSlurper = new JsonSlurper()

    /**
     * Construction of the Ontrack client, based on a raw HTTP client
     */
    Ontrack(OTHttpClient httpClient) {
        this.httpClient = httpClient
    }

    /**
     * Gets the list of projects
     */
    @DSLMethod("Gets the list of projects")
    List<Project> getProjects() {
        return get('structure/projects').resources.collect {
            new Project(this, it)
        }
    }

    /**
     * Looks for a project by its name
     * @param name Name of the project
     * @return Project or null is not found
     */
    @DSLMethod("Finds a project using its name. Returns null if not found.")
    Project findProject(String name) {
        def projectNode = get("structure/projects").resources.find {
            it.name == name
        }
        if (projectNode) {
            return new Project(this, get(projectNode._self))
        } else {
            return null
        }
    }

    @DSLMethod(value = "Finds or creates a project.", id = "project", count = 2)
    Project project(String name, String description = '') {
        def project = findProject(name)
        if (project) {
            return project
        }
        // If it does not exist, creates it
        else {
            new Project(
                    this,
                    post(
{'fraction_non_alphanumeric': 0.092173017507724, 'fraction_numerical': 0.0012873326467559218, 'mean_word_length': 2.2213930348258706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7660652', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1088, 'n_words': 341}