<commit_before>package com.hp.octane.plugins.jenkins.model.processors.scm;

import com.hp.octane.plugins.jenkins.model.scm.*;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.util.BuildData;
import hudson.scm.ChangeLogSet;
import hudson.tasks.Mailer;

import java.util.ArrayList;
import java.util.Set;

/**
 * Created by gullery on 31/03/2015.
 */

public class GitSCMProcessor extends AbstractSCMProcessor {
	GitSCMProcessor() {
	}

	@Override
	public SCMData getSCMChanges(AbstractBuild build) {
		ArrayList<SCMRepository> repositories = new ArrayList<SCMRepository>();
		AbstractProject project = build.getProject();
		GitSCM scmGit;
		SCMType tmpType;
		SCMRepository tmpRepo;
		SCMConfiguration tmpConfiguration;
		ArrayList<SCMCommit> tmpCommits;
		SCMCommit tmpCommit;
		ChangeLogSet<ChangeLogSet.Entry> changes = build.getChangeSet();
		BuildData buildData;
		Revision buildCommitRev;
		Set<String> repoUris;
		GitChangeSet gitChange;
		if (project.getScm() instanceof GitSCM) {
			tmpType = SCMType.GIT;
			scmGit = (GitSCM) project.getScm();
			buildData = scmGit.getBuildData(build);
			if (buildData != null) {
				buildCommitRev = buildData.getLastBuiltRevision();
				repoUris = buildData.getRemoteUrls();
				if (!repoUris.iterator().hasNext()) return null;
				tmpConfiguration = new SCMConfiguration(
						tmpType,
						repoUris.iterator().next(),
						buildCommitRev.getBranches().iterator().hasNext() ? buildCommitRev.getBranches().iterator().next().getName() : null,
						buildCommitRev.getSha1String()
				);
				tmpCommits = new ArrayList<SCMCommit>();
				for (ChangeLogSet.Entry change : changes) {
					if (change instanceof GitChangeSet) {
						gitChange = (GitChangeSet) change;
						tmpCommit = new SCMCommit(
								gitChange.getId(),
								gitChange.getComment().trim(),
								gitChange.getTimestamp()
						);
						tmpCommit.setUser(<commit_msg>Defect #: adding additional validations on the Git data retrieval.<commit_after>package com.hp.octane.plugins.jenkins.model.processors.scm;

import com.hp.octane.plugins.jenkins.model.scm.*;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import hudson.plugins.git.util.BuildData;
import hudson.scm.ChangeLogSet;
import hudson.tasks.Mailer;

import java.util.ArrayList;
import java.util.Set;

/**
 * Created by gullery on 31/03/2015.
 */

public class GitSCMProcessor extends AbstractSCMProcessor {
	GitSCMProcessor() {
	}

	@Override
	public SCMData getSCMChanges(AbstractBuild build) {
		ArrayList<SCMRepository> repositories = new ArrayList<SCMRepository>();
		AbstractProject project = build.getProject();
		GitSCM scmGit;
		SCMType tmpType;
		SCMRepository tmpRepo;
		SCMConfiguration tmpConfiguration;
		ArrayList<SCMCommit> tmpCommits;
		SCMCommit tmpCommit;
		ChangeLogSet<ChangeLogSet.Entry> changes = build.getChangeSet();
		BuildData buildData;
		Revision buildCommitRev;
		Set<String> repoUris;
		GitChangeSet gitChange;
		if (project.getScm() instanceof GitSCM) {
			tmpType = SCMType.GIT;
			scmGit = (GitSCM) project.getScm();
			buildData = scmGit.getBuildData(build);
			if (buildData != null) {
				buildCommitRev = buildData.getLastBuiltRevision();
				if (buildCommitRev == null || buildCommitRev.getBranches() == null) return null;
				repoUris = buildData.getRemoteUrls();
				if (!repoUris.iterator().hasNext()) return null;
				tmpConfiguration = new SCMConfiguration(
						tmpType,
						repoUris.iterator().next(),
						buildCommitRev.getBranches().iterator().hasNext() ? buildCommitRev.getBranches().iterator().next().getName() : null,
						buildCommitRev.getSha1String()
				);
				tmpCommits = new ArrayList<SCMCommit>();
				for (ChangeLogSet.Entry change : changes) {
					if (change instanceof GitChangeSet) {
						gitChange = (GitChangeSet) change;
						tmpCommit = new SCMCommit(
								gitChange.getId(),
								gitChange.getComment().trim(),
								gitChange.getTimestamp()
						);
						tmpCommit.setUser(
{'fraction_non_alphanumeric': 0.11271266540642721, 'fraction_numerical': 0.004253308128544423, 'mean_word_length': 4.426923076923077, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5716136', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1349, 'n_words': 258}