29
29
import hudson .model .TaskListener ;
30
30
import hudson .model .queue .Tasks ;
31
31
import hudson .plugins .git .browser .GitRepositoryBrowser ;
32
+ import hudson .plugins .git .extensions .GitClientConflictException ;
33
+ import hudson .plugins .git .extensions .GitClientType ;
34
+ import hudson .plugins .git .extensions .GitSCMChangelogExtension ;
32
35
import hudson .plugins .git .extensions .GitSCMExtension ;
33
36
import hudson .plugins .git .extensions .GitSCMExtensionDescriptor ;
34
37
import hudson .plugins .git .extensions .impl .AuthorInChangelog ;
59
62
import hudson .util .ListBoxModel ;
60
63
import jenkins .model .Jenkins ;
61
64
import jenkins .plugins .git .GitSCMMatrixUtil ;
65
+ import jenkins .plugins .git .LegacyGitSCMChangelogExtension ;
62
66
import net .sf .json .JSONObject ;
63
67
64
68
import org .eclipse .jgit .errors .MissingObjectException ;
@@ -1247,7 +1251,7 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
1247
1251
1248
1252
if (changelogFile != null ) {
1249
1253
computeChangeLog (git , revToBuild .revision , listener , previousBuildData , new FilePath (changelogFile ),
1250
- new BuildChooserContextImpl ( build . getParent (), build , environment ) );
1254
+ build );
1251
1255
}
1252
1256
}
1253
1257
@@ -1266,6 +1270,7 @@ private void printCommitMessageToLog(TaskListener listener, GitClient git, final
1266
1270
}
1267
1271
}
1268
1272
1273
+ // TODO update JavaDoc
1269
1274
/**
1270
1275
* Build up change log from all the branches that we've merged into {@code revToBuild}.
1271
1276
*
@@ -1308,33 +1313,16 @@ private void printCommitMessageToLog(TaskListener listener, GitClient git, final
1308
1313
* Information that captures what we did during the last build. We need this for changelog,
1309
1314
* or else we won't know where to stop.
1310
1315
*/
1311
- private void computeChangeLog (GitClient git , Revision revToBuild , TaskListener listener , BuildData previousBuildData , FilePath changelogFile , BuildChooserContext context ) throws IOException , InterruptedException {
1316
+ private void computeChangeLog (GitClient git , Revision revToBuild , TaskListener listener , BuildData previousBuildData , FilePath changelogFile , Run <?, ?> build ) throws IOException , InterruptedException {
1312
1317
boolean executed = false ;
1313
1318
ChangelogCommand changelog = git .changelog ();
1314
- changelog .includes ( revToBuild . getSha1 ());
1319
+ changelog .max ( MAX_CHANGELOG ); // default to allow override by extensions
1315
1320
try (Writer out = new OutputStreamWriter (changelogFile .write (),"UTF-8" )) {
1316
- boolean exclusion = false ;
1317
- ChangelogToBranch changelogToBranch = getExtensions ().get (ChangelogToBranch .class );
1318
- if (changelogToBranch != null ) {
1319
- listener .getLogger ().println ("Using 'Changelog to branch' strategy." );
1320
- changelog .excludes (changelogToBranch .getOptions ().getRef ());
1321
- exclusion = true ;
1322
- } else {
1323
- for (Branch b : revToBuild .getBranches ()) {
1324
- Build lastRevWas = getBuildChooser ().prevBuildForChangelog (b .getName (), previousBuildData , git , context );
1325
- if (lastRevWas != null && lastRevWas .revision != null && git .isCommitInRepo (lastRevWas .getSHA1 ())) {
1326
- changelog .excludes (lastRevWas .getSHA1 ());
1327
- exclusion = true ;
1328
- }
1329
- }
1330
- }
1321
+ GitSCMChangelogExtension ext = getGitSCMChangelogExtension ();
1322
+ boolean decorated = ext .decorateChangelogCommand (this , build , git , listener , changelog , revToBuild );
1331
1323
1332
- if (!exclusion ) {
1333
- // this is the first time we are building this branch, so there's no base line to compare against.
1334
- // if we force the changelog, it'll contain all the changes in the repo, which is not what we want.
1335
- listener .getLogger ().println ("First time build. Skipping changelog." );
1336
- } else {
1337
- changelog .to (out ).max (MAX_CHANGELOG ).execute ();
1324
+ if (decorated ) {
1325
+ changelog .to (out ).execute ();
1338
1326
executed = true ;
1339
1327
}
1340
1328
} catch (GitException ge ) {
@@ -1344,6 +1332,13 @@ private void computeChangeLog(GitClient git, Revision revToBuild, TaskListener l
1344
1332
}
1345
1333
}
1346
1334
1335
+ private GitSCMChangelogExtension getGitSCMChangelogExtension () {
1336
+ GitSCMChangelogExtension ext = getExtensions ().get (GitSCMChangelogExtension .class );
1337
+ if (ext == null )
1338
+ ext = new LegacyGitSCMChangelogExtension ();
1339
+ return ext ;
1340
+ }
1341
+
1347
1342
@ Override
1348
1343
@ Deprecated // Overrides a deprecated implementation, must also be deprecated
1349
1344
public void buildEnvVars (AbstractBuild <?, ?> build , Map <String , String > env ) {
0 commit comments