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

Patch 1 #6

Closed
wants to merge 2 commits into from
Closed
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
37 changes: 33 additions & 4 deletions src/main/java/testflight/TestflightRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import hudson.model.AbstractBuild;
import hudson.tasks.*;
import hudson.util.RunList;
import hudson.scm.ChangeLogSet.*;
import hudson.scm.ChangeLogSet;
import org.apache.commons.collections.Predicate;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
Expand All @@ -32,6 +34,7 @@
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.StaplerRequest;


public class TestflightRecorder extends Recorder
{
private String apiToken;
Expand All @@ -52,6 +55,12 @@ public Boolean getNotifyTeam()
return this.notifyTeam;
}

private Boolean sendSCMchanges;
public Boolean getSendSCMchanges()
{
return this.sendSCMchanges;
}

private String buildNotes;
public String getBuildNotes()
{
Expand Down Expand Up @@ -107,12 +116,13 @@ public int getProxyPort()
}

@DataBoundConstructor
public TestflightRecorder(String apiToken, String teamToken, Boolean notifyTeam, String buildNotes, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort)
public TestflightRecorder(String apiToken, String teamToken, Boolean notifyTeam, Boolean sendSCMchanges, String buildNotes, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort)
{
this.teamToken = teamToken;
this.apiToken = apiToken;
this.notifyTeam = notifyTeam;
this.buildNotes = buildNotes;
this.sendSCMchanges = sendSCMchanges;
this.buildNotes = buildNotes;
this.filePath = filePath;
this.dsymPath = dsymPath;
this.replace = replace;
Expand Down Expand Up @@ -178,10 +188,29 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
HttpPost httpPost = new HttpPost("/api/builds.json");
FileBody fileBody = new FileBody(file);

MultipartEntity entity = new MultipartEntity();
String notes = "";
Copy link
Member

Choose a reason for hiding this comment

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

Maybe initialize the variable with default build notes first, like this:

String notes = vars.expand(buildNotes);

Then the logic below can be simplified a bit.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, you're right

if (sendSCMchanges) {
ChangeLogSet changeSet = build.getChangeSet();
if (changeSet.isEmptySet()) {
notes = vars.expand(buildNotes);
listener.getLogger().println("No changeset found, sending default build notes to TestFlight");
}
else {
for (Object changelog : changeSet.getItems()) {
notes = notes + ((ChangeLogSet.Entry)changelog).getMsg() + "\n";
}
}
}
else
notes = vars.expand(buildNotes);

MultipartEntity entity = new MultipartEntity();
entity.addPart("api_token", new StringBody(apiToken));
entity.addPart("team_token", new StringBody(teamToken));
entity.addPart("notes", new StringBody(vars.expand(buildNotes)));
//entity.addPart("notes", new StringBody(vars.expand(buildNotes)));
Copy link
Member

Choose a reason for hiding this comment

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

Remember to remove code you have commented out

// Add the notes from the SCM changelogs
entity.addPart("notes", new StringBody(notes));
listener.getLogger().println("Notes to send to TestFlight: " + notes);
entity.addPart("file", fileBody);

if (!StringUtils.isEmpty(dsymPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
<f:entry title="dSYM File" field="dsymPath">
<f:textbox />
</f:entry>
<f:entry title="Build Notes" field="buildNotes">
<f:entry title="Send SCM changes as build notes" field="sendSCMchanges">
<f:checkbox />
</f:entry>
<f:entry title="Default Build Notes" field="buildNotes">
<f:textarea />
</f:entry>
<f:advanced>
Expand Down