Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/api/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ export function displayChannels(data: Channel[]) {
}

export async function getActiveChannels(supabase: SupabaseClient<Database>, appid: string) {
const { data, error: vError } = await supabase
.from('channels')
.select(`
const [{ data, error: vError }, { data: appData, error: appError }] = await Promise.all([
supabase
.from('channels')
.select(`
id,
name,
public,
allow_emulator,
allow_dev,
ios,
Expand All @@ -159,13 +159,24 @@ export async function getActiveChannels(supabase: SupabaseClient<Database>, appi
app_id,
version (id, name)
`)
.eq('app_id', appid)
// .eq('created_by', userId)
.order('created_at', { ascending: false })
.eq('app_id', appid)
.order('created_at', { ascending: false }),

if (vError) {
supabase.from('apps')
.select('default_channel_ios, default_channel_android')
.eq('app_id', appid)
.single(),
])

if (vError || appError) {
log.error(`App ${appid} not found in database`)
console.log(vError, appError)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Use allowed logging methods to fix pipeline error
ESLint forbids console.log; replace it with log.warn or log.error to comply with your logging guidelines and stop the pipeline failure.

-    console.log(vError, appError)
+    log.error(vError, appError)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(vError, appError)
log.error(vError, appError)
🧰 Tools
🪛 ESLint

[error] 173-173: Unexpected console statement. Only these console methods are allowed: warn, error.

(no-console)

🪛 GitHub Actions: Run tests

[error] 173-173: ESLint: Unexpected console statement. Only these console methods are allowed: warn, error (no-console)

🪛 GitHub Actions: autofix.ci

[error] 173-173: ESLint: Unexpected console statement. Only these console methods are allowed: warn, error (no-console)

program.error('')
}
return data as any as Channel[]
return data.map((channel) => {
return {
...channel,
public: appData?.default_channel_ios === channel.id || appData?.default_channel_android === channel.id,
}
}) as any as Channel[]
}
13 changes: 12 additions & 1 deletion src/bundle/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,17 @@ async function setVersionInChannel(
.rpc('is_allowed_capgkey', { apikey, keymode: ['write', 'all'] })
.single()

const { data: appData, error: appError } = await supabase
.from('apps')
.select('default_channel_ios, default_channel_android')
.eq('app_id', appid)
.single()

if (appError) {
log.error(`Cannot get app data ${formatError(appError)}`)
program.error('')
}

if (apiAccess) {
const { error: dbError3, data } = await updateOrCreateChannel(supabase, {
name: channel,
Expand All @@ -481,7 +492,7 @@ async function setVersionInChannel(
}
const appidWeb = convertAppName(appid)
const bundleUrl = `${localConfig.hostWeb}/app/p/${appidWeb}/channel/${data.id}`
if (data?.public)
if (appData?.default_channel_ios === data.id || appData?.default_channel_android === data.id)
log.info('Your update is now available in your public channel 🎉')
else if (data?.id)
log.info(`Link device to this bundle to try it: ${bundleUrl}`)
Expand Down
105 changes: 101 additions & 4 deletions src/channel/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
OptionsBase,
} from '../utils'
import { exit } from 'node:process'
import { intro, log, outro } from '@clack/prompts'
import { intro, isCancel, log, outro, select } from '@clack/prompts'
import { program } from 'commander'
import { checkAppExistsAndHasPermissionOrgErr } from '../api/app'
import {
Expand Down Expand Up @@ -108,12 +108,13 @@ export async function setChannel(channel: string, appId: string, options: Option
log.info(`Set ${appId} channel: ${channel} to @${bundleVersion}`)
channelPayload.version = data.id
}
let publicChannel = null as boolean | null
if (state != null) {
if (state === 'public' || state === 'private')
log.info(`Set ${appId} channel: ${channel} to public or private is deprecated, use default or normal instead`)

log.info(`Set ${appId} channel: ${channel} to ${state === 'public' || state === 'default' ? 'default' : 'normal'}`)
channelPayload.public = state === 'public' || state === 'default'
publicChannel = state === 'public' || state === 'default'
}
if (downgrade != null) {
log.info(`Set ${appId} channel: ${channel} to ${downgrade ? 'allow' : 'disallow'} downgrade`)
Expand Down Expand Up @@ -149,11 +150,106 @@ export async function setChannel(channel: string, appId: string, options: Option
log.info(`Set ${appId} channel: ${channel} to ${finalDisableAutoUpdate} disable update strategy to this channel`)
}
try {
const { error: dbError } = await updateOrCreateChannel(supabase, channelPayload)
const { error: dbError, data: channelData } = await updateOrCreateChannel(supabase, channelPayload)
if (dbError) {
log.error(`Cannot set channel the upload key is not allowed to do that, use the "all" for this.`)
program.error('')
}
if (publicChannel != null) {
const { data: appData, error: appError } = await supabase
.from('apps')
.select('default_channel_android, default_channel_ios')
.eq('app_id', appId)
.single()
if (appError) {
log.error(`Cannot get app ${appId}`)
program.error('')
}
if (!publicChannel) {
if (appData?.default_channel_android !== channelData.id && appData?.default_channel_ios !== channelData.id) {
log.info(`Channel ${channel} is not public for both iOS and Android.`)
}
else {
if (appData?.default_channel_android === channelData.id) {
const { error: androidError } = await supabase
.from('apps')
.update({ default_channel_android: null })
.eq('app_id', appId)
if (androidError) {
log.error(`Cannot set default channel android to null`)
program.error('')
}
}
if (appData?.default_channel_ios === channelData.id) {
const { error: iosError } = await supabase
.from('apps')
.update({ default_channel_ios: null })
.eq('app_id', appId)
if (iosError) {
log.error(`Cannot set default channel ios to null`)
program.error('')
}
}
if ((appData?.default_channel_ios === null && appData?.default_channel_android === channelData.id) || (appData?.default_channel_ios === channelData.id && appData?.default_channel_android === null)) {
const { error: bothError } = await supabase
.from('apps')
.update({ default_channel_sync: true })
.eq('app_id', appId)
if (bothError) {
log.error(`Cannot set default channel sync to true`)
program.error('')
}
}
}
}
else if (appData?.default_channel_ios === channelData.id && appData?.default_channel_android === channelData.id) {
// check if pehaps the channel is already public
log.info(`Channel ${channel} is already public for both iOS and Android.`)
}
else {
// here we need to ask the user if he wants the channel to become public for iOS android or Both
const platformType = await select({
message: 'Do you want the channel to become public for iOS android or Both?',
options: [
{ value: 'iOS', label: 'iOS' },
{ value: 'Android', label: 'Android' },
{ value: 'Both', label: 'Both' },
],
})
if (isCancel(platformType)) {
outro(`Bye 👋`)
exit()
}

const platform = platformType as 'iOS' | 'Android' | 'Both'
if (platform === 'iOS' || platform === 'Android') {
const opositePlatform = platform === 'iOS' ? 'android' : 'ios'
const { error: singlePlatformError } = await supabase
.from('apps')
.update({ [`default_channel_${platform.toLowerCase()}`]: channelData.id, default_channel_sync: appData?.[`default_channel_${opositePlatform}`] === channelData.id })
.eq('app_id', appId)
if (singlePlatformError) {
log.error(`Failed to set default channel ${platform} to ${channel}.`)
log.error(`This may be due to insufficient permissions or a database error.${formatError(singlePlatformError)}`)
program.error('')
}
}
else {
const { error: bothPlatformError } = await supabase
.from('apps')
.update({ default_channel_sync: true, default_channel_ios: channelData.id, default_channel_android: channelData.id })
.eq('app_id', appId)
if (bothPlatformError) {
log.error(`Failed to synchronize default channel settings across both platforms.`)
log.error(`Unable to set channel '${channel}' as default for both iOS and Android.${formatError(bothPlatformError)}`)
program.error('')
}
}
}
if (publicChannel && (appData?.default_channel_ios !== channelData.id || appData?.default_channel_android !== channelData.id)) {
log.info(`Set ${appId} channel: ${channel} to ${publicChannel ? 'public' : 'private'}`)
}
}
}
catch {
log.error(`Cannot set channel the upload key is not allowed to do that, use the "all" for this.`)
Expand All @@ -171,7 +267,8 @@ export async function setChannel(channel: string, appId: string, options: Option
}).catch()
}
catch (err) {
log.error(`Unknow error ${formatError(err)}`)
log.error(`An unexpected error occurred while setting channel '${channel}' for app '${appId}'.`)
log.error(`Please verify your inputs and try again.${formatError(err)}`)
program.error('')
}
outro(`Done ✅`)
Expand Down
Loading
Loading