Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@dfinity/identity": "^2.3.0",
"@dfinity/principal": "^2.3.0",
"@junobuild/admin": "^0.5.0-next-2025-06-04.3",
"@junobuild/cdn": "^0.1.0-next-2025-06-10.2",
"@junobuild/cdn": "^0.1.0-next-2025-06-10.3",
"@junobuild/cli-tools": "^0.2.0-next-2025-06-04.3",
"@junobuild/config": "^0.1.8",
"@junobuild/config-loader": "^0.2.1",
Expand Down
1 change: 1 addition & 0 deletions src/help/changes.apply.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const usage = `Usage: ${green('juno')} ${cyan('changes')} ${magenta('apply')} ${

Options:
${yellow('-i, --id')} The ID of the change to apply.
${yellow('--snapshot')} Create a snapshot before applying.
${OPTION_HASH}
${OPTION_KEEP_STAGED}
${OPTION_HELP}`;
Expand Down
51 changes: 40 additions & 11 deletions src/services/changes/changes.apply.services.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,73 @@
import {hexStringToUint8Array} from '@dfinity/utils';
import {commitProposal} from '@junobuild/cdn';
import {
ApplyProposalProgressStep,
executeApplyProposal,
type ApplyProposalParams,
type ApplyProposalProgress
} from '@junobuild/cdn';
import {hasArgs} from '@junobuild/cli-tools';
import ora from 'ora';
import type {SatelliteParametersWithId} from '../../types/satellite';
import {readChangesIdAndHash} from '../../utils/changes.utils';
import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils';
import {clearProposalStagedAssets} from './changes.clear.services';

export const applyChanges = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext();

const {proposalId, hash} = readChangesIdAndHash(args);

await executeApplyChanges({satellite, proposalId, hash});
const keepAssets = hasArgs({args, options: ['-k', '--keep-staged']});
const takeSnapshot = hasArgs({args, options: ['--snapshot']});

await clearProposalStagedAssets({
args,
proposalId
await executeApplyChanges({
satellite,
proposalId,
hash,
clearProposalAssets: !keepAssets,
takeSnapshot
});
};

const executeApplyChanges = async ({
satellite,
proposalId,
hash
hash,
...rest
}: {
proposalId: bigint;
hash: string;
satellite: SatelliteParametersWithId;
}) => {
const spinner = ora('Applying...').start();
} & Pick<ApplyProposalParams, 'clearProposalAssets' | 'takeSnapshot'>) => {
const spinner = ora().start();

const onProgress = ({step}: ApplyProposalProgress) => {
switch (step) {
case ApplyProposalProgressStep.TakingSnapshot:
spinner.text = 'Creating a snapshot...';
break;
case ApplyProposalProgressStep.CommittingProposal:
spinner.text = 'Applying update...';
break;
case ApplyProposalProgressStep.ClearingProposalAssets:
spinner.text = 'Clearing staged assets...';
break;
case ApplyProposalProgressStep.PostApply:
spinner.text = 'Reloading...';
break;
}
};

try {
await commitProposal({
await executeApplyProposal({
cdn: {
satellite
},
proposal: {
proposal_id: proposalId,
sha256: hexStringToUint8Array(hash)
}
},
onProgress,
...rest
});

spinner.stop();
Expand Down
43 changes: 31 additions & 12 deletions src/services/changes/changes.reject.services.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
import {hexStringToUint8Array} from '@dfinity/utils';
import {rejectProposal} from '@junobuild/cdn';
import {
type RejectProposalParams,
type RejectProposalProgress,
RejectProposalProgressStep,
executeRejectProposal
} from '@junobuild/cdn';
import {hasArgs} from '@junobuild/cli-tools';
import ora from 'ora';
import type {SatelliteParametersWithId} from '../../types/satellite';
import {readChangesIdAndHash} from '../../utils/changes.utils';
import {assertConfigAndLoadSatelliteContext} from '../../utils/satellite.utils';
import {clearProposalStagedAssets} from './changes.clear.services';

export const rejectChanges = async (args?: string[]) => {
const {satellite} = await assertConfigAndLoadSatelliteContext();

const {proposalId, hash} = readChangesIdAndHash(args);

await executeRejectChanges({satellite, proposalId, hash});
const keepAssets = hasArgs({args, options: ['-k', '--keep-staged']});

await clearProposalStagedAssets({
args,
proposalId
});
await executeRejectChanges({satellite, proposalId, hash, clearProposalAssets: !keepAssets});
};

const executeRejectChanges = async ({
satellite,
proposalId,
hash
hash,
...rest
}: {
proposalId: bigint;
hash: string;
satellite: SatelliteParametersWithId;
}) => {
const spinner = ora('Rejecting...').start();
} & Pick<RejectProposalParams, 'clearProposalAssets'>) => {
const spinner = ora().start();

const onProgress = ({step}: RejectProposalProgress) => {
switch (step) {
case RejectProposalProgressStep.RejectingProposal:
spinner.text = 'Rejecting...';
break;
case RejectProposalProgressStep.ClearingProposalAssets:
spinner.text = 'Clearing staged assets...';
break;
case RejectProposalProgressStep.PostReject:
spinner.text = 'Reloading...';
break;
}
};

try {
await rejectProposal({
await executeRejectProposal({
cdn: {
satellite
},
proposal: {
proposal_id: proposalId,
sha256: hexStringToUint8Array(hash)
}
},
onProgress,
...rest
});

spinner.stop();
Expand Down