<commit_before>package com.atlassian.jira.plugins.dvcs.smartcommits;

import java.util.Iterator;

import javax.ws.rs.core.CacheControl;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Qualifier;

import com.atlassian.crowd.embedded.api.CrowdService;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.crowd.search.EntityDescriptor;
import com.atlassian.crowd.search.builder.QueryBuilder;
import com.atlassian.crowd.search.builder.Restriction;
import com.atlassian.crowd.search.query.entity.EntityQuery;
import com.atlassian.crowd.search.query.entity.restriction.constants.UserTermKeys;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.Comment;
import com.atlassian.jira.issue.worklog.Worklog;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.CommentHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.TransitionHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.WorkLogHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommandsResults;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommandsResults.CommandResult;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitCommands;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitHookHandlerError;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.Either;
import com.atlassian.jira.security.JiraAuthenticationContext;

public class DefaultSmartcommitsService implements SmartcommitsService
{
	private static final Logger log = org.slf4j.LoggerFactory.getLogger(DefaultSmartcommitsService.class);

	private final CacheControl NO_CACHE;

	private final TransitionHandler transitionHandler;
	private final CommentHandler commentHandler;
	private final WorkLogHandler workLogHandler;

	private final IssueManager issueManager;

	private final JiraAuthenticationContext jiraAuthenticationContext;

	private final CrowdService crowdService;

	public DefaultSmartcommitsService(IssueManager issueManager,
			@Qualifier("smartcommitsTransitionsHandler") TransitionHandler transitionHandler,
			@Qualifier("smartcommitsCommentHandler") CommentHandler commentHandler,
			@Qualifier("smartcommitsWorklogHandler") WorkLogHandler workLogHandler,
			JiraAuthenticationContext jiraAuthenticationContext, CrowdService crowdService)
	{
		this.crowdService = crowdService;

		NO_CACHE = new CacheControl();
		NO_CACHE.setNoCache(true);

		this.issueManager = issueManager;
		this.transitionHandler = transitionHandler;
		this.commentHandler = commentHandler;
		this.workLogHandler = workLogHandler;
		this.jiraAuthenticationContext = jiraAuthenticationContext;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public CommandsResults doCommands(CommitCommands commands)
	{
		CommandsResults results = new CommandsResults();

		//
		// recognise user and auth user by email
		//
		String authorEmail = commands.getAuthorEmail();
		if (StringUtils.isBlank(authorEmail))
		{
            results.addGlobalError("Changeset hasn't fill author email.");
			return results;
		}
		//
		// Fetch user by email
		//
		User user = getUserByEmailOrNull(authorEmail);
		if (user == null)
		{
            results.addGlobalError("Can't find JIRA user with given author email: " + authorEmail);
			return results;
		}

		//
		// Authenticate user
		//
		jiraAuthenticationContext.setLoggedInUser(user);

		if (CollectionUtils.isEmpty(commands.getCommands()))
		{<commit_msg>PR #144 fixed wording<commit_after>package com.atlassian.jira.plugins.dvcs.smartcommits;

import java.util.Iterator;

import javax.ws.rs.core.CacheControl;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Qualifier;

import com.atlassian.crowd.embedded.api.CrowdService;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.crowd.search.EntityDescriptor;
import com.atlassian.crowd.search.builder.QueryBuilder;
import com.atlassian.crowd.search.builder.Restriction;
import com.atlassian.crowd.search.query.entity.EntityQuery;
import com.atlassian.crowd.search.query.entity.restriction.constants.UserTermKeys;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.comments.Comment;
import com.atlassian.jira.issue.worklog.Worklog;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.CommentHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.TransitionHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.handlers.WorkLogHandler;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommandsResults;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommandsResults.CommandResult;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitCommands;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitHookHandlerError;
import com.atlassian.jira.plugins.dvcs.smartcommits.model.Either;
import com.atlassian.jira.security.JiraAuthenticationContext;

public class DefaultSmartcommitsService implements SmartcommitsService
{
	private static final Logger log = org.slf4j.LoggerFactory.getLogger(DefaultSmartcommitsService.class);

	private final CacheControl NO_CACHE;

	private final TransitionHandler transitionHandler;
	private final CommentHandler commentHandler;
	private final WorkLogHandler workLogHandler;

	private final IssueManager issueManager;

	private final JiraAuthenticationContext jiraAuthenticationContext;

	private final CrowdService crowdService;

	public DefaultSmartcommitsService(IssueManager issueManager,
			@Qualifier("smartcommitsTransitionsHandler") TransitionHandler transitionHandler,
			@Qualifier("smartcommitsCommentHandler") CommentHandler commentHandler,
			@Qualifier("smartcommitsWorklogHandler") WorkLogHandler workLogHandler,
			JiraAuthenticationContext jiraAuthenticationContext, CrowdService crowdService)
	{
		this.crowdService = crowdService;

		NO_CACHE = new CacheControl();
		NO_CACHE.setNoCache(true);

		this.issueManager = issueManager;
		this.transitionHandler = transitionHandler;
		this.commentHandler = commentHandler;
		this.workLogHandler = workLogHandler;
		this.jiraAuthenticationContext = jiraAuthenticationContext;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public CommandsResults doCommands(CommitCommands commands)
	{
		CommandsResults results = new CommandsResults();

		//
		// recognise user and auth user by email
		//
		String authorEmail = commands.getAuthorEmail();
		if (StringUtils.isBlank(authorEmail))
		{
            results.addGlobalError("Changeset doesn't contain author email. Unable to map this to JIRA user.");
			return results;
		}
		//
		// Fetch user by email
		//
		User user = getUserByEmailOrNull(authorEmail);
		if (user == null)
		{
            results.addGlobalError("Can't find JIRA user with given author email: " + authorEmail);
			return results;
		}

		//
		// Authenticate user
		//
		jiraAuthenticationContext.setLoggedInUser(user);

		if (CollectionUtils.isEmpty(commands.getCommands()))
		{
{'fraction_non_alphanumeric': 0.09074853960059774, 'fraction_numerical': 0.000950957750305665, 'mean_word_length': 5.766544117647059, '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': '3322600', 'n_tokens_mistral': 2331, 'n_tokens_neox': 2186, 'n_words': 374}