Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-29369 Fix locale dependent accumulated msg
The accumulated commit message is now using english locale when
formatting date and time. The commit message is generated by the plugin
and formatted to look like the squash commit message except for the
header line.

Tests have been improved to include detailed commit message asserts and
extend to include few more tests for squashed also.
Each test now verifies that the formatting of dates are correct for the
tests regarding special charecters and custom integration branch (those
were the newer tests we added so the follow a better design).

Other improvements and refactoring:

- removed un-used code in squash commit strategy
- removed debug print of squash commit strategy to build console
- add debug printing of exception during integration to the build
  console
- fixed minor bug in test utils regarding printing console which is null
- test base class for static git repos extended to print out cleaning
  repos and temp files
  • Loading branch information
Bue Petersen committed Jul 12, 2015
1 parent 3495706 commit 9b4e052
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 93 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -104,6 +104,26 @@ Publish changes on success:

_We currently miss documentation on a lot of the design decisions - they should go into this document._

## The accumulated commit message

The accumulated commit message can not be generated automatically by git, as the squashed message, so the plugin must collect, extract and format the needed information from the commits that goes into the integration commit.
This means that locale settings and language in the environment affect the string formatting regarding dates.
It is an early decision that the accumulated commit message should look the squash commit message.

To make the accumulated commit message look almost identical to the squash message, we use english formatting of the date strings as this seems to be the default behavior for git squash commit message, if autogenerated. Independent from environments.

See the `GetAllCommitsFromBranchCallback` for actual implementation.

Message formatting:

* commit, author and date are indented with spaces to match vertically
* indentation of the individual commit messages (headers and body) is also done with space, not tabs
* date is string formatted using Java simple date formatter, with "EEE MMM d kk:mm:ss yyyy ZZZZ" and English locale.

See the plugin wiki page for more information on example commits and demo jobs: [Demo jobs and example on commit messages and output](https://wiki.jenkins-ci.org/display/JENKINS/Pretested+Integration+Plugin#PretestedIntegrationPlugin-Demojobsandexampleoncommitmessagesandoutput)

Relates to [JENKINS-29369](https://issues.jenkins-ci.org/browse/JENKINS-29369).

# Only one integration repository is supported

* **Integration only support one repository**: Doing pretested integration on several repositories as the same time would not make sense conceptually. There should also be a 1:1 relation between a Jenkins job and a repository as a best practice. Further it would not be possible to make pretested integration as an atomic non interuptable operation on several repositories. For example if they both integrate successfully, but publishing result fails on the second one. What should then happen with the first one?
Expand Down
Expand Up @@ -135,6 +135,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// which also print out the exception to the job console to let the
// user easily investigate.
logger.log(Level.SEVERE, "Exception while merging. Logging exception", ex);
listener.getLogger().println(LOG_PREFIX + String.format("Exception while merging. Logging exception msg: %s", ex.getMessage()));
logger.exiting("AccumulatedCommitStrategy", "integrate-mergeFailure");
throw new IntegationFailedExeception(ex);
}
Expand Down Expand Up @@ -179,6 +180,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// which also print out the exception to the job console to let the
// user easily investigate.
logger.log(Level.SEVERE, "Exception while comitting. Logging exception", ex);
listener.getLogger().println(LOG_PREFIX + String.format("Exception while committing. Logging exception msg: %s", ex.getMessage()));
logger.exiting("AccumulatedCommitStrategy", "integrate-commitFailure");
throw new IntegationFailedExeception(ex);
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.eclipse.jgit.lib.ObjectId;
Expand Down Expand Up @@ -64,11 +65,15 @@ public String invoke(Repository repo, VirtualChannel channel) throws IOException
Integer secondsSinceUnixEpoch = rev.getCommitTime();
// Note that the git log shows different date formats, depending on configuration.
// The choices in the git commit message below matches the squashed commit message
// that git generates on a Ubuntu Linux 14.04 with default git installation.
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM d kk:mm:ss yyyy ZZZZ");
// that git generates on a Ubuntu Linux 14.04 with default git installation.
// Locale if forced to enligsh to make it independent from operating system
// and environment.
// Note that it is not the standard ISO format.
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM d kk:mm:ss yyyy ZZZZ", Locale.ENGLISH);
Date commitTime = new Date(secondsSinceUnixEpoch * 1000L); // seconds to milis
String asString = formatter.format(commitTime);
sb.append(String.format("Date: %s", asString ));

sb.append(String.format("%n"));
sb.append(String.format("%n"));

Expand Down
Expand Up @@ -57,14 +57,14 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
Branch gitDataBranch = gitBuildData.lastBuild.revision.getBranches().iterator().next();
GitClient client;

String integrationSHA = "Not specified";
try {
logger.fine("Getting current integration SHA");
integrationSHA = (String) build.getAction(PretestedIntegrationAction.class).getCurrentIntegrationTip().getId();
logger.fine("Found integration SHA");
} catch (Exception ex) {
logger.log(Level.SEVERE, "Integrate() error, integration SHA not found", ex);
}
// String integrationSHA = "Not specified";
// try {
// logger.fine("Getting current integration SHA");
// integrationSHA = (String) build.getAction(PretestedIntegrationAction.class).getCurrentIntegrationTip().getId();
// logger.fine("Found integration SHA");
// } catch (Exception ex) {
// logger.log(Level.SEVERE, "Integrate() error, integration SHA not found", ex);
// }

logger.log(Level.INFO, String.format("Preparing to merge changes in commit %s on development branch %s to integration branch %s", gitDataBranch.getSHA1String(), gitDataBranch.getName(), gitbridge.getBranch()));
listener.getLogger().println(String.format(LOG_PREFIX + "Preparing to merge changes in commit %s on development branch %s to integration branch %s", gitDataBranch.getSHA1String(), gitDataBranch.getName(), gitbridge.getBranch()));
Expand Down Expand Up @@ -103,11 +103,9 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
}

