Skip to content

Commit

Permalink
GH-125 handle refs/remotes prefixed branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Claus Schneider (Praqma) committed Aug 14, 2018
1 parent 8f9b8c5 commit 335307c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListene
}

@Override
public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev, GitBridge gitbridge) throws NothingToDoException, IntegrationFailedException, IOException, InterruptedException {
public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Branch triggeredBranch, GitBridge gitbridge) throws NothingToDoException, IntegrationFailedException, IOException, InterruptedException {


String expandedRepoName;
Expand All @@ -234,13 +234,12 @@ public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git,
expandedRepoName = gitbridge.getRepoName();
}

if (!PretestedIntegrationGitUtils.isRelevant(rev, expandedRepoName)) {
if (!PretestedIntegrationGitUtils.isRelevant(triggeredBranch, expandedRepoName)) {
throw new NothingToDoException("No revision matches configuration in 'Integration repository'");
}

Branch triggerBranch = rev.getBranches().iterator().next();
String expandedIntegrationBranch = gitbridge.getExpandedIntegrationBranch(build.getEnvironment(listener));
doTheIntegration((Run) build, listener, gitbridge, triggerBranch.getSHA1(), git, expandedIntegrationBranch, triggerBranch);
doTheIntegration((Run) build, listener, gitbridge, triggeredBranch.getSHA1(), git, expandedIntegrationBranch, triggeredBranch);
}

public boolean isShortCommitMessage() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.pretestedintegration.scm.git;

import hudson.model.*;
import hudson.plugins.git.Branch;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
import org.jenkinsci.plugins.gitclient.GitClient;
Expand All @@ -23,7 +24,7 @@ public abstract interface IntegrationStrategyAsGitPluginExt{
* @param git current git client
* @param listener The BuildListener
* @param marked marked revision for use in GitExtensions
* @param rev revision f
* @param triggeredBranch the triggered branch
* @param bridge the gitbridge
* @throws IntegrationFailedException The integration failed ala merge
* @throws NothingToDoException The triggered revision is behind the integration
Expand All @@ -32,7 +33,7 @@ public abstract interface IntegrationStrategyAsGitPluginExt{
* @throws InterruptedException Unforeseen problems
*/

public abstract void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Revision rev, GitBridge bridge)
public abstract void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, Revision marked, Branch triggeredBranch, GitBridge bridge)
throws IntegrationFailedException, NothingToDoException, UnsupportedConfigurationException, IOException, InterruptedException;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public Revision decorateRevisionToBuild(
EnvVars environment = run.getEnvironment(listener);

// TODO: Should this be last branch in stead of?
Branch triggeredBranch = triggeredRevision.getBranches().iterator().next();
Branch triggeredBranchDraft = triggeredRevision.getBranches().iterator().next();
Branch triggeredBranch = new Branch(triggeredBranchDraft.getName().replaceFirst("refs/remotes/", ""), triggeredBranchDraft.getSHA1());
String expandedIntegrationBranch = gitBridge.getExpandedIntegrationBranch(environment);
String expandedRepo = gitBridge.getExpandedRepository(environment);
String ucCredentialsId = "";
Expand All @@ -122,7 +123,7 @@ public Revision decorateRevisionToBuild(
gitBridge.evalBranchConfigurations(triggeredBranch, expandedIntegrationBranch, expandedRepo);
listener.getLogger().println(String.format(LOG_PREFIX + "Checking out integration branch %s:", expandedIntegrationBranch));
git.checkout().branch(expandedIntegrationBranch).ref(expandedRepo + "/" + expandedIntegrationBranch).deleteBranchIfExist(true).execute();
((GitIntegrationStrategy) gitBridge.integrationStrategy).integrateAsGitPluginExt(scm, run, git, listener, marked, triggeredRevision, gitBridge);
((GitIntegrationStrategy) gitBridge.integrationStrategy).integrateAsGitPluginExt(scm, run, git, listener, marked, triggeredBranch, gitBridge);


} catch (NothingToDoException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ private static Set<BuildData> findRelevantBuildDataImpl(PrintStream logger, List
return relevantBuildData;
}

public static boolean isRelevant(Revision r, String repoName) {
Branch br = r.getBranches().iterator().next();

return br.getName().startsWith(repoName + "/");
public static boolean isRelevant(Branch triggeredBranch, String repoName) {
return triggeredBranch.getName().startsWith(repoName + "/") || triggeredBranch.getName().startsWith("refs/remotes/" + repoName + "/");
}

/***
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListene


@Override
public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient client, TaskListener listener, Revision marked, Revision rev, GitBridge gitbridge) throws IntegrationFailedException, IntegrationUnknownFailureException, NothingToDoException, UnsupportedConfigurationException {
public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient client, TaskListener listener, Revision marked, Branch triggeredBranch, GitBridge gitbridge) throws IntegrationFailedException, IntegrationUnknownFailureException, NothingToDoException, UnsupportedConfigurationException {

String expandedRepoName;
try {
Expand All @@ -208,7 +208,7 @@ public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient clien
expandedRepoName = gitbridge.getRepoName();
}

if (!PretestedIntegrationGitUtils.isRelevant(rev, expandedRepoName)) {
if (!PretestedIntegrationGitUtils.isRelevant(triggeredBranch, expandedRepoName)) {
throw new NothingToDoException("No revision matches configuration in 'Integration repository'");
}

Expand All @@ -224,9 +224,7 @@ public void integrateAsGitPluginExt(GitSCM scm, Run<?, ?> build, GitClient clien
// multiple revisons, when two branches point to the same commit?
// (JENKINS-24909). Check integrationBranch spec before doing anything
// It could be the last rather than the first that is the wanted
Branch triggerBranch = rev.getBranches().iterator().next();

doTheIntegration((Run) build, listener, gitbridge, rev.getSha1(), client, expandedIntegrationBranch, triggerBranch);
doTheIntegration((Run) build, listener, gitbridge, triggeredBranch.getSHA1(), client, expandedIntegrationBranch, triggeredBranch);
}

/**
Expand Down

0 comments on commit 335307c

Please sign in to comment.