<commit_before>package org.scm4j.releaser;

import org.scm4j.commons.Version;
import org.scm4j.releaser.branch.DevelopBranch;
import org.scm4j.releaser.branch.DevelopBranchStatus;
import org.scm4j.releaser.branch.ReleaseBranch;
import org.scm4j.releaser.conf.Component;
import org.scm4j.releaser.conf.DelayedTagsFile;
import org.scm4j.releaser.conf.Options;
import org.scm4j.vcs.api.IVCS;
import org.scm4j.vcs.api.VCSCommit;
import org.scm4j.vcs.api.VCSTag;
import org.scm4j.vcs.api.WalkDirection;

import java.util.List;

public class Build {

	public static final String ZERO_PATCH = "0";
	private final Component comp;
	private final ReleaseBranch rb;

	public Build(ReleaseBranch rb) {
		comp = rb.getComponent();
		this.rb = rb;
	}
	
	public Build(Component comp) {
		this(new ReleaseBranch(comp));
	}

	public BuildStatus getStatus() {
		if (Options.isPatch()) {
			if (!rb.exists()) {
				return BuildStatus.ERROR;
			}
			
			Version headVersion = rb.getVersion();
			if (/*comp.isProduct() && */Integer.parseInt(headVersion.getPatch()) < 1) {
				return BuildStatus.ERROR;
			}
		} else {
			if (!comp.getVersion().isExact()) {
				if (isNeedToFork()) {
					return BuildStatus.FORK;
				}
			}
			
			if (Integer.parseInt(rb.getVersion().getPatch()) > 0) {
				return BuildStatus.DONE;
			}
		}
		
		List<Component> mDeps = rb.getMDeps();
		if (!areMDepsFrozen(mDeps)) {
			return BuildStatus.FREEZE;
		}
		
		if (hasMDepsNotInDONEStatus(mDeps)) {
			return BuildStatus.BUILD_MDEPS;
		}

		if (!areMDepsPatchesActual(mDeps)) {
			return BuildStatus.ACTUALIZE_PATCHES;
		}
		
		if (Options.isPatch() && noValueableCommitsAfterLastTag()) {
			return BuildStatus.DONE;
		}
		
		return BuildStatus.BUILD;
	}

	private boolean hasMDepsNotInDONEStatus(List<Component> mDeps) {
		for (Component mDep : mDeps) {
			ReleaseBranch rbMDep = new ReleaseBranch(mDep);
			if (!rbMDep.exists()) {
				return false;
			}
			if (hasMDepsNotInDONEStatus(rbMDep.getMDeps())) {
				return true;
			}
			Build bMDep = new Build(mDep);
			if (bMDep.getStatus() != BuildStatus.DONE) {
				return true;
			}
		}
		return false;
	}

	private boolean noValueableCommitsAfterLastTag() {
		IVCS vcs = comp.getVCS();
		List<VCSCommit> commits = vcs.getCommitsRange(rb.getName(), null, WalkDirection.DESC, 0);
		DelayedTagsFile dtf = new DelayedTagsFile();
		String delayedTagRevision = dtf.getRevisitonByUrl(comp.getVcsRepository().getUrl());
		for (VCSCommit commit : commits) {
			if (commit.getRevision().equals(delayedTagRevision)) {
				return true;
			}
			if (!commit.getLogMessage().contains(LogTag.SCM_VER) && !commit.getLogMessage().contains(LogTag.SCM_IGNORE)) {
				List<VCSTag> tags = vcs.getTagsOnRevision(commit.getRevision());
				return !tags.isEmpty();
			}
		}
		return true;
	}<commit_msg>fixed noValueableCommitsAfterLastTag()<commit_after>package org.scm4j.releaser;

import org.scm4j.commons.Version;
import org.scm4j.releaser.branch.DevelopBranch;
import org.scm4j.releaser.branch.DevelopBranchStatus;
import org.scm4j.releaser.branch.ReleaseBranch;
import org.scm4j.releaser.conf.Component;
import org.scm4j.releaser.conf.DelayedTagsFile;
import org.scm4j.releaser.conf.Options;
import org.scm4j.vcs.api.IVCS;
import org.scm4j.vcs.api.VCSCommit;
import org.scm4j.vcs.api.VCSTag;
import org.scm4j.vcs.api.WalkDirection;

import java.util.List;

public class Build {

	public static final String ZERO_PATCH = "0";
	private final Component comp;
	private final ReleaseBranch rb;

	public Build(ReleaseBranch rb) {
		comp = rb.getComponent();
		this.rb = rb;
	}
	
	public Build(Component comp) {
		this(new ReleaseBranch(comp));
	}

	public BuildStatus getStatus() {
		if (Options.isPatch()) {
			if (!rb.exists()) {
				return BuildStatus.ERROR;
			}
			
			Version headVersion = rb.getVersion();
			if (/*comp.isProduct() && */Integer.parseInt(headVersion.getPatch()) < 1) {
				return BuildStatus.ERROR;
			}
		} else {
			if (!comp.getVersion().isExact()) {
				if (isNeedToFork()) {
					return BuildStatus.FORK;
				}
			}
			
			if (Integer.parseInt(rb.getVersion().getPatch()) > 0) {
				return BuildStatus.DONE;
			}
		}
		
		List<Component> mDeps = rb.getMDeps();
		if (!areMDepsFrozen(mDeps)) {
			return BuildStatus.FREEZE;
		}
		
		if (hasMDepsNotInDONEStatus(mDeps)) {
			return BuildStatus.BUILD_MDEPS;
		}

		if (!areMDepsPatchesActual(mDeps)) {
			return BuildStatus.ACTUALIZE_PATCHES;
		}
		
		if (Options.isPatch() && noValueableCommitsAfterLastTag()) {
			return BuildStatus.DONE;
		}
		
		return BuildStatus.BUILD;
	}

	private boolean hasMDepsNotInDONEStatus(List<Component> mDeps) {
		for (Component mDep : mDeps) {
			ReleaseBranch rbMDep = new ReleaseBranch(mDep);
			if (!rbMDep.exists()) {
				return false;
			}
			if (hasMDepsNotInDONEStatus(rbMDep.getMDeps())) {
				return true;
			}
			Build bMDep = new Build(mDep);
			if (bMDep.getStatus() != BuildStatus.DONE) {
				return true;
			}
		}
		return false;
	}

	private boolean noValueableCommitsAfterLastTag() {
		IVCS vcs = comp.getVCS();
		List<VCSCommit> commits = vcs.getCommitsRange(rb.getName(), null, WalkDirection.DESC, 0);
		DelayedTagsFile dtf = new DelayedTagsFile();
		String delayedTagRevision = dtf.getRevisitonByUrl(comp.getVcsRepository().getUrl());
		for (VCSCommit commit : commits) {
			if (commit.getRevision().equals(delayedTagRevision)) {
				return true;
			}
			//TODO: add test when we put tag on #scm-ver commit. noValueableCommitsAfterLastTag() should check if we have tags on it 
			List<VCSTag> tags = vcs.getTagsOnRevision(commit.getRevision());
			if (!commit.getLogMessage().contains(LogTag.SCM_VER) && !commit.getLogMessage().contains(LogTag.SCM_IGNORE)) {
				return !tags.isEmpty();
			}
			if (!tags.isEmpty()) {
				return true;
			}
		}
		return true;
	}
{'fraction_non_alphanumeric': 0.1299982689977497, 'fraction_numerical': 0.005539207200969361, 'mean_word_length': 3.9939498703543648, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1778584', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2085, 'n_words': 374}