<commit_before>package com.atlassian.jira.plugins.dvcs.dao.impl.transform;

import com.atlassian.jira.plugins.dvcs.activity.PullRequestParticipantMapping;
import com.atlassian.jira.plugins.dvcs.activity.RepositoryPullRequestMapping;
import com.atlassian.jira.plugins.dvcs.model.Participant;
import com.atlassian.jira.plugins.dvcs.model.PullRequest;
import com.atlassian.jira.plugins.dvcs.model.PullRequestRef;
import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class PullRequestTransformer
{
    public static final Logger log = LoggerFactory.getLogger(PullRequestTransformer.class);

    private final RepositoryService repositoryService;

    public PullRequestTransformer(final RepositoryService repositoryService)
    {
        this.repositoryService = repositoryService;
    }

    public PullRequest transform(RepositoryPullRequestMapping pullRequestMapping)
    {
        if (pullRequestMapping == null)
        {
            return null;
        }

        Repository repository = repositoryService.get(pullRequestMapping.getToRepositoryId());

        final PullRequest pullRequest = new PullRequest(pullRequestMapping.getToRepositoryId());
        pullRequest.setRemoteId(pullRequestMapping.getRemoteId());
        pullRequest.setRepositoryId(pullRequestMapping.getToRepositoryId());
        pullRequest.setName(pullRequestMapping.getName());
        pullRequest.setUrl(pullRequestMapping.getUrl());

        pullRequest.setSource(new PullRequestRef(pullRequestMapping.getSourceBranch(), pullRequestMapping.getSourceRepo(), createRepositoryUrl(repository.getOrgHostUrl(), pullRequestMapping.getSourceRepo())));
        pullRequest.setDestination(new PullRequestRef(pullRequestMapping.getDestinationBranch(), createRepositoryLabel(repository), repository.getRepositoryUrl()));

        pullRequest.setStatus(pullRequestMapping.getLastStatus());
        pullRequest.setCreatedOn(pullRequestMapping.getCreatedOn());
        pullRequest.setUpdatedOn(pullRequestMapping.getUpdatedOn());
        pullRequest.setAuthor(pullRequestMapping.getAuthor());
        pullRequest.setParticipants(transform(pullRequestMapping.getParticipants()));
        pullRequest.setCommentCount(pullRequestMapping.getCommentCount());

        return pullRequest;
    }

    private List<Participant> transform(final PullRequestParticipantMapping[] participantMappings)
    {
        if (participantMappings == null)
        {
            return null;
        }

        List<Participant> participants = new ArrayList<Participant>();
        for (PullRequestParticipantMapping participantMapping : participantMappings)
        {
            Participant participant = new Participant(participantMapping.getUsername(), participantMapping.isApproved(), participantMapping.getRole());
            participants.add(participant);
        }

        return participants;
    }

    private String createRepositoryUrl(String hostUrl, String repositoryLabel)
    {
        if (repositoryLabel == null)
        {
            // the fork repository was deleted
            return null;
        }
        // normalize
        if (hostUrl != null && hostUrl.endsWith("/"))
        {
            hostUrl = hostUrl.substring(0, hostUrl.length() - 1);
        }
        return hostUrl + "/" + repositoryLabel;
    }

    private String createRepositoryLabel(Repository repository)
    {
        return repository.getOrgName() + "/" + repository.getSlug();
    }
}
<commit_msg>FUSE-603 Fixing pull request transformation<commit_after>package com.atlassian.jira.plugins.dvcs.dao.impl.transform;

import com.atlassian.jira.plugins.dvcs.activity.PullRequestParticipantMapping;
import com.atlassian.jira.plugins.dvcs.activity.RepositoryPullRequestMapping;
import com.atlassian.jira.plugins.dvcs.model.Participant;
import com.atlassian.jira.plugins.dvcs.model.PullRequest;
import com.atlassian.jira.plugins.dvcs.model.PullRequestRef;
import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.service.RepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class PullRequestTransformer
{
    public static final Logger log = LoggerFactory.getLogger(PullRequestTransformer.class);

    private final RepositoryService repositoryService;

    public PullRequestTransformer(final RepositoryService repositoryService)
    {
        this.repositoryService = repositoryService;
    }

    public PullRequest transform(RepositoryPullRequestMapping pullRequestMapping)
    {
        if (pullRequestMapping == null)
        {
            return null;
        }

        Repository repository = repositoryService.get(pullRequestMapping.getToRepositoryId());

        final PullRequest pullRequest = new PullRequest(pullRequestMapping.getID());
        pullRequest.setRemoteId(pullRequestMapping.getRemoteId());
        pullRequest.setRepositoryId(pullRequestMapping.getToRepositoryId());
        pullRequest.setName(pullRequestMapping.getName());
        pullRequest.setUrl(pullRequestMapping.getUrl());

        pullRequest.setSource(new PullRequestRef(pullRequestMapping.getSourceBranch(), pullRequestMapping.getSourceRepo(), createRepositoryUrl(repository.getOrgHostUrl(), pullRequestMapping.getSourceRepo())));
        pullRequest.setDestination(new PullRequestRef(pullRequestMapping.getDestinationBranch(), createRepositoryLabel(repository), repository.getRepositoryUrl()));

        pullRequest.setStatus(pullRequestMapping.getLastStatus());
        pullRequest.setCreatedOn(pullRequestMapping.getCreatedOn());
        pullRequest.setUpdatedOn(pullRequestMapping.getUpdatedOn());
        pullRequest.setAuthor(pullRequestMapping.getAuthor());
        pullRequest.setParticipants(transform(pullRequestMapping.getParticipants()));
        pullRequest.setCommentCount(pullRequestMapping.getCommentCount());

        return pullRequest;
    }

    private List<Participant> transform(final PullRequestParticipantMapping[] participantMappings)
    {
        if (participantMappings == null)
        {
            return null;
        }

        List<Participant> participants = new ArrayList<Participant>();
        for (PullRequestParticipantMapping participantMapping : participantMappings)
        {
            Participant participant = new Participant(participantMapping.getUsername(), participantMapping.isApproved(), participantMapping.getRole());
            participants.add(participant);
        }

        return participants;
    }

    private String createRepositoryUrl(String hostUrl, String repositoryLabel)
    {
        if (repositoryLabel == null)
        {
            // the fork repository was deleted
            return null;
        }
        // normalize
        if (hostUrl != null && hostUrl.endsWith("/"))
        {
            hostUrl = hostUrl.substring(0, hostUrl.length() - 1);
        }
        return hostUrl + "/" + repositoryLabel;
    }

    private String createRepositoryLabel(Repository repository)
    {
        return repository.getOrgName() + "/" + repository.getSlug();
    }
}

{'fraction_non_alphanumeric': 0.09021447721179625, 'fraction_numerical': 0.0014745308310991957, 'mean_word_length': 3.414792899408284, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7255995', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1853, 'n_words': 290}