String commitAuthor; //leaving un-assigned, want to fail later if not assigned
String commitMessage; //leaving un-assigned, want to fail later if not assigned
try {
logger.log(Level.INFO, String.format(LOG_PREFIX + "Collecting commit messages on development branch (for debug printing): %s", gitDataBranch.getName()));
listener.getLogger().println(String.format(LOG_PREFIX + "Collecting commit messages on development branch (for debug printing): %s", gitDataBranch.getName()));
commitMessage = client.withRepository(new FindCommitMessageCallback(listener, gitDataBranch.getSHA1()));
logger.log(Level.INFO, String.format(LOG_PREFIX + "Done collecting commit messages"));
listener.getLogger().println(String.format(LOG_PREFIX + "Done collecting commit messages"));

Expand All @@ -131,6 +129,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// which also print out the exception to the job console to let the
// user easily investigate.
logger.log(Level.SEVERE, "Exception while merging. Logging exception", ex);
listener.getLogger().println(LOG_PREFIX + String.format("Exception while merging. Logging exception msg: %s", ex.getMessage()));
logger.exiting("SquashCommitStrategy", "integrate-mergeFailure");
throw new IntegationFailedExeception(ex);
}
Expand Down Expand Up @@ -169,12 +168,6 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
logger.info("Commit of squashed merge done");
listener.getLogger().println(String.format(LOG_PREFIX + "Commit of squashed merge done"));

// This is for debugging only, so basically FindCommitMessageCallback
// can be removed. We are though planning features that might need
// this method again, to change the commit message, so we leave it
// for now.
listener.getLogger().println(String.format(LOG_PREFIX + "Debug print - commit message for squash merge:%n%s", commitMessage));
logger.info(String.format(LOG_PREFIX + "Debug print - commit message for squash merge:%n%s", commitMessage));
} catch (Exception ex) {
// We handle all exceptions here, as we will not continue with
// anything if there is problems, even if it is only null pointer
Expand All @@ -183,7 +176,8 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
// which also print out the exception to the job console to let the
// user easily investigate.
logger.log(Level.SEVERE, "Exception while merging or comitting, logging exception", ex);
logger.exiting("SquashCommitStrategy", "integrate-mergeFailure");
listener.getLogger().println(LOG_PREFIX + String.format("Exception while committing. Logging exception msg: %s", ex.getMessage()));
logger.exiting("SquashCommitStrategy", "integrate-commitFailure");
throw new IntegationFailedExeception(ex);
}
// NOTICE: The catch-throw exception above means we have handles all
Expand Down
Expand Up @@ -67,8 +67,7 @@ public BuildResultValidator retain() {


public void validate() throws Exception {
System.out.println(consoleLog);

//System.out.println(consoleLog); // seems to always be null
if(consolePhrases != null) {
validateConsoleMessages();
}
Expand Down Expand Up @@ -122,11 +121,11 @@ private boolean validateHeadCommitMessage() throws ValidationException, Exceptio
while(i.hasNext()) {
commit = walk.parseCommit(i.next());
if(commit.equals(head)) {
System.out.println(commit.getFullMessage());
boolean match = true;
boolean matched = false;
for(String s : contents) {
matched = true;
System.out.println(commit.getFullMessage());
match &= commit.getFullMessage().contains(s);
}

Expand Down

0 comments on commit 9b4e052

Please sign in to comment.