forked from Praqma/pretested-integration-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'JENKINS-30891'
- Loading branch information
Showing
9 changed files
with
233 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/org/jenkinsci/plugins/pretestedintegration/scm/git/GitIntegrationStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.jenkinsci.plugins.pretestedintegration.scm.git; | ||
|
||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.BuildListener; | ||
import hudson.plugins.git.GitException; | ||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.eclipse.jgit.lib.ObjectId; | ||
import org.jenkinsci.plugins.gitclient.Git; | ||
import org.jenkinsci.plugins.gitclient.GitClient; | ||
import org.jenkinsci.plugins.gitclient.MergeCommand; | ||
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge; | ||
import org.jenkinsci.plugins.pretestedintegration.IntegrationStrategy; | ||
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegationFailedExeception; | ||
import org.jenkinsci.plugins.pretestedintegration.exceptions.NothingToDoException; | ||
import org.jenkinsci.plugins.pretestedintegration.exceptions.UnsupportedConfigurationException; | ||
|
||
public class GitIntegrationStrategy extends IntegrationStrategy { | ||
|
||
private static final Logger logger = Logger.getLogger(GitIntegrationStrategy.class.getName()); | ||
private static final String LOG_PREFIX = "[PREINT] "; | ||
|
||
@Override | ||
public void integrate(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, AbstractSCMBridge bridge) throws IntegationFailedExeception, NothingToDoException, UnsupportedConfigurationException { | ||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | ||
} | ||
|
||
public boolean tryFastForward(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, GitBridge bridge) throws IntegationFailedExeception{ | ||
logger.log(Level.INFO, String.format(LOG_PREFIX + "Entering tryFastForward")); | ||
|
||
//Get the commit count | ||
int commitCount; | ||
try { | ||
commitCount = bridge.countCommits(build, listener); | ||
logger.log(Level.INFO, String.format(LOG_PREFIX + "Branch commit count: " + commitCount)); | ||
} catch (IOException | InterruptedException ex) { | ||
throw new IntegationFailedExeception("Failed to count commits.", ex); | ||
} | ||
|
||
//Only fast forward if it's a single commit | ||
if (commitCount != 1) { | ||
listener.getLogger().println(String.format(LOG_PREFIX + "Not attempting fast forward. Exiting tryFastForward.")); | ||
return false; | ||
} | ||
|
||
//FF merge the commit | ||
try { | ||
logger.log(Level.INFO, String.format(LOG_PREFIX + "Attempting rebase.")); | ||
GitClient client = Git.with(listener, build.getEnvironment(listener)).in(bridge.resolveWorkspace(build, listener)).getClient(); | ||
ObjectId commitId = bridge.getCommitId(build, listener); | ||
client.merge().setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY).setRevisionToMerge(commitId).execute(); | ||
listener.getLogger().println(String.format(LOG_PREFIX + "FF merge successful.")); | ||
logger.log(Level.INFO, LOG_PREFIX + " Exiting tryFastForward."); | ||
return true; | ||
} catch (GitException | IOException | InterruptedException ex) { | ||
listener.getLogger().println(String.format(LOG_PREFIX + "FF merge failed.")); | ||
logger.log(Level.INFO, LOG_PREFIX + " Exiting tryFastForward."); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.