From 99654620c6dbcb07540468d9099ceba89974373a Mon Sep 17 00:00:00 2001 From: Francisco Perez <francisco.perez@eclipse-foundation.org> Date: Thu, 7 Sep 2023 18:19:37 +0200 Subject: [PATCH] adding a query to transform documents into documents with default branch and default branch protection --- otterdog_database/doc/MongoDB_queries.md | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/otterdog_database/doc/MongoDB_queries.md b/otterdog_database/doc/MongoDB_queries.md index 3575378..0c9425b 100644 --- a/otterdog_database/doc/MongoDB_queries.md +++ b/otterdog_database/doc/MongoDB_queries.md @@ -1,5 +1,72 @@ # MongoDB Queries +## A list of documents transformed into document with: github_id, default_branch and default_protection + +```javascript +db.getCollection("branch_security_rules").aggregate([{ + $project:{ + _id:0, + github_id: 1, + repositories: { + $map:{ + input: "$repositories", + as: "repo", + in: { + repo_name: "$$repo.name", + repo_default_branch: "$$repo.default_branch", + branch_protection_rules: "$$repo.branch_protection_rules", + } + } + }, + } +}, { + $unwind: "$repositories" +},{ + $project:{ + _id:0, + github_id: 1, + repo_name: "$repositories.repo_name", + repo_default_branch: "$repositories.repo_default_branch", + repo_branch_protection_rules: "$repositories.branch_protection_rules", + + } +}, { + $sort: { + total_repo_branch_protection_rules: -1 + } +}, { + $project: { + _id:0, + github_id: 1, + repo_name: 1, + repo_default_branch: 1, + repo_branch_protection_rules: { + $filter: { + input: "$repo_branch_protection_rules", + as: "bpr", + cond: { $eq: ["$$bpr.pattern", "$repo_default_branch"] } + } + } + } +},{ + $project: { + _id:0, + github_id: 1, + repo_name: 1, + repo_default_branch: 1, + repo_default_branch_protection: { + $cond: { + if: { $eq: [ "$repo_branch_protection_rules", []]}, + then: "not protected", + else: "protected" + } + } + } +} +]) + +``` + ## A list of documentos where repo_default_branch == repo.branch_protection_rules.pattern ```javascript @@ -65,4 +132,48 @@ db.branch_security_rules.aggregate([ } } ]) +``` + +## A list of documents with github_id, repo_name, repo_default_branch and branch_protection_rules_pattern +```javascript +db.branch_security_rules.aggregate([ + {$project: { + _id: 0, + github_id: 1, + repositories: { + $map: { + input: "$repositories", + as: "repo", + in:{ + default_branch: "$$repo.default_branch", + name: "$$repo.name", + branch_protection_rules: { + $map: { + input: "$$repo.branch_protection_rules", + as: "bpr", + in:{ + pattern: "$$bpr.pattern" + } + } + } + } + } + } + + } + },{ + $unwind: "$repositories" + },{ + $unwind: "$repositories.branch_protection_rules" + },{ + $project:{ + _id:1, + github_id: 1, + repo_name: "$repositories.name", + repo_default_branch: "$repositories.default_branch", + branch_protection_rules_pattern: "$repositories.branch_protection_rules.pattern" + } + }, +]) + ``` \ No newline at end of file -- GitLab