-
Notifications
You must be signed in to change notification settings - Fork 362
Adds spo site alert get
command. Closes #6862
#6998
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
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 spo site alert get
to retrieve details of a specific alert from a SharePoint site list, addressing issue #6862.
Key changes:
- Implements a new command to get SharePoint site alert details by ID
- Adds comprehensive test coverage with validation scenarios
- Includes complete documentation with examples and response formats
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/site/site-alert-get.ts | Main command implementation with API call to SharePoint alerts endpoint |
src/m365/spo/commands/site/site-alert-get.spec.ts | Comprehensive test suite covering success, error, and validation scenarios |
src/m365/spo/commands.ts | Adds command constant for registration |
docs/src/config/sidebars.ts | Updates documentation navigation |
docs/docs/cmd/spo/site/site-alert-get.mdx | Complete command documentation with examples |
.devproxy/api-specs/sharepoint.yaml | API specification for the SharePoint alerts endpoint |
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.
Solid work, let's change a few things before we merge it.
webUrl: zod.alias('u', z.string().refine(url => validation.isValidSharePointUrl(url) === true, { | ||
message: 'Specify a valid SharePoint site URL' | ||
})), | ||
id: z.string().refine(id => validation.isValidGuid(id) === true, { | ||
message: 'Specify a valid GUID' | ||
}) |
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.
For options validation, let's make sure that:
- Error messages end on a period
.
. - Print the passed value in the error message (like ' is not a valid GUID.'). This makes it easier for folks to debug their scripts.
|
||
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> { | ||
const requestOptions: CliRequestOptions = { | ||
url: `${args.options.webUrl}/_api/Web/Alerts/GetById('${args.options.id}')?$expand=List,User,List/Rootfolder&$select=*,List/Id,List/Title,List/Rootfolder/ServerRelativeUrl`, |
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.
We forgot to expand the Item
property. Let's do that as well.
Check the API URL of the list
command.
}; | ||
|
||
try { | ||
const res = await request.get(requestOptions); |
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.
In the list
command, we remove a duplicate ID
property at the Item
object, let's do this as well here since PowerShell has a hard time parsing it.
}); | ||
|
||
it('has correct name', () => { | ||
assert.strictEqual(command.name.startsWith(commands.SITE_ALERT_GET), true); |
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 use an exact equal.
sinon.stub(request, 'get').callsFake(async (opts) => { | ||
if (opts.url === `${webUrl}/_api/Web/Alerts/GetById('${alertId}')?$expand=List,User,List/Rootfolder&$select=*,List/Id,List/Title,List/Rootfolder/ServerRelativeUrl`) { | ||
throw error; | ||
} | ||
|
||
throw 'Invalid request'; | ||
}); |
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.
In this case, we don't really care if the API URL is correct. We want to keep the test as simple as possible, only to validate if the command correctly shows a decent error message.
So in this case we can just use .rejects(error)
.
it('passes validation if the id option is a valid GUID', async () => { | ||
const actual = commandOptionsSchema.safeParse({ | ||
webUrl: webUrl, | ||
id: alertId | ||
}); | ||
assert.strictEqual(actual.success, true); | ||
}); |
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.
This test is the same as the one 2 tests above, isn't it?
`-u, --webUrl <webUrl>` | ||
: The URL of the SharePoint site | ||
|
||
`--id <id>` | ||
: The ID of the alert |
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.
`-u, --webUrl <webUrl>` | |
: The URL of the SharePoint site | |
`--id <id>` | |
: The ID of the alert | |
`-u, --webUrl <webUrl>` | |
: The URL of the SharePoint site. | |
`--id <id>` | |
: The ID of the alert. |
"Properties": [ | ||
{ | ||
"Key": "dispformurl", | ||
"Value": "Documents/Forms/DispForm.aspx", | ||
"ValueType": "Edm.String" | ||
}, | ||
{ | ||
"Key": "filterindex", | ||
"Value": "0", | ||
"ValueType": "Edm.String" | ||
}, | ||
{ | ||
"Key": "defaultitemopen", | ||
"Value": "Browser", | ||
"ValueType": "Edm.String" | ||
}, | ||
{ | ||
"Key": "sendurlinsms", | ||
"Value": "False", | ||
"ValueType": "Edm.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.
For a list, we require to only show 1 item of the list to reduce cluttering the docs. Let's update this for other response types as well.
|
||
</TabItem> | ||
</Tabs> | ||
|
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 remove one empty line at the end of the file.
Closes #6862