From 65cab6a14d3efd49c6cdaa986113317cace2e562 Mon Sep 17 00:00:00 2001 From: Brad Andalman Date: Wed, 2 Sep 2020 18:14:27 -0700 Subject: [PATCH] =?UTF-8?q?generate=5Fappcast=20can=20update=20the=20relea?= =?UTF-8?q?se=20notes=20element=E2=80=99s=20URL=20when=20required?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, generate_appcast could only add or remove the release notes element for an update. This was probably fine, because it was unlikely to change: the release notes URL was determined by the SUFeedURL. However, now that —release-notes-url-prefix was added, the release notes element CAN change. So, with this commit, if the release notes element is present for an update, the URL will be set correctly. (cherry picked from commit 7c7e924ed45603a36a8d6ef1ac4ff5b01659c3e1) --- generate_appcast/FeedXML.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 1834a577..07040b85 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -108,16 +108,24 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { } minVer?.setChildren([text(update.minimumSystemVersion)]) + // Look for an existing release notes element let releaseNotesXpath = "\(SUAppcastElementReleaseNotesLink)" let results = ((try? item.nodes(forXPath: releaseNotesXpath)) as? [XMLElement])? .filter { !($0.attributes ?? []) .contains(where: { $0.name == SUXMLLanguage }) } let relElement = results?.first + if let url = update.releaseNotesURL { - if nil == relElement { + // The update includes a valid release notes URL + if let existingReleaseNotesElement = relElement { + // The existing item includes a release notes element. Update it. + existingReleaseNotesElement.stringValue = url.absoluteString + } else { + // The existing item doesn't have a release notes element. Add one. item.addChild(XMLElement.element(withName: SUAppcastElementReleaseNotesLink, stringValue: url.absoluteString) as! XMLElement) } } else if let childIndex = relElement?.index { + // The update doesn't include a release notes URL. Remove it. item.removeChild(at: childIndex) }