-
Notifications
You must be signed in to change notification settings - Fork 1
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
DOP-5197 #55
Merged
DOP-5197 #55
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f824ff5
update repos branches entry when done uploading to S3
seungpark 2502ebc
include id in repo entry
seungpark 40c792c
set offline for copy snooty only
seungpark 800b655
remove logs
seungpark b0ead90
add logs
seungpark 25271cd
convert branch._id to branch.id
seungpark 963e973
use bsonid
seungpark 4777804
skip extensions for non dotcomprd or dotcomstg
seungpark a16aaea
testing on prd
seungpark 9118e1b
Revert "testing on prd"
seungpark a57a145
Revert "Revert "testing on prd""
seungpark 953fc06
catch errors while converting
seungpark 064e992
debug printing
seungpark b69ddf6
format fix
seungpark d6652e0
revert last few commits
seungpark 93083df
comment unused var
seungpark bf291ff
Revert "comment unused var"
seungpark 60b570f
Revert "revert last few commits"
seungpark 40c7d63
Revert "format fix"
seungpark b72fed8
Revert "debug printing"
seungpark d61abde
Revert "catch errors while converting"
seungpark 99079bb
Revert "Revert "Revert "testing on prd"""
seungpark f7e9c51
Revert "Revert "testing on prd""
seungpark 51b2a3f
Revert "testing on prd"
seungpark f3749dd
Revert "skip extensions for non dotcomprd or dotcomstg"
seungpark bc76f21
add debugging logs
seungpark ac55e82
add more logs
seungpark 5b50964
check env file
seungpark 87a2023
use node fs instead of echo
seungpark 693467c
fix filepath
seungpark 1d089f2
fix filepath
seungpark d359dbd
try to catch logs
seungpark 59e27a2
fix env var
seungpark d4924da
remove testing logs
seungpark d1d7d69
remove gatsby related directories manually
seungpark 05d4592
remove testing code
seungpark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
52 changes: 52 additions & 0 deletions
52
extensions/offline-snooty/src/updateReposBranches/index.ts
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,52 @@ | ||
import { ObjectId, type UpdateResult } from 'mongodb'; | ||
import { join } from 'node:path'; | ||
import type { | ||
BranchEntry, | ||
ReposBranchesDocument, | ||
} from 'util/databaseConnection/types'; | ||
import { | ||
getClusterZeroDb, | ||
type clusterZeroParams, | ||
} from 'util/databaseConnection/clusterZeroConnector'; | ||
import type { CollectionName } from 'util/assertDbEnvVars'; | ||
|
||
type updateParams = { | ||
branchEntry: BranchEntry; | ||
repoEntry: ReposBranchesDocument; | ||
collectionName?: CollectionName; | ||
}; | ||
|
||
function getUrl(baseUrl: string, fileName: string) { | ||
return join(baseUrl, 'docs', 'offline', fileName); | ||
} | ||
|
||
export const updateReposBranches = async ( | ||
{ repoEntry, branchEntry, collectionName }: updateParams, | ||
connectionParams: clusterZeroParams, | ||
baseUrl: string, | ||
fileName: string, | ||
): Promise<UpdateResult<ReposBranchesDocument>> => { | ||
const dbSession = await getClusterZeroDb(connectionParams); | ||
const reposBranchesCollection = dbSession.collection<ReposBranchesDocument>( | ||
collectionName ?? 'repos_branches', | ||
); | ||
|
||
const updateFilter = { | ||
_id: new ObjectId(repoEntry._id), | ||
'branches.id': new ObjectId(branchEntry.id), | ||
}; | ||
|
||
const updateParams = { | ||
$set: { 'branches.$.offlineUrl': getUrl(baseUrl, fileName) }, | ||
}; | ||
|
||
console.log( | ||
`Updating repos branches collection for collection ${collectionName} in db ${connectionParams.databaseName} for repo id ${repoEntry._id} for branch ${branchEntry.id} ${branchEntry.gitBranchName}`, | ||
); | ||
|
||
const updateRes = await reposBranchesCollection.updateOne( | ||
updateFilter, | ||
updateParams, | ||
); | ||
return updateRes; | ||
}; |
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 |
---|---|---|
@@ -1,52 +1,37 @@ | ||
// TODO: consolidate with populate-metadata extension | ||
type EnvironmentConfig = { | ||
dev?: string; | ||
stg: string; | ||
dotcomstg: string; | ||
prd: string; | ||
dotcomprd: string; | ||
}; | ||
export interface DocsetsDocument { | ||
bucket: EnvironmentConfig; | ||
project: string; | ||
url: EnvironmentConfig; | ||
prefix: EnvironmentConfig; | ||
} | ||
import type { | ||
ReposBranchesDocument, | ||
BranchEntry, | ||
EnvironmentConfig, | ||
DocsetsDocument, | ||
} from 'util/databaseConnection/types'; | ||
|
||
export interface BranchEntry { | ||
name?: string; | ||
gitBranchName: string; | ||
urlSlug: string; | ||
isStableBranch: boolean; | ||
active: boolean; | ||
} | ||
|
||
export interface ReposBranchesDocument { | ||
repoName: string; | ||
project: string; | ||
search?: { | ||
categoryTitle: string; | ||
categoryName?: string; | ||
}; | ||
branches?: Array<BranchEntry>; | ||
prodDeployable: boolean; | ||
internalOnly: boolean; | ||
/** | ||
* Returns buckets that are preconfigured to public URL | ||
* Some projects are stored in different buckets, | ||
* but offline versions are stored in general usage bucket | ||
* to route to same URL | ||
*/ | ||
function getBucketName(env: keyof EnvironmentConfig) { | ||
return `docs-mongodb-org-${env}`; | ||
} | ||
|
||
export function readEnvConfigs({ | ||
env, | ||
docsetEntry, | ||
repoEntry, | ||
branchEntry, | ||
docsetEntry, | ||
}: { | ||
env: string; | ||
docsetEntry: DocsetsDocument; | ||
env: keyof EnvironmentConfig; | ||
repoEntry: ReposBranchesDocument; | ||
branchEntry: BranchEntry; | ||
docsetEntry: DocsetsDocument; | ||
}) { | ||
const docset: DocsetsDocument = docsetEntry; | ||
const bucketName = docset.bucket[env as keyof EnvironmentConfig] ?? ''; | ||
const bucketName = getBucketName(env); | ||
const project: string = repoEntry?.project ?? ''; | ||
const version = branchEntry?.gitBranchName ?? ''; | ||
return { bucketName, fileName: `${project}-${version}.tar.gz` }; | ||
return { | ||
bucketName, | ||
fileName: `${project}-${version}.tar.gz`, | ||
baseUrl: docsetEntry?.url[env] ?? '', | ||
}; | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
TODO: minor note to uncomment this after approval. wanted to leave this for logs