generate_appcast can update the release notes element’s URL when required

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 7c7e924ed4)
This commit is contained in:
Brad Andalman authored and Gwynne Raskind committed 2020-09-23 07:26:54 -05:00
1 parent 923f15220f
commit 65cab6a14d
1 file changed
+9 -1
+9 -1
View File
@@ -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)
}