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

[JENKINS-4162] Optionally report the most recent commit as the changelog of a new build #1565

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3e62161
Add files via upload
rhit-inskeeda Mar 20, 2024
838cc41
code for gui
rhit-inskeeda Mar 20, 2024
d76a507
trait file
rhit-inskeeda Mar 20, 2024
5f681b3
gitscm changes
rhit-inskeeda Mar 20, 2024
756f77c
testing for new trait behavior
rhit-inskeeda Mar 20, 2024
b5ba0e8
Merge pull request #1 from rhit-inskeeda/new-trait
rhit-inskeeda Mar 20, 2024
d6f6cf9
null check time
rhit-gawronja Mar 20, 2024
27d5942
update to proper version number
rhit-inskeeda Mar 22, 2024
ce2fd99
Update FirstBuildChangelogTrait
rhit-inskeeda Mar 22, 2024
d17fafd
Merge branch 'master' into integration
MarkEWaite Apr 2, 2024
370d763
Format new files with spotless:apply
MarkEWaite Apr 2, 2024
c66d139
Remove trailing space characters
MarkEWaite Apr 2, 2024
88640c5
Changed equals to use proper equals method
rhit-gawronja Apr 2, 2024
62aad20
Changed equals to use proper equals method
rhit-gawronja Apr 2, 2024
cab31cc
Changed equals to use proper equals method
rhit-gawronja Apr 2, 2024
baa7384
Merge remote-tracking branch 'origin/integration' into integration
rhit-gawronja Apr 2, 2024
84846d7
changed to compatible equal
rhit-gawronja Apr 2, 2024
6f4fa4d
Fix Mark's poor code review
MarkEWaite Apr 2, 2024
1664429
Use leading lower case letter for the symbol
MarkEWaite Apr 2, 2024
47ab82b
Use sentence case for display name
MarkEWaite Apr 2, 2024
a9eacdf
Set API release to 5.3.0
MarkEWaite Apr 2, 2024
24c444b
Merge branch 'master' into integration
MarkEWaite Apr 8, 2024
143b0d2
removed groovy and checkbox
rhit-inskeeda Apr 16, 2024
ae92de6
Merge pull request #2 from rhit-inskeeda/no-groovy
rhit-inskeeda Apr 16, 2024
5dfe120
Update to documentation and applying spotless
rhit-gawronja Apr 17, 2024
a803d34
Pushing documentation image
rhit-gawronja Apr 17, 2024
45e7fff
Undo spotless changes - not ready for spotless
MarkEWaite May 1, 2024
4499e95
Reduce doc diffs
MarkEWaite May 1, 2024
591d0da
Merge branch 'master' into integration
MarkEWaite May 1, 2024
8df79db
Use Unix file format for help
MarkEWaite May 1, 2024
667a4fa
Jenkins Pipeline symbols start with a lower case letter
MarkEWaite May 1, 2024
11955ee
Remove blank line from doc example
MarkEWaite May 1, 2024
34be383
First build changelog reports most recent commit as changelog
MarkEWaite May 1, 2024
13816f4
Format new example same as prior examples.
MarkEWaite May 4, 2024
81606a6
Clarify first build option help and docs
MarkEWaite May 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import hudson.plugins.git.extensions.impl.BuildSingleRevisionOnly;
import hudson.plugins.git.extensions.impl.ChangelogToBranch;
import hudson.plugins.git.extensions.impl.CloneOption;
import hudson.plugins.git.extensions.impl.FirstBuildChangelog;
import hudson.plugins.git.extensions.impl.PathRestriction;
import hudson.plugins.git.extensions.impl.LocalBranch;
import hudson.plugins.git.extensions.impl.RelativeTargetDirectory;
Expand Down Expand Up @@ -1493,9 +1494,18 @@
}

