-
Notifications
You must be signed in to change notification settings - Fork 44
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
base: next
Are you sure you want to change the base?
Changes from all commits
2dfe886
04730e1
6ef3b16
105c715
52f5776
ce065c2
8d4ea7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||
import type { PageMetadata } from './readPage.js'; | ||||||
import type { GuidesRequestRepresentation } from './types.js'; | ||||||
import type { GuidesRequestRepresentation, ProjectRepresentation } from './types.js'; | ||||||
import type DocsUploadCommand from '../commands/docs/upload.js'; | ||||||
|
||||||
import fs from 'node:fs/promises'; | ||||||
|
@@ -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; | ||||||
}); | ||||||
|
||||||
// check whether or not the project has bidirection syncing enabled | ||||||
// if it is, validations must be skipped to prevent frontmatter from being overwritten | ||||||
const headers = new Headers({ authorization: `Bearer ${key}` }); | ||||||
const projectMetadata: ProjectRepresentation = await this.readmeAPIFetch('/projects/me', { | ||||||
method: 'GET', | ||||||
headers, | ||||||
}).then(res => { | ||||||
return this.handleAPIRes(res); | ||||||
}); | ||||||
|
||||||
const biDiConnection = projectMetadata.data.git?.connection; | ||||||
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. maybe just to be extra cautious:
Suggested change
|
||||||
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.", | ||||||
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.
Suggested change
|
||||||
); | ||||||
} | ||||||
|
||||||
if (skipValidation) { | ||||||
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. 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
|
||||||
this.warn('Skipping pre-upload validation of the Markdown file(s). This is not recommended.'); | ||||||
} | ||||||
|
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.
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