Unverified Commit bc18e961 authored by Maxime Lefrançois's avatar Maxime Lefrançois
Browse files

read remote branches also for target repository. Closes #4

parent 22d60e6a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,3 +4,4 @@ dependency-reduced-pom.xml
.classpath
.settings
bin
.vscode
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
cache:
  paths:
    - .m2/repository

stages:
  - build
  - deploy
+6 −6
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
	<modelVersion>4.0.0</modelVersion>
	<groupId>fr.mines-stetienne.ci.saref</groupId>
	<artifactId>saref-pipeline</artifactId>
	<version>1.0</version>
	<version>1.0.1</version>
	<packaging>jar</packaging>

	<name>SAREF-Pipeline</name>
@@ -45,7 +45,7 @@
		</license>
	</licenses>

	<repositories>
	<!-- <repositories>
		<repository>
			<id>gitlab-maven</id>
			<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
@@ -61,13 +61,13 @@
			<id>gitlab-maven</id>
			<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
		</repository>
	</distributionManagement>
	</distributionManagement> -->

	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.source>11</maven.compiler.source>
		<maven.compiler.target>11</maven.compiler.target>
		<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssZ</maven.build.timestamp.format>
		<jdk.version>1.8</jdk.version>
		<jdk.version>11</jdk.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<project.scm.id>git</project.scm.id>
+23 −23
Original line number Diff line number Diff line
@@ -69,12 +69,10 @@ public class RepositoryFactory extends SAREFErrorLogger {
		target_name, develop_branch, not_clean, release_branch, release_git, source_name;
	}

	public static final String REGEX_REMOTELOCAL_BRANCH_VAR = "remotelocal";
	public static final String REGEX_VERSION_BRANCH_VAR = "type";
	public static final String REGEX_VERSION_BRANCH = String.format(
			"^(refs/heads/)?(?<%s>(develop|prerelease|release))-%s$", REGEX_VERSION_BRANCH_VAR,
			SAREF.REGEX_VERSION_NUMBER);
	public static final String REGEX_ORIGIN_VERSION_BRANCH = String.format(
			"^refs/remotes/origin/(?<%s>(develop|prerelease|release))-%s$", REGEX_VERSION_BRANCH_VAR,
			"^(refs/?(?<%s>(heads|remotes/origin)/))?(?<%s>(develop|prerelease|release))-%s$", REGEX_REMOTELOCAL_BRANCH_VAR, REGEX_VERSION_BRANCH_VAR,
			SAREF.REGEX_VERSION_NUMBER);

	private final boolean isTarget;
@@ -193,17 +191,13 @@ public class RepositoryFactory extends SAREFErrorLogger {
	private void readVersions(Git git, SAREFRepository repository) throws GitAPIException {
		final List<Ref> allBranches;
		final Pattern pattern;
		if (isTarget) {
			allBranches = git.branchList().call();
			pattern = Pattern.compile(REGEX_VERSION_BRANCH);
		} else {
		allBranches = git.branchList().setListMode(ListMode.REMOTE).call();
			pattern = Pattern.compile(REGEX_ORIGIN_VERSION_BRANCH);
		}
		pattern = Pattern.compile(REGEX_VERSION_BRANCH);
		Map<SAREFVersionName, VersionBuilder> versionBuilders = new HashMap<>();
		for (Ref ref : allBranches) {
			Matcher m = pattern.matcher(ref.getName());
			if (m.find()) {
				String remotelocalType = m.group(REGEX_REMOTELOCAL_BRANCH_VAR);
				String branchType = m.group(REGEX_VERSION_BRANCH_VAR);

				// only consider release branches when running in RELEASE_PORTAL mode
@@ -228,13 +222,19 @@ public class RepositoryFactory extends SAREFErrorLogger {
				}
				switch (branchType) {
					case "develop":
						if(versionBuilder.developRef == null || remotelocalType.equals("heads")) {
							versionBuilder.developRef = ref;
						} 
						break;
					case "prerelease":
						if(versionBuilder.developRef == null || remotelocalType.equals("heads")) {
							versionBuilder.prereleaseRef = ref;
						}
						break;
					case "release":
						if(versionBuilder.releaseRef == null || remotelocalType.equals("heads")) {
							versionBuilder.releaseRef = ref;
						}
						break;
					default:
						throw new NullPointerException("Should not reach this point");