if (!exclusion) {
// this is the first time we are building this branch, so there's no base line to compare against.
// if we force the changelog, it'll contain all the changes in the repo, which is not what we want.
listener.getLogger().println("First time build. Skipping changelog.");
FirstBuildChangelog firstBuildChangelog = getExtensions().get(FirstBuildChangelog.class);
if (firstBuildChangelog!=null&&firstBuildChangelog.isMakeChangelog()) {

Check warning on line 1498 in src/main/java/hudson/plugins/git/GitSCM.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1498 is only partially covered, one branch is missing
changelog.to(out).max(1).execute();
executed = true;
listener.getLogger().println("First time build. Latest changes added to changelog.");
} else {
// this is the first time we are building this branch, so there's no base line
// to compare against.
// if we force the changelog, it'll contain all the changes in the repo, which
// is not what we want.
Comment on lines +1503 to +1506
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this existing comment should be rewritten now that its within the context of the else case of the new option. But, perhaps just removing it would be best.

listener.getLogger().println("First time build. Skipping changelog.");
}
} else {
changelog.to(out).max(MAX_CHANGELOG).execute();
executed = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package hudson.plugins.git.extensions.impl;
rhit-gawronja marked this conversation as resolved.
Show resolved Hide resolved

import hudson.Extension;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
import java.util.Objects;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* First Build generates a changelog.
*
* @author Derek Inskeep
*/
public class FirstBuildChangelog extends GitSCMExtension {
private boolean makeChangelog;

@DataBoundConstructor
public FirstBuildChangelog() {
}

public boolean isMakeChangelog() {
return makeChangelog;
}

@DataBoundSetter
public void setMakeChangelog(boolean makeChangelog) {
this.makeChangelog = makeChangelog;
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FirstBuildChangelog that = (FirstBuildChangelog) o;
return makeChangelog == that.makeChangelog;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hash(makeChangelog);
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "FirstBuildChangelog{" +

Check warning on line 61 in src/main/java/hudson/plugins/git/extensions/impl/FirstBuildChangelog.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 38-61 are not covered by tests
"makeChangelog=" + makeChangelog +
'}';
}

@Extension
@Symbol("FirstBuildChangelog")
public static class DescriptorImpl extends GitSCMExtensionDescriptor {

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "First Build Changelog";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package jenkins.plugins.git.traits;

import hudson.Extension;
import hudson.plugins.git.extensions.impl.FirstBuildChangelog;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
* Exposes {@link FirstBuildChangelog} as a {@link SCMSourceTrait}.
*
* @since 5.2.0
*/
public class FirstBuildChangelogTrait extends GitSCMExtensionTrait<FirstBuildChangelog> {

/**
* @deprecated Use constructor that accepts extension instead.
*/
@Deprecated
public FirstBuildChangelogTrait() {
this(null);
}

/**
* Stapler constructor.
*
* @param extension the option to force first build to have a non-empty changelog.
*/
@DataBoundConstructor
public FirstBuildChangelogTrait(@CheckForNull FirstBuildChangelog extension) {
super(extension == null ? new FirstBuildChangelog() : extension);
}

Check warning on line 34 in src/main/java/jenkins/plugins/git/traits/FirstBuildChangelogTrait.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 23-34 are not covered by tests

/**
* Our {@link hudson.model.Descriptor}
*/
@Extension
@Symbol("FirstBuildChangelog")
public static class DescriptorImpl extends GitSCMExtensionTraitDescriptor {
/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "First Build Changelog";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hudson.plugins.git.extensions.impl.FirstBuildChangelog

def f = namespace(lib.FormTagLib)

f.entry(field: "makeChangelog") {
f.checkbox(title: _("Make Changelog"))
}
rhit-gawronja marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
First builds create changelog of latest commit, if any.
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
First builds will populate the changelog with the latest commit, if any, to allow for pipelines to consistently check and test for file changes.
</div>
20 changes: 20 additions & 0 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,26 @@ public void testCleanBeforeCheckout() throws Exception {
assertThat("Cleaning should happen before fetch", cleaningLogLine, is(lessThan(fetchingLogLine)));
}

@Test
public void testFirstBuiltChangelog() throws Exception {
assumeTrue("Test class max time " + MAX_SECONDS_FOR_THESE_TESTS + " exceeded", isTimeAvailable());
FreeStyleProject p = setupProject("master", false, null, null, "Jane Doe", null);
FirstBuildChangelog fbc = new FirstBuildChangelog();
fbc.setMakeChangelog(true);
((GitSCM) p.getScm()).getExtensions().add(fbc);

rhit-gawronja marked this conversation as resolved.
Show resolved Hide resolved
/* First build should should generate a changelog */
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, janeDoe, "Commit number 1");
final FreeStyleBuild firstBuild = build(p, Result.SUCCESS, commitFile1);
assertThat(firstBuild.getLog(50), hasItem("First time build. Latest changes added to changelog."));
/* Second build should have normal behavior */
final String commitFile2 = "commitFile2";
commit(commitFile2, johnDoe, janeDoe, "Commit number 2");
final FreeStyleBuild secondBuild = build(p, Result.SUCCESS, commitFile2);
assertThat(secondBuild.getLog(50), not(hasItem("First time build. Latest changes added to changelog.")));
}

@Issue("JENKINS-8342")
@Test
public void testExcludedRegionMultiCommit() throws Exception {
Expand Down