diff --git a/otterdog_database/doc/HOWTO.md b/otterdog_database/doc/HOWTO.md index 243fe1d84b4f7b1fbba95c8612d3150a1036f456..ed7bdc771d49eaaca112bfd3f1445a9a66bd933d 100644 --- a/otterdog_database/doc/HOWTO.md +++ b/otterdog_database/doc/HOWTO.md @@ -19,7 +19,7 @@ ## How to get a list of documents with default_branch (name) and default_branch_protection * 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 diff --git a/otterdog_database/doc/mongdb_queries/local/documents_list_with_default_branch_and_branch_protection.js b/otterdog_database/doc/mongdb_queries/local/documents_list_with_default_branch_and_branch_protection.js new file mode 100644 index 0000000000000000000000000000000000000000..09ef16ee1c118b7b5ebbe9d12fc60d1572dfd76c --- /dev/null +++ b/otterdog_database/doc/mongdb_queries/local/documents_list_with_default_branch_and_branch_protection.js @@ -0,0 +1,61 @@ +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