Skip to content
Open
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
57 changes: 53 additions & 4 deletions src/main/java/testflight/TestflightRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public boolean getAppendChangelog() {
return this.appendChangelog;
}

private boolean combineChangelogSinceLastSuccess;

public boolean getCombineChangelogSinceLastSuccess() {
return this.combineChangelogSinceLastSuccess;
}

/**
* Comma- or space-separated list of patterns of files/directories to be archived.
* The variable hasn't been renamed yet for compatibility reasons
Expand Down Expand Up @@ -131,13 +137,14 @@ public Boolean getDebug() {
}

@DataBoundConstructor
public TestflightRecorder(String tokenPairName, Secret apiToken, Secret teamToken, Boolean notifyTeam, String buildNotes, Boolean appendChangelog, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort, Boolean debug, TestflightTeam [] additionalTeams) {
public TestflightRecorder(String tokenPairName, Secret apiToken, Secret teamToken, Boolean notifyTeam, String buildNotes, Boolean appendChangelog, Boolean combineChangelogSinceLastSuccess, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort, Boolean debug, TestflightTeam [] additionalTeams) {
this.tokenPairName = tokenPairName;
this.apiToken = apiToken;
this.teamToken = teamToken;
this.notifyTeam = notifyTeam;
this.buildNotes = buildNotes;
this.appendChangelog = appendChangelog;
this.combineChangelogSinceLastSuccess = combineChangelogSinceLastSuccess;
this.filePath = filePath;
this.dsymPath = dsymPath;
this.replace = replace;
Expand Down Expand Up @@ -257,7 +264,9 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
ur.filePaths = vars.expand(StringUtils.trim(team.getFilePath()));
ur.dsymPath = vars.expand(StringUtils.trim(team.getDsymPath()));
ur.apiToken = vars.expand(Secret.toString(tokenPair.getApiToken()));
ur.buildNotes = createBuildNotes(vars.expand(buildNotes), build.getChangeSet());

List<Entry> entries = combineChangelogSinceLastSuccess ? getChangeSetEntriesSinceLastSuccess(build) : getChangeSetEntries(build);
ur.buildNotes = createBuildNotes(vars.expand(buildNotes), entries);
ur.lists = vars.expand(lists);
ur.notifyTeam = notifyTeam;
ProxyConfiguration proxy = getProxy();
Expand All @@ -271,6 +280,46 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
return ur;
}

private List<Entry> getChangeSetEntries(AbstractBuild<?, ?> build) {
ArrayList<Entry> entries = new ArrayList<Entry>();
ChangeLogSet<?> changeSet = build.getChangeSet();
for (Entry entry : changeSet) {
entries.add(entry);
}
return entries;
}

private List<Entry> getChangeSetEntriesSinceLastSuccess(AbstractBuild<?, ?> build) {
ArrayList<Entry> entries = new ArrayList<Entry>();

//The next build after the last successful one should either be a failure, or the current build.
//It could be in progress I guess, but we should probably just append the changelog anyway.
AbstractBuild<?, ?> lastBuild = build.getPreviousSuccessfulBuild();
if(lastBuild != null) {
lastBuild = lastBuild.getNextBuild();
}
else {
return getChangeSetEntries(build);
}

while(lastBuild != null) {

ChangeLogSet<?> changeSet = lastBuild.getChangeSet();
if(changeSet != null) {
for (Entry entry : changeSet) {
entries.add(entry);
}
}

if(lastBuild.equals(build))
break;

lastBuild = lastBuild.getNextBuild();
}

return entries;
}

private ProxyConfiguration getProxy() {
ProxyConfiguration proxy;
if (Hudson.getInstance() != null && Hudson.getInstance().proxy != null) {
Expand All @@ -285,7 +334,7 @@ private ProxyConfiguration getProxy() {
}

// Append the changelog if we should and can
private String createBuildNotes(String buildNotes, final ChangeLogSet<?> changeSet) {
private String createBuildNotes(String buildNotes, final List<Entry> changeSet) {
if (appendChangelog) {
StringBuilder stringBuilder = new StringBuilder();

Expand All @@ -294,7 +343,7 @@ private String createBuildNotes(String buildNotes, final ChangeLogSet<?> changeS

// Then append the changelog
stringBuilder.append("\n\n")
.append(changeSet.isEmptySet() ? Messages.TestflightRecorder_EmptyChangeSet() : Messages.TestflightRecorder_Changelog())
.append(changeSet.isEmpty() ? Messages.TestflightRecorder_EmptyChangeSet() : Messages.TestflightRecorder_Changelog())
.append("\n");

int entryNumber = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/testflight/TestflightRecorder/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
<f:checkbox />
</f:entry>
<f:advanced>
<f:entry title="Combine all changelogs in builds since the last successful one for the build notes. This will not actually append them." field="combineChangelogSinceLastSuccess">
<f:checkbox />
</f:entry>
<f:entry title="Distribution Lists" field="lists">
<f:textbox />
</f:entry>
Expand Down