-
Notifications
You must be signed in to change notification settings - Fork 339
Adds spp model apply
command. Closes #6119
#6453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR and the additional info @mkm17! We'll get back to you ASAP. |
@mkm17 I added the |
c69155f
to
f366ea7
Compare
@mkm17, could you resolve the merge conflicts, please? |
f366ea7
to
d7d8e52
Compare
hi @milanholemans , I apologize for the delay, but I finally found some time to resolve the conflicts here. I have also reviewed the code and made the changes you pointed out in some other |
Hi @mkm17, sorry again, could you resolve the conflicts? Will try to review it ASAP when they are resolved. |
d7d8e52
to
4bd3c1e
Compare
Conflicts resolved :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, sorry for the late review. The last couple of weeks were a bit hectic for me. Anyway, I did a first review, and it looks already quite good. In the meantime, could you also rebase your branch with the latest main
? There are no merge conflicts, but main
contains some updated logic about how we call the telemetry collection function.
Great suggestion, feel free to add it to this PR as well. |
122ba9a
to
e0cb486
Compare
I have rebased a solution and I have switched options to zod setup. I hope that is correct |
Converting the PR to use a ZOD scheme is very much appreciated. Thanks @mkm17! |
There was a problem hiding this 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 command ("spp model apply") that applies a trained model to a SharePoint document library and updates related logic and tests. Key changes include:
- Introducing and using a shared getModel function in spp.ts for fetching models by title or unique id.
- Creating the new model-apply command with proper URL validation, error handling, and list information retrieval.
- Updating tests and command registration to support the new command functionality.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/utils/spp.ts | Added getModel function to retrieve models by title or id |
src/m365/spp/commands/model/model-apply.ts | Implemented the spp model apply command and integrated validation |
src/m365/spp/commands.ts | Registered the new MODEL_APPLY command |
src/utils/spp.spec.ts | Added tests for getModel behavior |
src/m365/spp/commands/model/model-get.ts | Refactored to leverage the shared getModel function |
src/m365/spp/commands/model/model-get.spec.ts | Updated tests to stub spp.getModel and handle error scenarios |
docs/src/config/sidebars.ts | Updated documentation sidebar to include the new model apply command |
Files not reviewed (1)
- docs/docs/cmd/spp/model/model-apply.mdx: Language not supported
Comments suppressed due to low confidence (1)
src/m365/spp/commands/model/model-apply.ts:16
- [nitpick] Consider renaming 'contentCenterUrl' to 'modelContentSiteUrl' for increased clarity on its purpose, although the current name is acceptable if aligned with team conventions.
contentCenterUrl: z.string()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mkm17, sorry for another late review on this PR. I've did another review, I feel we're almost there, let's do a couple more changes first.
), | ||
id: zod.alias('i', z.string() | ||
.refine(id => validation.isValidGuid(id) === true, id => ({ | ||
message: `${id} is not a valid GUID for option 'id'.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Zod scheme, we don't have to repeat the name of the failing option anymore. Zod wil print this automatically.
message: `${id} is not a valid GUID for option 'id'.` | ||
})) | ||
.optional()), | ||
title: zod.alias('t', z.string().optional()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: zod.alias('t', z.string().optional()), | |
title: zod.alias('t', z.string()).optional(), |
listId: z.string().refine(listId => validation.isValidGuid(listId) === true, listId => ({ | ||
message: `${listId} is not a valid GUID for option 'listId'.` | ||
})).optional(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it consistent with the other options. Let's:
- Start the refine on a new line
- We shouldn't repeat the option name in the error message anymore
} | ||
|
||
class SppModelApplyCommand extends SpoCommand { | ||
public readonly viewOptions: string[] = ['NewViewAsDefault', 'DoNotChangeDefault', 'TileViewAsDefault']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using this anywhere?
.refine(options => !(options.id && options.title), { | ||
message: `Specify either 'id' or 'title', but not both` | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this refinement, we can just leave id and title empty.
Let's use the refinement below for id and title so we are sure exactly 1 value is provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an additional test that ensures the command doesn't output anything as result?
src/utils/spp.ts
Outdated
* @returns SharePoint Premium model | ||
*/ | ||
|
||
async getModel(contentCenterUrl: string, title?: string, id?: string): Promise<SppModel> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'm more a fan of splitting this into two functions instead of having a 'useless' parameter.
getModelById
and getModelByTitle
would cover the load better.
src/utils/spp.spec.ts
Outdated
await spp.getModel('https://contoso.sharepoint.com/sites/portal', undefined, '9b1b1e42-794b-4c71-93ac-5ed92488b67f'); | ||
assert(stubGet.calledOnce); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, let's check for the output the function generates.
await spp.getModel('https://contoso.sharepoint.com/sites/portal', undefined, '9b1b1e42-794b-4c71-93ac-5ed92488b67f'); | |
assert(stubGet.calledOnce); | |
const actual = await spp.getModel('https://contoso.sharepoint.com/sites/portal', undefined, '9b1b1e42-794b-4c71-93ac-5ed92488b67f'); | |
assert.deepStrictEqual(actual, expected); |
src/utils/spp.spec.ts
Outdated
|
||
|
||
await assert.rejects(spp.getModel('https://contoso.sharepoint.com/sites/portal', undefined, '9b1b1e42-794b-4c71-93ac-5ed92488b67f'), | ||
'File Not Found.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'File Not Found.'); | |
new Error('File Not Found.')); |
if (this.verbose) { | ||
await logger.log(`Applying a model to a document library...`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a fan of adding more verbose logging to our commands. I suggest that we log something for about every request we do.
- Assert the content center is valid
- Getting model info
- Getting list info
- Applying model to list
e0cb486
to
ad06a1d
Compare
@milanholemans Hi, thank you again for the review. I’ve also made some updates to other commands to align them with the changes in the |
Adds
spp model apply
command. Closes #6119I realized I forgot to add a parameter needed to locate the content site where the model is stored:
contentCenterUrl
Let me know if name is ok. We can change it to modelContentSiteUrl or something else.
I also modified the
viewOption
parameter. During testing, I saw that it’s possible to set three different values:NewViewAsDefault
,DoNotChangeDefault
,TileViewAsDefault
The API does not return an error when attempting to apply a model to a custom SharePoint List. However, I’ve added a condition to check if the list is a document library. I hope that’s ok.
potentially, when the
spp model get
command is approved, thegetModel
function from this command should be exported to thespp.ts
file so it can be used by both commands.