From c72543f67c4eaacd31345e02f35a72ed7454de28 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:19:40 +0200 Subject: [PATCH] Repository: add action users metrics (#472) --- source/templates/repository/partials/base.header.ejs | 6 ++++++ source/templates/repository/template.mjs | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/source/templates/repository/partials/base.header.ejs b/source/templates/repository/partials/base.header.ejs index 7bd4c238..744d38a6 100644 --- a/source/templates/repository/partials/base.header.ejs +++ b/source/templates/repository/partials/base.header.ejs @@ -48,6 +48,12 @@ <%= repo.environments.totalCount %> Environment<%= s(repo.environments.totalCount) %> + <% if (repo.actionUsersCount) { %> +
+ + <%= repo.actionUsersCount %> workflow<%= s(repo.actionUsersCount) %> using it +
+ <% } %> <% if (plugins.lines) { %>
diff --git a/source/templates/repository/template.mjs b/source/templates/repository/template.mjs index 89de4b62..d7691559 100644 --- a/source/templates/repository/template.mjs +++ b/source/templates/repository/template.mjs @@ -63,6 +63,18 @@ export default async function({login, q}, {data, rest, graphql, queries, account //Override plugins parameters q["projects.limit"] = 0 + //Fetching users count if it's an action + try { + if (await rest.repos.getContent({owner:login, repo, path:"action.yml"})) { + console.debug(`metrics/compute/${login}/${repo} > this repository seems to be a GitHub action, fetching users using code search`) + const {data:{total_count}} = await rest.search.code({q:`uses ${login} ${repo} path:.github/workflows language:YAML`}) + data.repo.actionUsersCount = total_count + } + } + catch { + //Ignore errors + } + //Core await imports.plugins.core(...arguments) await Promise.all(pending)