sourcegraph/client/web
Michael Bahr 3ff0ddf1cb
fix(batches): switch github app installation handling from redirect flow to webhooks (#64036)
Closes SRCH-741
Closes SRCH-716

This PR removes the GitHub installation code from the redirect flow to a
webhook-based appraoch. We expect that the GitHub server calls the
webhook when the installation is ready, and therefore shouldn't see the
errors explained in the issues above.

To handle the potential delay until the webhook is called and the
credential is set up, I added a scrappy info notice that the user should
refresh their page:

<img width="928" alt="Screenshot 2024-07-24 at 13 48 24"
src="https://github.com/user-attachments/assets/4d298f2a-d7b8-423b-9e2f-2ae53fbce1ac">

Below is what you see after you refreshed (or if the webhook was called
faster than the user being redirected back to the settings):

<img width="929" alt="Screenshot 2024-07-24 at 13 50 14"
src="https://github.com/user-attachments/assets/b6826158-8561-476d-b20e-e36f8cfb86fd">

I'm able to create PRs for sourcegraph-testing with an app that was
created this way.

<img width="1171" alt="Screenshot 2024-07-24 at 16 16 06"
src="https://github.com/user-attachments/assets/86e20acb-136f-4a46-a33b-bdfdd0d51d71">

I'm seeing an error when getting an access token with a personal github
app to run a batch change, but that will be handled with another PR.

<img width="1053" alt="Screenshot 2024-07-24 at 16 38 38"
src="https://github.com/user-attachments/assets/5655ba91-1ae4-453a-8d5c-1bcdbe34bc17">

## Test plan

Manual testing locally, and more testing to be done on S2 where we have
a more production like environment

## Changelog

- When installing a GitHub app for batch changes, the instance now waits
for a callback from GitHub to complete the installation to avoid issues
from eventual consistency.

---------

Co-authored-by: Peter Guy <peter.guy@sourcegraph.com>
2024-07-26 11:53:34 +00:00
..
__mocks__ reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
bookmarklet
dev chore(local): hotfix when local client assets become too big (#63807) 2024-07-18 14:20:39 +02:00
dist fix(client): restore paths for extension bundles (#63402) 2024-06-21 16:12:34 +02:00
src fix(batches): switch github app installation handling from redirect flow to webhooks (#64036) 2024-07-26 11:53:34 +00:00
tests-examples feat(ci): Adds playwright tests for sveltekit to bazel (#62560) 2024-06-06 12:45:05 -06:00
.bazelignore bazel: ignore files generated into src (#45922) 2022-12-21 20:43:29 -08:00
.eslintignore
.stylelintrc.json
BUILD.bazel remove "organizations aren't supported" page on dotcom (#63932) 2024-07-19 01:20:56 -07:00
bundlesize.config.js Bump code-web-experimental version to 0.2.0 (#63675) 2024-07-05 18:57:38 -03:00
package.json chore(local): hotfix when local client assets become too big (#63807) 2024-07-18 14:20:39 +02:00
README.md fix: update links for dev docs (#62758) 2024-05-17 13:47:34 +02:00
statoscope Report bundle size diff in PRs (#42277) 2022-10-12 10:19:51 +02:00
tsconfig.json Create a shared Cody Ignore dataset (#61968) 2024-05-09 13:18:35 +00:00
vitest.config.ts bazel: fix vitest_test in Bazel in sandbox mode (#58274) 2023-11-15 10:14:41 +01:00

Web Application

Local development

Use sg CLI tool to configure and start local development server. For more information check out the sg documentation.

Our local development server runs by starting both a Caddy HTTPS server and a Node HTTP server. We then can reverse proxy requests to the Node server to serve client assets under HTTPS.

Configuration

Environment variables important for the web server:

  1. WEB_BUILDER_SERVE_INDEX should be set to true to enable serving of an index page.
  2. SOURCEGRAPH_API_URL is used as a proxied API url. By default it points to the https://k8s.sgdev.org.

It's possible to overwrite these variables by creating sg.config.overwrite.yaml in the root folder and adjusting the env section of the relevant command.

Development server

sg start web-standalone

Public API

To use a public API that doesn't require authentication for most of the functionality:

SOURCEGRAPH_API_URL=https://sourcegraph.com sg start web-standalone

Production server

sg start web-standalone-prod

Web app should be available at https://${SOURCEGRAPH_HTTPS_DOMAIN}:${SOURCEGRAPH_HTTPS_PORT}. Build artifacts will be served from <rootRepoPath>/client/web/dist.

Note: If you are unable to use the above commands (e.g. you can't install Caddy), you can use sg run web-standalone-http instead. This will start a development server using only Node, and will be available at http://localhost:${SOURCEGRAPH_HTTP_PORT}.

API proxy

In both environments, server proxies API requests to SOURCEGRAPH_API_URL provided as the .env variable.