-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Slack command to support disable all audits #1596
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
Open
tkotthakota-adobe
wants to merge
5
commits into
main
Choose a base branch
from
SITES-37053-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+198
−11
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb9df02
Slack command to support disable all audits
tkotthakota-adobe 8c1ea46
Merge branch 'main' of github.com:adobe/spacecat-api-service into SIT…
tkotthakota-adobe 89801ed
cleanup
tkotthakota-adobe 766cfe8
Merge branch 'main' of github.com:adobe/spacecat-api-service into SIT…
tkotthakota-adobe eb85af0
merge main
tkotthakota-adobe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,8 +100,9 @@ export default (context) => { | |
| CSV file must be in the format of baseURL per line(no headers). | ||
| Profiles are defined in the config/profiles.json file.`, | ||
| phrases: [PHRASE], | ||
| usageText: `${PHRASE} {enable/disable} {site} {auditType} for singleURL, | ||
| or ${PHRASE} {enable/disable} {profile/auditType} with CSV file uploaded.`, | ||
| usageText: `${PHRASE} {enable/disable} {site} {auditType} for single URL, | ||
| or ${PHRASE} {enable/disable} {profile/auditType} with CSV file uploaded. | ||
| Special: ${PHRASE} disable {site} all [profile] to disable all audits from a profile.`, | ||
| }); | ||
|
|
||
| const { log, dataAccess } = context; | ||
|
|
@@ -193,11 +194,11 @@ export default (context) => { | |
|
|
||
| // single URL behavior | ||
| if (isNonEmptyArray(files) === false) { | ||
| const [, baseURLInput, singleAuditType] = args; | ||
| const [, baseURLInput, auditType, profileName] = args; | ||
|
|
||
| const baseURL = extractURLFromSlackInput(baseURLInput); | ||
|
|
||
| validateInput(enableAudit, singleAuditType); | ||
| validateInput(enableAudit, auditType); | ||
|
|
||
| if (isValidUrl(baseURL) === false) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}Please provide either a CSV file or a single baseURL.`); | ||
|
|
@@ -212,13 +213,48 @@ export default (context) => { | |
| } | ||
|
|
||
| const registeredAudits = configuration.getHandlers(); | ||
| if (!registeredAudits[singleAuditType]) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}The "${singleAuditType}" is not present in the configuration.\nList of allowed audits:\n${Object.keys(registeredAudits).join('\n')}.`); | ||
|
|
||
| // Handle "all" keyword to disable all audits from a profile | ||
| if (auditType === 'all') { | ||
| if (isEnableAudit) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}Enable all is not supported. Please enable audits individually or use a profile with CSV upload.`); | ||
| return; | ||
| } | ||
|
|
||
| const targetProfile = profileName || 'demo'; | ||
|
|
||
| let profile; | ||
| try { | ||
| profile = loadProfileConfig(targetProfile); | ||
| } catch (error) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}Profile "${targetProfile}" not found.`); | ||
| return; | ||
| } | ||
| const profileAuditTypes = Object.keys(profile.audits || {}); | ||
| if (profileAuditTypes.length === 0) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}No audits found in profile "${targetProfile}".`); | ||
| return; | ||
| } | ||
|
|
||
| await say(`:hourglass_flowing_sand: Disabling ${profileAuditTypes.length} audits from profile "${targetProfile}" for ${site.getBaseURL()}...`); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we mention as |
||
|
|
||
| profileAuditTypes.forEach((type) => { | ||
| configuration.disableHandlerForSite(type, site); | ||
| }); | ||
|
|
||
| await configuration.save(); | ||
| await say(`${SUCCESS_MESSAGE_PREFIX}Successfully disabled ${profileAuditTypes.length} audits from profile "${targetProfile}" for "${site.getBaseURL()}".\n\`\`\`${profileAuditTypes.join('\n')}\`\`\``); | ||
| return; | ||
| } | ||
|
|
||
| // Handle single audit type | ||
| if (!registeredAudits[auditType]) { | ||
| await say(`${ERROR_MESSAGE_PREFIX}The "${auditType}" is not present in the configuration.\nList of allowed audits:\n${Object.keys(registeredAudits).join('\n')}.`); | ||
| return; | ||
| } | ||
|
|
||
| if (isEnableAudit) { | ||
| if (singleAuditType === 'preflight') { | ||
| if (auditType === 'preflight') { | ||
| const authoringType = site.getAuthoringType(); | ||
| const deliveryConfig = site.getDeliveryConfig(); | ||
| const helixConfig = site.getHlxConfig(); | ||
|
|
@@ -247,18 +283,18 @@ export default (context) => { | |
|
|
||
| if (configMissing) { | ||
| // Prompt user to configure missing requirements | ||
| await promptPreflightConfig(slackContext, site, singleAuditType); | ||
| await promptPreflightConfig(slackContext, site, auditType); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| configuration.enableHandlerForSite(singleAuditType, site); | ||
| configuration.enableHandlerForSite(auditType, site); | ||
| } else { | ||
| configuration.disableHandlerForSite(singleAuditType, site); | ||
| configuration.disableHandlerForSite(auditType, site); | ||
| } | ||
|
|
||
| await configuration.save(); | ||
| await say(`${SUCCESS_MESSAGE_PREFIX}The audit "${singleAuditType}" has been *${enableAudit}d* for "${site.getBaseURL()}".`); | ||
| await say(`${SUCCESS_MESSAGE_PREFIX}The audit "${auditType}" has been *${enableAudit}d* for "${site.getBaseURL()}".`); | ||
| } catch (error) { | ||
| log.error(error); | ||
| await say(`${ERROR_MESSAGE_PREFIX}An error occurred while trying to enable or disable audits: ${error.message}`); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why
Special? we can simply add this asand