Skip to content
Snippets Groups Projects
Commit 601ebb9c authored by Francisco Perez's avatar Francisco Perez
Browse files

Merge branch 'adding_local_query_to_list_documents_with_branch_protection' into 'main'

Adding local query to list all documents with branch protection

See merge request !13
parents 574bc0d5 000f38ee
No related branches found
No related tags found
1 merge request!13Adding local query to list all documents with branch protection
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
## How to get a list of documents with default_branch (name) and default_branch_protection ## How to get a list of documents with default_branch (name) and default_branch_protection
* Local instance * Local instance
TBD [mongdb_queries/local/documents_list_with_default_branch_and_branch_protection.js](./mongdb_queries/local/documents_list_with_default_branch_and_branch_protection.js)
* Free MongoDB cloud instance * Free MongoDB cloud instance
......
db.getCollection("organizations").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"
}
}
}
}
])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment