Skip to content

Commit

Permalink
Add new LOOKBACK_DAYS variable (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgdfool2 authored Oct 26, 2021
1 parent 768300f commit a885ee3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The dashboard has all of it's parameters passed via environment variables.
- GITHUB_APP_CLIENTSECRET - The client secret from the GitHub App general settings page.
- GITHUB_APP_INSTALLATIONID - Installation id that can be retrieved using steps in the next section.
- GITHUB_APP_WEBHOOK_SECRET - Optional. If you don't supply the dashboard will not setup webhooks and only update every 15 minutes.
- LOOKBACK_DAYS - Optional, defaults to 7. Number of days to look in the past for workflow runs.
- DEBUG=action-dashboard:\* - Optional setting to help in debugging

### Installation Id
Expand Down
7 changes: 4 additions & 3 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const _privateKey = Buffer.from(process.env.GITHUB_APP_PRIVATEKEY || "", "base64
const _clientId = process.env.GITHUB_APP_CLIENTID;
const _clientSecret = process.env.GITHUB_APP_CLIENTSECRET;
const _installationId = process.env.GITHUB_APP_INSTALLATIONID;
const _lookbackDays = process.env.LOOKBACK_DAYS || 7

// Cache all workflows to speed up refresh
let _runs = [];
Expand Down Expand Up @@ -98,13 +99,13 @@ GitHub.getUsage = async function getUsage(repoOwner, repoName, workflowId, run_i

GitHub.getMostRecentRuns = async function getMostRecentRuns(repoOwner, repoName, workflowId) {
try {
const sevenDaysAgo = dayjs().subtract(7, 'day');
const daysAgo = dayjs().subtract(_lookbackDays, 'day');
const runs = await octokit.paginate(octokit.actions.listWorkflowRuns, { repo: repoName, owner: repoOwner, workflow_id: workflowId });
if (runs.length > 0) {
const groupedRuns = _.groupBy(runs, 'head_branch')
const rows = _.reduce(groupedRuns, (result, runs, branch) => {
debug(`branch`, branch);
if (sevenDaysAgo.isBefore(dayjs(runs[0].created_at))) {
if (daysAgo.isBefore(dayjs(runs[0].created_at))) {
debug(`adding run.id: ${runs[0].id}`);
result.push({
runId: runs[0].id,
Expand Down Expand Up @@ -231,4 +232,4 @@ if (!process.env.DOCKER_BUILD) {
setInterval(GitHub.refreshRuns, 1000 * 60 * 15);
}

module.exports = GitHub;
module.exports = GitHub;

0 comments on commit a885ee3

Please sign in to comment.