Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Oct 31, 2023
1 parent 4bf04b8 commit bfd902a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All notable changes to homebridge-config-ui-x will be documented in this file.
### Notable Changes

- Show UI and plugin updates for newer beta versions when already running a beta version of the plugin
- Note: this only works when using an npm tag called `beta`
- Note: this only works when a plugin uses a `beta` NPM tag for beta releases
- Show 'Restart Homebridge Now' modal (with additional messaging for child bridges) after any plugin update, not just the UI

### i18n Changes
Expand Down
54 changes: 22 additions & 32 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,40 +854,30 @@ export class PluginsService {

// Special case for beta npm tags for homebridge, homebridge ui and all plugins
if (plugin.latestVersion?.includes('beta')) {
switch (plugin.name) {
case 'homebridge':
case 'homebridge-config-ui-x': {
// If loading a homebridge/ui beta returned pre-defined help text
// Query the list of branches for the repo, if the request doesn't work it doesn't matter too much
let betaBranch: string;
try {
// Find the first branch that starts with "beta"
betaBranch = (await this.httpService.get(`https://api.github.com/repos/homebridge/${plugin.name}/branches`).toPromise())
.data
.find((branch: any) => branch.name.startsWith('beta-'))
?.name;
} catch (e) {
this.logger.error(`Failed to get list of branches from GitHub: ${e.message}`);
}
return {
name: 'v' + plugin.latestVersion,
changelog: `Thank you for helping improve Homebridge by testing the beta build for \`${plugin.name}\`.\n\n` +
'To see what needs testing or to report issues:\n' +
`- https://github.com/homebridge/${plugin.name}/issues` +
`${betaBranch && `\n\nSee the commit history for recent changes:\n- https://github.com/homebridge/${plugin.name}/commits/${betaBranch}`}`,
};
}
default: {
// If loading any other plugin beta, return some generic text for now
return {
name: 'v' + plugin.latestVersion,
changelog: `Thank you for helping improve \`${pluginName}\` by testing the beta build.\n\n` +
'You can use the Homebridge UI at any time to revert back to the stable version of this plugin.\n\n' +
'Please remember this is a **test** version of the plugin, and report any issues to the plugin\'s GitHub page:\n' +
`- https://github.com/${repoMatch[1]}/${repoMatch[2]}/issues`,
};
let betaBranch: string | undefined;

if (['homebridge-config-ui-x', 'homebridge'].includes(plugin.name)) {
// If loading a homebridge/ui beta returned pre-defined help text
// Query the list of branches for the repo, if the request doesn't work it doesn't matter too much
try {
// Find the first branch that starts with "beta"
betaBranch = (await this.httpService.get(`https://api.github.com/repos/homebridge/${plugin.name}/branches`).toPromise())
.data
.find((branch: any) => branch.name.startsWith('beta-'))
?.name;
} catch (e) {
this.logger.error(`Failed to get list of branches from GitHub: ${e.message}`);
}
}

return {
name: 'v' + plugin.latestVersion,
changelog: `Thank you for helping improve ${plugin.displayName || `\`${plugin.name}\`.`} by testing the beta build.\n\n` +
'You can use the Homebridge UI at any time to revert back to the stable version.\n\n' +
'Please remember this is a **test** version, and report any issues to the GitHub repository page:\n' +
`- https://github.com/${repoMatch[1]}/${repoMatch[2]}/issues` +
`${betaBranch && `\n\nSee the commit history for recent changes:\n- https://github.com/${repoMatch[1]}/${repoMatch[2]}/commits/${betaBranch}`}`,
};
}

try {
Expand Down

0 comments on commit bfd902a

Please sign in to comment.