<commit_before>package com.github.jk1.ytplugin.components

import com.github.jk1.ytplugin.NoActiveYouTrackTaskFoundException
import com.github.jk1.ytplugin.NoYouTrackRepositoryException
import com.github.jk1.ytplugin.TaskManagementDisabledException
import com.github.jk1.ytplugin.YouTrackRepositoryNotConfiguredException
import com.intellij.openapi.components.AbstractProjectComponent
import com.intellij.openapi.project.Project
import com.intellij.tasks.Task
import com.intellij.tasks.TaskManager
import com.intellij.tasks.TaskRepository
import com.intellij.tasks.impl.BaseRepository
import com.intellij.tasks.impl.BaseRepositoryImpl
import org.apache.commons.httpclient.HttpClient


class TaskManagerProxyComponentImpl(val project: Project) :
        AbstractProjectComponent(project), TaskManagerProxyComponent {

    override fun getActiveTask(): Task {
        val task = getTaskManager().activeTask
        if (task.isIssue && task.repository?.isYouTrack() ?: false) {
            return getTaskManager().activeTask
        } else {
            throw NoActiveYouTrackTaskFoundException()
        }
    }

    override fun getTaskManager(): TaskManager {
        return project.getComponent(TaskManager::class.java)
                ?: throw TaskManagementDisabledException()
    }

    override fun getYouTrackRepository(): BaseRepository {
        val repository = getTaskManager().allRepositories
                ?.filter { it.isYouTrack() }
                ?.firstOrNull() as BaseRepository?
                ?: throw NoYouTrackRepositoryException()
        if (repository.isConfigured) {
            return repository
        } else {
            throw YouTrackRepositoryNotConfiguredException()
        }
    }

    override fun getRestClient(): HttpClient {
        // dirty hack to get preconfigured http client from task management plugin
        // we don't want to handle all the connection/testing/proxy stuff ourselves
        val method = BaseRepositoryImpl::class.java.getDeclaredMethod("getHttpClient")
        method.isAccessible = true
        return method.invoke(getYouTrackRepository()) as HttpClient
    }

    private fun TaskRepository.isYouTrack() = this.javaClass.name.contains("youtrack", true)
}<commit_msg>task-based repository discovery<commit_after>package com.github.jk1.ytplugin.components

import com.github.jk1.ytplugin.NoActiveYouTrackTaskFoundException
import com.github.jk1.ytplugin.TaskManagementDisabledException
import com.github.jk1.ytplugin.YouTrackRepositoryNotConfiguredException
import com.intellij.openapi.components.AbstractProjectComponent
import com.intellij.openapi.project.Project
import com.intellij.tasks.Task
import com.intellij.tasks.TaskManager
import com.intellij.tasks.TaskRepository
import com.intellij.tasks.impl.BaseRepository
import com.intellij.tasks.impl.BaseRepositoryImpl
import org.apache.commons.httpclient.HttpClient


class TaskManagerProxyComponentImpl(val project: Project) :
        AbstractProjectComponent(project), TaskManagerProxyComponent {

    override fun getActiveTask(): Task {
        val task = getTaskManager().activeTask
        if (task.isIssue && task.repository?.isYouTrack() ?: false) {
            return getTaskManager().activeTask
        } else {
            throw NoActiveYouTrackTaskFoundException()
        }
    }

    override fun getTaskManager(): TaskManager {
        return project.getComponent(TaskManager::class.java)
                ?: throw TaskManagementDisabledException()
    }

    override fun getYouTrackRepository(): BaseRepository {
        val repository = getActiveTask().repository as BaseRepository
        if (repository.isConfigured) {
            return repository
        } else {
            throw YouTrackRepositoryNotConfiguredException()
        }
    }

    override fun getRestClient(): HttpClient {
        // dirty hack to get preconfigured http client from task management plugin
        // we don't want to handle all the connection/testing/proxy stuff ourselves
        val method = BaseRepositoryImpl::class.java.getDeclaredMethod("getHttpClient")
        method.isAccessible = true
        return method.invoke(getYouTrackRepository()) as HttpClient
    }

    private fun TaskRepository.isYouTrack() = this.javaClass.name.contains("youtrack", true)
}
{'fraction_non_alphanumeric': 0.07945013979496739, 'fraction_numerical': 0.002096924510717614, 'mean_word_length': 3.5914438502673796, 'pattern_counts': {'":': 0, '<': 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': '6964783', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1067, 'n_words': 227}