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 15 commits into
base: next
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: add safeguard for docs upload if projects have bidi enabled
  • Loading branch information
emilyskuo committed Feb 25, 2025
commit 2dfe886c79142d334fbd48fe1e63517f37ca490b
19 changes: 18 additions & 1 deletion src/lib/syncPagePath.ts
Original file line number Diff line number Diff line change
@@ -197,7 +197,7 @@ function sortFiles(files: PageMetadata<PageRepresentation>[]): PageMetadata<Page
*/
export default async function syncPagePath(this: CommandsThatSyncMarkdown) {
const { path: pathInput }: { path: string } = this.args;
const { 'dry-run': dryRun, 'skip-validation': skipValidation } = this.flags;
const { key, 'dry-run': dryRun, 'skip-validation': skipValidation } = this.flags;

const allowedFileExtensions = ['.markdown', '.md'];

@@ -208,6 +208,23 @@ export default async function syncPagePath(this: CommandsThatSyncMarkdown) {
throw err;
});

// get the project metadata via apiv2 https://api.readme.com/v2/projects/me
// look for project.git?.connection
// if it exists, AND the skipValidation flag is not on, throw an error
// if the it doesn't exist or the skipValidation flag is on, proceed

const headers = new Headers({ authorization: `Bearer ${key}` });
const projectMetadata = await this.readmeAPIFetch('/projects/me', { method: 'GET', headers }).then(res => {
return this.handleAPIRes(res);
});

const biDiConnection = projectMetadata.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.`,
);
}

if (skipValidation) {
this.warn('Skipping pre-upload validation of the Markdown file(s). This is not recommended.');
}
Loading