Skip to content
Closed
Changes from all commits
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
61 changes: 58 additions & 3 deletions src/services/changes/changes.apply.services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {hexStringToUint8Array} from '@dfinity/utils';
import {commitProposal} from '@junobuild/cdn';
import {fromNullable, hexStringToUint8Array, isNullish} from '@dfinity/utils';
import {commitProposal, getProposal, Proposal} from '@junobuild/cdn';

Check failure on line 2 in src/services/changes/changes.apply.services.ts

View workflow job for this annotation

GitHub Actions / lint

Imports "Proposal" are only used as type
import {red} from 'kleur';
import ora from 'ora';
import type {SatelliteParametersWithId} from '../../types/satellite';
import {readChangesIdAndHash} from '../../utils/changes.utils';
Expand All @@ -9,14 +10,68 @@
export const applyChanges = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext(args);

const {proposalId, hash} = readChangesIdAndHash(args);
const result = await init({args, satellite});

if (result.result === "error") {
return;
}

const {proposalId, proposal, hash} = result;

await executeApplyChanges({satellite, proposalId, hash});

await clearProposalStagedAssets({
args,
proposalId
});

switch (Object.keys(proposal.proposal_type)[0]) {
case 'SegmentsDeployment':
// TODO
default:

Check failure on line 31 in src/services/changes/changes.apply.services.ts

View workflow job for this annotation

GitHub Actions / lint

Expected a 'break' statement before 'default'
return;

Check failure on line 32 in src/services/changes/changes.apply.services.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary return statement
}
};

const init = async ({
args,
satellite
}: {
args?: string[];
satellite: SatelliteParametersWithId;
}): Promise<
{result: 'success'; proposalId: bigint; hash: string; proposal: Proposal} | {result: 'error'}
> => {
const spinner = ora('Loading...').start();

try {
const {proposalId, ...rest} = readChangesIdAndHash(args);

const result = await getProposal({
cdn: {
satellite
},
proposal_id: proposalId
});

const proposal = fromNullable(result);

if (isNullish(proposal)) {
console.log(red(`Unknown proposal ID ${proposalId}.`));
return {result: 'error'};
}

return {
result: 'success',
...rest,
proposal,
proposalId
};
} catch (err: unknown) {
spinner.stop();

throw err;
}
};

const executeApplyChanges = async ({
Expand Down
Loading