From 43b25a0b6629074fa7aa5e4a4da7f9edc5225127 Mon Sep 17 00:00:00 2001 From: Dylan Sale Date: Mon, 19 Aug 2013 16:24:32 +0930 Subject: [PATCH 1/2] Added option to search for a build notes file and prepend the content to the build notes field. The default path is $WORKSPACE/BUILD_NOTES. It will search for the file exactly to start with and will prepend $WORSKSPACE to the given path if it is not found. --- .../java/testflight/TestflightRecorder.java | 53 +++++++++++++++++-- .../TestflightRecorder/config.jelly | 5 +- .../help-buildNotesPath.html | 5 ++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/testflight/TestflightRecorder/help-buildNotesPath.html diff --git a/src/main/java/testflight/TestflightRecorder.java b/src/main/java/testflight/TestflightRecorder.java index 90f1b91..811f3a6 100644 --- a/src/main/java/testflight/TestflightRecorder.java +++ b/src/main/java/testflight/TestflightRecorder.java @@ -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; @@ -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() { @@ -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; @@ -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(); @@ -271,6 +284,28 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe return ur; } + private File getBuildNotesFile(EnvVars vars, String buildNotesPath) { + 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; + } + } + + 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) { @@ -285,7 +320,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(); diff --git a/src/main/resources/testflight/TestflightRecorder/config.jelly b/src/main/resources/testflight/TestflightRecorder/config.jelly index 64130e1..4c72a4f 100644 --- a/src/main/resources/testflight/TestflightRecorder/config.jelly +++ b/src/main/resources/testflight/TestflightRecorder/config.jelly @@ -46,7 +46,10 @@ - + + + + diff --git a/src/main/resources/testflight/TestflightRecorder/help-buildNotesPath.html b/src/main/resources/testflight/TestflightRecorder/help-buildNotesPath.html new file mode 100644 index 0000000..bb43c6f --- /dev/null +++ b/src/main/resources/testflight/TestflightRecorder/help-buildNotesPath.html @@ -0,0 +1,5 @@ +
+ Will prepend the notes 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. +
From d9c02bce7feca47357e57ed8d447bbfdf66ff4b0 Mon Sep 17 00:00:00 2001 From: Dylan Sale Date: Mon, 19 Aug 2013 20:11:23 +0930 Subject: [PATCH 2/2] fixed possible bug when build notes path is empty or null --- .../java/testflight/TestflightRecorder.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/testflight/TestflightRecorder.java b/src/main/java/testflight/TestflightRecorder.java index 811f3a6..a2a1022 100644 --- a/src/main/java/testflight/TestflightRecorder.java +++ b/src/main/java/testflight/TestflightRecorder.java @@ -285,19 +285,21 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe } private File getBuildNotesFile(EnvVars vars, String buildNotesPath) { - 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()) { + 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; + } + } } - buildNotesFile = new File(vars.expand("$WORKSPACE"),"BUILD_NOTES"); + File buildNotesFile = new File(vars.expand("$WORKSPACE"),"BUILD_NOTES"); if (buildNotesFile.exists()) { return buildNotesFile; }