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

Build notes file path #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
55 changes: 52 additions & 3 deletions src/main/java/testflight/TestflightRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import hudson.util.RunList;
import hudson.util.Secret;
import org.apache.commons.collections.Predicate;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import hudson.model.Hudson;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

import net.sf.json.JSONObject;
Expand Down Expand Up @@ -56,6 +60,13 @@ public String getBuildNotes() {
return this.buildNotes;
}

private String buildNotesPath;

public String getBuildNotesPath() {
return this.buildNotesPath;
}


private boolean appendChangelog;

public boolean getAppendChangelog() {
Expand Down Expand Up @@ -131,12 +142,13 @@ 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 buildNotesPath, String buildNotes, Boolean appendChangelog, 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.buildNotesPath = buildNotesPath;
this.appendChangelog = appendChangelog;
this.filePath = filePath;
this.dsymPath = dsymPath;
Expand Down Expand Up @@ -257,7 +269,8 @@ 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());
File buildNotesFile = getBuildNotesFile(vars, buildNotesPath);
ur.buildNotes = createBuildNotes(buildNotesFile, vars.expand(buildNotes), build.getChangeSet());
ur.lists = vars.expand(lists);
ur.notifyTeam = notifyTeam;
ProxyConfiguration proxy = getProxy();
Expand All @@ -271,6 +284,30 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
return ur;
}

private File getBuildNotesFile(EnvVars vars, String buildNotesPath) {
if(buildNotesPath != null && !buildNotesPath.isEmpty()) {
buildNotesPath = vars.expand(buildNotesPath);
File buildNotesFile = new File(buildNotesPath);
if(buildNotesFile.exists()) {
return buildNotesFile;
}
else {
buildNotesFile = new File(vars.expand("$WORKSPACE"), buildNotesPath);
if (buildNotesFile.exists()) {
return buildNotesFile;
}
}
}

File buildNotesFile = new File(vars.expand("$WORKSPACE"),"BUILD_NOTES");
if (buildNotesFile.exists()) {
return buildNotesFile;
}

return null;
}


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

// Append the changelog if we should and can
private String createBuildNotes(String buildNotes, final ChangeLogSet<?> changeSet) {
private String createBuildNotes(File buildNotesFile, String buildNotes, final ChangeLogSet<?> changeSet) {
if(buildNotesFile != null) {
try {
String fileContents = FileUtils.readFileToString(buildNotesFile, "UTF-8");
buildNotes = fileContents + "\n\n" + buildNotes;
} catch (FileNotFoundException e) {
//the file should have been checked if it exists, but if not, just ignore it.
} catch (IOException e) {
//ignore it
}
}


if (appendChangelog) {
StringBuilder stringBuilder = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
</f:entry>
</table>
</f:repeatable>
</f:entry>
</f:entry>
<f:entry title="Build Notes Path" field="buildNotesPath">
<f:textbox />
</f:entry>
<f:entry title="Build Notes" field="buildNotes">
<f:textarea />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
Will prepend the <i>notes</i> Testflight API parameter to the contents of the file at the path.
Note: the append change log option modifies it.
Defaults to $WORKSPACE/BUILD_NOTES. Will try to prepend $WORKSPACE if the file does not exist.
</div>