<commit_before>package com.groupon.jenkins.dotci.patch;

import com.google.common.base.*;
import com.groupon.jenkins.github.services.*;
import hudson.model.*;
import org.kohsuke.github.*;
import org.wickedsource.diffparser.api.*;
import org.wickedsource.diffparser.api.model.*;

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class PatchParser {
    private final PrintStream logger;

    public PatchParser(BuildListener listener) {
        this.logger = listener.getLogger();
    }

    public  List<PatchFile> getLines(String repoUrl,int prNumber){
        GHRepository repo = new GithubRepositoryService(repoUrl).getGithubRepository();
        List<PatchFile> files = new ArrayList<PatchFile>();

        try {
            DiffParser parser = new UnifiedDiffParser();
            for(GHPullRequestFileDetail file : repo.getPullRequest(prNumber).listFiles()){
                PatchFile patchFile = new PatchFile(file.getFilename());
                files.add(patchFile);
                if(file.getPatch() ==null) continue;
                String fixPatch = fixPatch(file.getPatch());
//                printPatches(file, fixPatch);

                String patch = "--- /file/path \n +++ /file/path_new\n"+ fixPatch;
                List<Diff> diffs = parser.parse(patch.getBytes());
                for(Diff diff : diffs){
                    int pos =0;
                    for(Hunk hunk: diff.getHunks()){
                        PatchHunk patchHunk = new PatchHunk(hunk.getToFileRange());
                        patchFile.add(patchHunk);
                        int lineNo = hunk.getToFileRange().getLineStart();

                        for(Line line: hunk.getLines()){
                            pos = pos+1;
                            if(line.getLineType().equals(Line.LineType.NEUTRAL)){
                                lineNo= lineNo + 1;
                            }
                            if(line.getLineType().equals(Line.LineType.TO)){
                                patchHunk.add(new PatchLine(lineNo,pos));
                                lineNo= lineNo + 1;
                            }
                        }
                        pos = pos + 1; //Increment pos for each new hunk
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }<commit_msg>Removing leading space that was confusing patchparser<commit_after>package com.groupon.jenkins.dotci.patch;

import com.google.common.base.*;
import com.groupon.jenkins.github.services.*;
import hudson.model.*;
import org.kohsuke.github.*;
import org.wickedsource.diffparser.api.*;
import org.wickedsource.diffparser.api.model.*;

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class PatchParser {
    private final PrintStream logger;

    public PatchParser(BuildListener listener) {
        this.logger = listener.getLogger();
    }

    public  List<PatchFile> getLines(String repoUrl,int prNumber){
        GHRepository repo = new GithubRepositoryService(repoUrl).getGithubRepository();
        List<PatchFile> files = new ArrayList<PatchFile>();

        try {
            DiffParser parser = new UnifiedDiffParser();
            for(GHPullRequestFileDetail file : repo.getPullRequest(prNumber).listFiles()){
                PatchFile patchFile = new PatchFile(file.getFilename());
                files.add(patchFile);
                if(file.getPatch() ==null) continue;
                String fixPatch = fixPatch(file.getPatch());
//                printPatches(file, fixPatch);

                String patch = "--- /file/path\n+++ /file/path_new\n"+ fixPatch;
                List<Diff> diffs = parser.parse(patch.getBytes());
                for(Diff diff : diffs){
                    int pos =0;
                    for(Hunk hunk: diff.getHunks()){
                        PatchHunk patchHunk = new PatchHunk(hunk.getToFileRange());
                        patchFile.add(patchHunk);
                        int lineNo = hunk.getToFileRange().getLineStart();

                        for(Line line: hunk.getLines()){
                            pos = pos+1;
                            if(line.getLineType().equals(Line.LineType.NEUTRAL)){
                                lineNo= lineNo + 1;
                            }
                            if(line.getLineType().equals(Line.LineType.TO)){
                                patchHunk.add(new PatchLine(lineNo,pos));
                                lineNo= lineNo + 1;
                            }
                        }
                        pos = pos + 1; //Increment pos for each new hunk
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
{'fraction_non_alphanumeric': 0.10737976782752902, 'fraction_numerical': 0.0020729684908789387, 'mean_word_length': 1.5843599357257632, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '936425', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1219, 'n_words': 249}