Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add a new action if already attached by a parallel step #220

Merged
merged 2 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<url>https://github.com/jenkinsci/git-forensics-plugin</url>

<properties>
<revision>0.10.0</revision>
<revision>0.9.1</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>${project.groupId}.git.forensics</module.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ private void recordNewCommits(final Run<?, ?> build, final GitRepositoryValidato

String latestRecordedCommit = getLatestRecordedCommit(build, id, logger);
GitCommitsRecord commitsRecord = recordNewCommits(build, gitRepository, logger, latestRecordedCommit);
build.addAction(commitsRecord);
if (!hasRecordForScm(build, id)) { // In case a parallel step has added the same result in the meanwhile
build.addAction(commitsRecord);
}
}

private String getLatestRecordedCommit(final Run<?, ?> build, final String scmKey, final FilteredLog logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ public void shouldDecorateSeveralRepositories() {
verifyAction(actions.get(1), GIT_FORENSICS_URL);
}

/**
* Creates a pipeline that checks out the same repository twice.
*/
@Test
public void shouldSkipDuplicateRepositories() {
WorkflowJob job = createPipeline();
job.setDefinition(asStage(
"checkout([$class: 'GitSCM', "
+ "branches: [[name: 'a6d0ef09ab3c418e370449a884da99b8190ae950' ]],\n"
+ "userRemoteConfigs: [[url: '" + FORENSICS_API_URL + "']],\n"
+ "extensions: [[$class: 'RelativeTargetDirectory', \n"
+ " relativeTargetDir: 'forensics-api']]])",
"checkout([$class: 'GitSCM', "
+ "branches: [[name: 'a6d0ef09ab3c418e370449a884da99b8190ae950' ]],\n"
+ "userRemoteConfigs: [[url: '" + FORENSICS_API_URL + "']],\n"
+ "extensions: [[$class: 'RelativeTargetDirectory', \n"
+ " relativeTargetDir: 'forensics-api']]])"));

List<GitCommitsRecord> actions = buildSuccessfully(job).getActions(GitCommitsRecord.class);
assertThat(actions).hasSize(1);

verifyAction(actions.get(0), FORENSICS_API_URL);
}

private void verifyAction(final GitCommitsRecord record, final String repository) {
assertThat(record.getInfoMessages())
.contains("Recording commits of 'git " + repository + "'",
Expand Down