Skip to content

New command: spo file archive. Closes #7175#7192

Draft
Saurabh7019 wants to merge 3 commits intopnp:mainfrom
Saurabh7019:issue-7175
Draft

New command: spo file archive. Closes #7175#7192
Saurabh7019 wants to merge 3 commits intopnp:mainfrom
Saurabh7019:issue-7175

Conversation

@Saurabh7019
Copy link
Copy Markdown
Contributor

Closes #7175

@Saurabh7019 Saurabh7019 marked this pull request as ready for review April 5, 2026 19:10
@milanholemans
Copy link
Copy Markdown
Contributor

Awesome work @Saurabh7019! We'll try to check it ASAP.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new SharePoint Online command (m365 spo file archive) to archive a file (by server-relative URL or UniqueId), including documentation, command constant wiring, Dev Proxy API spec updates, and a full unit test suite.

Changes:

  • Added spo file archive command implementation with Zod-based option parsing and confirmation prompt support.
  • Added Mocha tests covering validation, confirmation flow, success paths (by URL / by ID), and error handling.
  • Updated docs navigation + new command reference page, and extended the Dev Proxy SharePoint API spec.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/m365/spo/commands/file/file-archive.ts Implements the new spo file archive command and SharePoint REST interactions to resolve list/item and call Archive.
src/m365/spo/commands/file/file-archive.spec.ts Adds unit tests for option validation, prompting behavior, success cases, and error handling.
src/m365/spo/commands.ts Registers the command name constant FILE_ARCHIVE.
docs/src/config/sidebars.ts Adds the command doc to the SPO “file” commands sidebar.
docs/docs/cmd/spo/file/file-archive.mdx Adds end-user documentation for the new command, including examples and sample output.
.devproxy/api-specs/sharepoint.yaml Adds Dev Proxy spec entries for Archive and GetFileByServerRelativePath.

Comment thread src/m365/spo/commands/file/file-archive.ts Outdated
Comment thread .devproxy/api-specs/sharepoint.yaml Outdated
Copy link
Copy Markdown
Contributor

@milanholemans milanholemans left a comment

Choose a reason for hiding this comment

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

Nice command! I did a first review based on sight and found some things we should take a look at.

Comment thread docs/docs/cmd/spo/file/file-archive.mdx Outdated
Comment thread src/m365/spo/commands/file/file-archive.ts Outdated
Comment thread src/m365/spo/commands/file/file-archive.ts Outdated
Comment thread src/m365/spo/commands/file/file-archive.ts Outdated
@milanholemans milanholemans marked this pull request as draft April 8, 2026 22:39
@Saurabh7019 Saurabh7019 marked this pull request as ready for review April 9, 2026 19:28
Copy link
Copy Markdown
Contributor

@milanholemans milanholemans left a comment

Choose a reason for hiding this comment

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

Command looks almost good to go! I think we need to adjust a few minor things to get this merged.
If you are able to process the feedback by next weekend, I'm sure we can get the command in the April release.


## Examples

Archive a file without prompting for confirmation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Archive a file without prompting for confirmation
Archive a file by id without prompting for confirmation

const { webUrl, url, id, force, verbose } = args.options;

if (!force) {
const result = await cli.promptForConfirmation({ message: `Are you sure you want to archive the file ${url || id} at site ${webUrl}?` });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's reuse some warnings from the GUI about the 7 days period and 24h reactivation time. I wouldn't mention the site URL here because the warning will get too long.

responseType: 'json'
});

const archiveUrl = `${webUrl}/_api/Lists(guid'${fileInfo.ListId}')/items(${fileInfo.ListItemAllFields.Id})/Archive`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's assign the URL directly to the request body.

});

it('prompts before archiving file when confirmation argument not passed', async () => {
await command.action(logger, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add some simple stubs to this test. In case we accidentally remove the prompt mechanism, this test will currently timeout because API requests are not stubbed.

});

it('aborts archiving file when prompt not confirmed', async () => {
const postStub = sinon.stub(request, 'post').resolves();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also stub the get request?

}
else if (url) {
const serverRelativePath = urlUtil.getServerRelativePath(webUrl, url);
requestUrl += `/GetFileByServerRelativePath(DecodedUrl='${serverRelativePath}')`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's encode this query parameter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests so far are looking quite good. However, I would love to see two additional tests:

  • Test to ensure that the logger is not used (ensure the command outputs no result)
  • Test that archives a file using a site-relative URL, e.g.: /MarketingDocs/Icons/ContosoIcon.svg)

@milanholemans milanholemans marked this pull request as draft April 17, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command: spo file archive

3 participants