From a4441a0973ab0ecf76de55d7a872ea1b37884ced Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sun, 20 Oct 2019 09:39:45 +0300 Subject: [PATCH 1/2] fix getBuildDetails url and tag builds where branch does not exists --- src/jobs/recent-circle-ci-builds.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/jobs/recent-circle-ci-builds.js b/src/jobs/recent-circle-ci-builds.js index 33a9faf..ec4fe8c 100644 --- a/src/jobs/recent-circle-ci-builds.js +++ b/src/jobs/recent-circle-ci-builds.js @@ -23,7 +23,7 @@ function getRecentBuilds(limit = 10) { } function getBuildDetails(build) { - const uri = `https://circleci.com/api/v1.1/project/github/ePages-de/${build.reponame}/${build.circleCiJob}`; + const uri = `https://circleci.com/api/v1.1/project/github/${build.owner}/${build.reponame}/${build.circleCiJob}`; return request({ ...requestOptions, @@ -124,6 +124,11 @@ export const perform = async () => { const key = (workflows || {}).workflow_id || (reponame + branch); + if (!branch) { + // if build does not contains branch (e.g. tag build) + return allBuilds + } + // skip all but the most recent builds for the same branch if (Object.values(allBuilds).find( b => b.reponame === reponame @@ -174,7 +179,7 @@ export const perform = async () => { if (build.buildStatus === 'failed') { if (build.workflowSteps && build.workflowSteps.length > 1) { for await (const step of build.workflowSteps) - step.failedStep = ((await getBuildDetails(step)) + step.failedStep = ((await getBuildDetails(build)) .steps.find(step => step.actions.find(action => action.failed)) || {}) .name; From c8202968960b0546df35ef4357754226959fe460 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Sun, 20 Oct 2019 09:40:03 +0300 Subject: [PATCH 2/2] add github org filtering --- README.md | 3 +++ src/jobs/recent-circle-ci-builds.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index fdc1e57..6431393 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ metricio: CIRCLE_CI_TOKEN: $CIRCLE_CI_TOKEN GITHUB_USER: $GITHUB_USER GITHUB_TOKEN: $GITHUB_TOKEN + GITHUB_ORG: $GITHUB_ORG redis: container_name: circle-ci-wall-redis @@ -30,6 +31,7 @@ Just run the following commands: export CIRCLE_CI_TOKEN= export GITHUB_USER= export GITHUB_TOKEN= +export GITHUB_ORG= docker-compose up -d ``` @@ -40,6 +42,7 @@ docker-compose up -d 1. `export CIRCLE_CI_TOKEN=` (see above) 1. `export GITHUB_USER=` (see above) 1. `export GITHUB_TOKEN=` (see above) +1. `export GITHUB_ORG=` (see above) 1. `npm start` 1. navigate to http://localhost:3000 diff --git a/src/jobs/recent-circle-ci-builds.js b/src/jobs/recent-circle-ci-builds.js index ec4fe8c..5ea63d5 100644 --- a/src/jobs/recent-circle-ci-builds.js +++ b/src/jobs/recent-circle-ci-builds.js @@ -129,6 +129,12 @@ export const perform = async () => { return allBuilds } + const GITHUB_ORG = process.env['GITHUB_ORG'] + if (GITHUB_ORG && username !== GITHUB_ORG) { + return allBuilds; + } + + // skip all but the most recent builds for the same branch if (Object.values(allBuilds).find( b => b.reponame === reponame