Skip to content
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

fix(docs/upload): add safeguard if projects have bidi enabled #1175

Open
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

emilyskuo
Copy link
Member

@emilyskuo emilyskuo commented Feb 25, 2025

🚥 Resolves RM-11901

🧰 Changes

Adding in a safe guard for ReadMe projects with bidirectional sync enabled, since the docs frontmatter format is different for bidi. By default, rdme docs upload may try to "fix" things and modify the markdown files, which could result in corrupted data and/or syncing errors.

Once https://github.com/readmeio/readme/pull/13869 is merged, we'll be exposing info on the project's bidi connection if it exists via the get project metadata (/projects/me) endpoint. This PR will introduce a check to see if a bidi connection exists, and throw an error if it does. If users want to continue uploading via rdme, they can use the --skip-validation flag to do so without potential issues from rdme's validation & fixing steps.

🧬 QA & Testing

Tested this against https://github.com/readmeio/readme/pull/13869 locally. Added some tests for docs upload as well.

@emilyskuo emilyskuo marked this pull request as ready for review February 28, 2025 22:20
@emilyskuo emilyskuo requested a review from kanadgupta February 28, 2025 22:20
@emilyskuo emilyskuo changed the title chore: add safeguard for docs upload if projects have bidi enabled fix(docs/upload): add safeguard if projects have bidi enabled Feb 28, 2025
Copy link
Member

@kanadgupta kanadgupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small outstanding things but this looks great on the whole!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮‍💨 do you think we could make it so we split out the openapi changes into their own PR? and this PR is branched off of that PR?

const biDiConnection = projectMetadata.data.git?.connection;
if (biDiConnection && !skipValidation) {
throw new Error(
"Bi-directional syncing is enabled for this project. Uploading these docs will overwrite what's currently synced from Git. To proceed with uploading via `rdme`, please use the `--skip-validation` flag.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Bi-directional syncing is enabled for this project. Uploading these docs will overwrite what's currently synced from Git. To proceed with uploading via `rdme`, please use the `--skip-validation` flag.",
"Bi-directional syncing is enabled for this project. Uploading these docs will overwrite what's currently synced from Git. To proceed with the upload, re-run this command with the `--skip-validation` flag.",

"Bi-directional syncing is enabled for this project. Uploading these docs will overwrite what's currently synced from Git. To proceed with uploading via `rdme`, please use the `--skip-validation` flag.",
);
}

if (skipValidation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on making it so this warning is only shown if bidi is not enabled? or maybe we have a separate warning for those users?

Suggested change
if (skipValidation) {
if (skipValidation && !bidiConnection) {

return this.handleAPIRes(res);
});

const biDiConnection = projectMetadata.data.git?.connection;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just to be extra cautious:

Suggested change
const biDiConnection = projectMetadata.data.git?.connection;
const biDiConnection = projectMetadata?.data?.git?.connection;

@@ -24,6 +24,9 @@ describe('rdme docs upload', () => {
categories: {},
parentPages: {},
});
getAPIv2Mock({ authorization }).get('/projects/me').reply(200, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are great, ty! could you also add a test case for if this initial /projects/me request fails? i'll DM you an example error response that you can pull from shortly

kanadgupta added a commit that referenced this pull request Mar 7, 2025
## 🧰 Changes

this PR updates our APIv2 openapi description as part of @emilyskuo's
work in #1175 and chunks out the OAS into its own dedicated file since
it's absolutely massive. you can check out the diff of the file changes
[here](next...1346b8b).

i tried messing around with JSON module imports so we can eventually
automate these updates more easily, but we lose out on a lot of good
strict typing that we currently have with `as const satisfies
OASDocument`. annoying!

## 🧬 QA & Testing

no functional changes. do tests still pass?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants