From 57781c7fb08405b71629823b9881b5c7a79da935 Mon Sep 17 00:00:00 2001 From: Jim Clark Date: Thu, 10 Sep 2020 20:40:56 -0700 Subject: [PATCH] Add scan command * make sure it iterates over each configuration --- index.js | 36 ++++++++++++------------------------ package-lock.json | 12 ++++++------ package.json | 2 +- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/index.js b/index.js index 9777782..ed9ee54 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ var api = require("@atomist/api-cljs/atomist.middleware"); -var configureReviews = function(request) { +var configureReviews = (request) => { if (request.required_approving_review_count || request.require_code_owner_reviews || request.dismiss_stale_reviews) { return { ... (request.required_approving_review_count && {required_approving_review_count: request.required_approving_review_count}), @@ -12,7 +12,7 @@ var configureReviews = function(request) { } }; -var convergeBranchRules = async function (request, branch, repo) { +var convergeBranchRules = async (request, repo, branch) => { if ( request.topic && repo.topics && @@ -35,29 +35,13 @@ var convergeBranchRules = async function (request, branch, repo) { return true; }; -var scan = async (request) => { - // await request.withRepoIterator(async (repo) => { - // return await repo.withBranches(async (branches) => { - // return await Promise.all(branches.map(async branch => { - // console.info(`check ${branch} on ${repo.owner}/${repo.repo}`); - // return await convergeBranchRules( - // request, - // branch, - // repo - // ); - // })); - // }); - // }); - console.info(JSON.stringify(request)); -}; - exports.handler = api.handler({ OnAnyPush: async (request) => { await request.withRepo(async (repo) => { return await convergeBranchRules( request, - request.data.Push[0].branch, - repo + repo, + request.data.Push[0].branch ); }); }, @@ -65,11 +49,15 @@ exports.handler = api.handler({ await request.withRepo(async (repo) => { return await convergeBranchRules( request, - request.data.PullRequest[0].baseBranchName, - repo + repo, + request.data.PullRequest[0].baseBranchName ); }); }, - sync: scan, - OnSchedule: scan + sync: api.scanBranches(async (request, repo, branch) => { + return await api.eachConfig(request, async (req) => { + return await convergeBranchRules(req, repo, branch); + }); + }), + OnSchedule: api.scanBranches(convergeBranchRules) }); diff --git a/package-lock.json b/package-lock.json index d2ca1bd..25d8934 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@atomist/api-cljs": { - "version": "0.4.101", - "resolved": "https://registry.npmjs.org/@atomist/api-cljs/-/api-cljs-0.4.101.tgz", - "integrity": "sha512-uHkEp6eSlD3gkuivZgWqYi+JXeETJGpZWCeP51pdpkuLVZs3USlzN6zYgiNDdPKZYvCg1juI/Ve/lTybuST0oQ==", + "version": "0.4.102", + "resolved": "https://registry.npmjs.org/@atomist/api-cljs/-/api-cljs-0.4.102.tgz", + "integrity": "sha512-nW2QwrkujbYI4wt/Bh+sCHN3wDc5ysnAfd3cEtEvOIiwcgjAsOmGFkXOOpg9iuIyUptWYyKHCLw0vgt1/wIM6A==", "requires": { "@atomist/skill-logging": "0.1.0-master.20200316180914", "@google-cloud/pubsub": "^1.0.0", @@ -383,9 +383,9 @@ "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" }, "@types/node": { - "version": "13.13.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.17.tgz", - "integrity": "sha512-rGZftvdDpsYtG/rOlDOwny1f6Aq4FHJdGSVfPg5vC2DaR9Rt4W2OpsOF5GTU2bSqZmwTkfnsvJhhzpMWYxxlEA==" + "version": "13.13.18", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.18.tgz", + "integrity": "sha512-nru5D2PxzwzWyo3ocADAkzbc5H1KxVJMmX8oco9Fe5c+4vv6+MMp93wPq6ADqwHAwDtNH55eTCNGVaIZHZsAFQ==" }, "@types/parse-json": { "version": "4.0.0", diff --git a/package.json b/package.json index b78aad8..930e464 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "atm:lint:prettier": "prettier --write" }, "dependencies": { - "@atomist/api-cljs": "^0.4.101" + "@atomist/api-cljs": "^0.4.102" }, "main": "node_modules/@atomist/api-cljs/app.js", "devDependencies": {