-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(import): send import results to discord (#6662)
This PR adds the ability to send github import results (errors/warnings) to Discord (to the channel `#site-import-webhook`). **Details:** 1. Added a generic API endpoint for sending messages to Discord from our code. We use `discord-webhook-node` to format the message. The generic logic is here: [utopia-remix/app/util/discordWebhookUtils.ts](https://github.com/concrete-utopia/utopia/pull/6662/files#diff-77fb1f38c2e0b74476d2dac0b094d0c3f56cd598ca46f5ba2f348dd1afd8c4ae) 2. The code in the client that sends the results, here: [editor/src/core/shared/import/import-operation-service.ts](https://github.com/concrete-utopia/utopia/pull/6662/files#diff-426bff74c9da628f136029668cad91728508ef49a539c96a379c8c1e3f70e150R250-R265) 3. The code in the server that builds the textual site import message here: [utopia-remix/app/handlers/discordMessageBuilder.ts](https://github.com/concrete-utopia/utopia/pull/6662/files#diff-d2102489b75734896e5f1e06678c3f0ca926650eb08cdd14e00e79315f947302R22-R80) No other logic was changed, the rest of the code changes are mainly refactors / types. The code is generic and we can later [add](https://github.com/concrete-utopia/utopia/pull/6662/files#diff-77fb1f38c2e0b74476d2dac0b094d0c3f56cd598ca46f5ba2f348dd1afd8c4aeR20-R22) more Discord webhooks for other functionalities, easily. The webhook url for the specific channel is hidden in an env var - `DISCORD_WEBHOOK_SITE_IMPORT`, it is already set on our staging/production servers, and currently not on local machines. **Messages Example:** <img width="434" alt="image" src="https://github.com/user-attachments/assets/3b991dc1-f315-48b0-bccf-1d3df66591af"> **Manual Tests:** I hereby swear that: - [X] I opened a hydrogen project and it loaded - [X] I could navigate to various routes in Play mode
- Loading branch information
Showing
19 changed files
with
545 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
49 changes: 49 additions & 0 deletions
49
editor/src/components/editor/import-wizard/import-wizard-helpers.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react' | ||
import { | ||
ImportOperationResult, | ||
type ImportOperation, | ||
} from '../../../core/shared/import/import-operation-types' | ||
import { assertNever } from '../../../core/shared/utils' | ||
|
||
export function getImportOperationText(operation: ImportOperation): string { | ||
if (operation.text != null) { | ||
return operation.text | ||
} | ||
switch (operation.type) { | ||
case 'loadBranch': | ||
const action = | ||
operation.result == ImportOperationResult.Error || | ||
operation.result == ImportOperationResult.CriticalError | ||
? 'Error Fetching' | ||
: 'Fetching' | ||
if (operation.branchName != null) { | ||
return `${action} branch **${operation.githubRepo?.owner}/${operation.githubRepo?.repository}@${operation.branchName}**` | ||
} else { | ||
return `${action} repository **${operation.githubRepo?.owner}/${operation.githubRepo?.repository}**` | ||
} | ||
case 'fetchDependency': | ||
return `Fetching ${operation.dependencyName}@${operation.dependencyVersion}` | ||
case 'parseFiles': | ||
return 'Parsing files' | ||
case 'refreshDependencies': | ||
return 'Fetching dependencies' | ||
case 'checkRequirementsPreParse': | ||
return 'Validating code' | ||
case 'checkRequirementsPostParse': | ||
return 'Checking Utopia requirements' | ||
case 'checkRequirementAndFixPreParse': | ||
return operation.text | ||
case 'checkRequirementAndFixPostParse': | ||
return operation.text | ||
default: | ||
assertNever(operation) | ||
} | ||
} | ||
|
||
export function getImportOperationTextAsJsx(operation: ImportOperation): React.ReactNode { | ||
const text = getImportOperationText(operation) | ||
const nodes = text.split('**').map((part, index) => { | ||
return index % 2 == 0 ? part : <strong key={part}>{part}</strong> | ||
}) | ||
return <span>{nodes}</span> | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.