Skip to content

Commit

Permalink
fix(electron-updater): fix backward compatibility for GitHub provider…
Browse files Browse the repository at this point in the history
… without channels (#6998)
  • Loading branch information
matejkriz committed Jul 16, 2022
1 parent c9f0da5 commit d6115bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-gifts-explain.md
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix(electron-updater): fix backward compatibility for GitHub provider without channels
56 changes: 31 additions & 25 deletions packages/electron-updater/src/providers/GitHubProvider.ts
Expand Up @@ -58,32 +58,38 @@ export class GitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
try {
if (this.updater.allowPrerelease) {
const currentChannel = this.updater?.channel || (semver.prerelease(this.updater.currentVersion)?.[0] as string) || null
for (const element of feed.getElements("entry")) {

if (currentChannel === null) {
// noinspection TypeScriptValidateJSTypes
const hrefElement = hrefRegExp.exec(element.element("link").attribute("href"))!

// If this is null then something is wrong and skip this release
if (hrefElement === null) continue

// This Release's Tag
const hrefTag = hrefElement[1]
//Get Channel from this release's tag
const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || null

const shouldFetchVersion = !currentChannel || ["alpha", "beta"].includes(currentChannel)
const isCustomChannel = !["alpha", "beta"].includes(String(hrefChannel))
// Allow moving from alpha to beta but not down
const channelMismatch = currentChannel === "beta" && hrefChannel === "alpha"

if (shouldFetchVersion && !isCustomChannel && !channelMismatch) {
tag = hrefTag
break
}

const isNextPreRelease = hrefChannel && hrefChannel === currentChannel
if (isNextPreRelease) {
tag = hrefTag
break
tag = hrefRegExp.exec(latestRelease.element("link").attribute("href"))![1]
} else {
for (const element of feed.getElements("entry")) {
// noinspection TypeScriptValidateJSTypes
const hrefElement = hrefRegExp.exec(element.element("link").attribute("href"))!

// If this is null then something is wrong and skip this release
if (hrefElement === null) continue

// This Release's Tag
const hrefTag = hrefElement[1]
//Get Channel from this release's tag
const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || null

const shouldFetchVersion = !currentChannel || ["alpha", "beta"].includes(currentChannel)
const isCustomChannel = !["alpha", "beta"].includes(String(hrefChannel))
// Allow moving from alpha to beta but not down
const channelMismatch = currentChannel === "beta" && hrefChannel === "alpha"

if (shouldFetchVersion && !isCustomChannel && !channelMismatch) {
tag = hrefTag
break
}

const isNextPreRelease = hrefChannel && hrefChannel === currentChannel
if (isNextPreRelease) {
tag = hrefTag
break
}
}
}
} else {
Expand Down

0 comments on commit d6115bc

Please sign in to comment.