diff --git a/README.md b/README.md index bc93ce8..d667711 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,21 @@ This [action](./action.yml) generates periodic umami reports into a given file, and action outputs. -Accepted periods are: 1h, 1d, 7d, 30d, 31d. +Accepted periods are: 1h, 1d, 1w, 1m. ## Inputs -| input name | required | description | -|------------------------|----------|------------------------------------| -| `umami-server` | yes | Umami server instance (*). | -| `umami-user` | yes | Umami API user. Default `"admin"`. | -| `umami-password` | yes | Umami API password. | -| `umami-site-domain` | no | Umami site domain name (*). | -| `umami-report-file` | no | Umami report file to generate. | -| `umami-report-content` | no | Report content to generate (*). | -| `umami-period` | no | (main) Report data/analysis period (*). | -| `umami-unit` | no | (main) Report interval unit (*). | -| `umami-tz` | no | (main) Report date time timezone (*). | +| input name | required | description | +|------------------------|----------|-----------------------------------------| +| `umami-server` | yes | Umami server instance (*). | +| `umami-user` | yes | Umami API user. Default `"admin"`. | +| `umami-password` | yes | Umami API password. | +| `umami-site-domain` | no | Umami site domain name (*). | +| `umami-report-file` | no | Umami report file to generate. | +| `umami-report-content` | no | Report content to generate (*). | +| `umami-period` | no | (main) Report data/analysis period (*). | +| `umami-unit` | no | (main) Report interval unit (*). | +| `umami-tz` | no | (main) Report date time timezone (*). | legend*: - [Umami API](https://umami.is/docs/api) login expected to be available at `https:///api/auth/login`. @@ -101,9 +101,12 @@ npm manual.js ### Services or activated bots -| badge | name | description | -|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|:-----------------------------------------------------------------------------------| -| [![scheduled npm audit](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml/badge.svg)](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml) | Github actions | Continuous vulnerability audit. -| [](https://houndci.com/) | [Houndci](https://houndci.com/) | JavaScript automated review (configured by `.hound.yml`) | -| [![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/) | [gren](https://github.com/github-tools/github-release-notes) | [Release notes](https://github.com/boly38/action-umami-report/releases) automation | +- [Github actions](https://github.com/features/actions) - Continuous vulnerability audit.
+[![scheduled npm audit](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml/badge.svg)](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml) + +- [Houndci](https://houndci.com/) - JavaScript automated review (configured by [`.hound.yml`](./.hound.yml)).
+[](https://houndci.com/) + +- [gren](https://github.com/github-tools/github-release-notes) - [Release notes](https://github.com/boly38/action-umami-report/releases) automation.
+[![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/) diff --git a/lib/action.js b/lib/action.js index 9efe9de..4790042 100644 --- a/lib/action.js +++ b/lib/action.js @@ -35,9 +35,9 @@ class Action { static async produceReport(umamiSite, umamiSiteStats, sitePageViews = null, siteEvents = null, siteMetricsUrl = null, - outputFile = null, reportContent = 'pageviews|events|urls', period = '24h') { + outputFile = null, reportContent = 'pageviews|events|urls', period = '24h', unit = 'hour') { //~~ generate umami report content - const generator = new ReportGenerator(umamiSite, reportContent, period, umamiSiteStats, sitePageViews, siteEvents, siteMetricsUrl); + const generator = new ReportGenerator(umamiSite, reportContent, period, unit, umamiSiteStats, sitePageViews, siteEvents, siteMetricsUrl); const umamiOneLineReport = generator.oneLineReport(); const umamiReport = generator.detailedReport(); diff --git a/lib/reportGenerator.js b/lib/reportGenerator.js index 150a85e..cceecd6 100644 --- a/lib/reportGenerator.js +++ b/lib/reportGenerator.js @@ -4,7 +4,7 @@ const ENUMERATION_LIMIT = 10; class ReportGenerator { - constructor(umamiSite, reportContent = 'pageviews|events|urls', period = '24h', umamiSiteStats = null, sitePageViews = null, siteEvents = null, siteMetricsUrl = null) { + constructor(umamiSite, reportContent = 'pageviews|events|urls', period = '24h', unit = 'hour', umamiSiteStats = null, sitePageViews = null, siteEvents = null, siteMetricsUrl = null) { this.site = umamiSite; this.siteStats = umamiSiteStats; this.sitePageViews = sitePageViews; @@ -12,6 +12,7 @@ class ReportGenerator { this.siteMetricsUrl = siteMetricsUrl; this.reportContent = reportContent; this.period = period; + this.unit = unit; this.reportDateTime = dayjs().format('DD/MM/YYYY HH:mm') } @@ -74,9 +75,9 @@ class ReportGenerator { report += `events:\n`; var lastTime = ''; this.siteEvents.forEach( event => { - const eventDateTime = event.t.substring(11); + const eventDateTime = (this.period === '24h') ? event.t.substring(11) : event.t.substring(5); if (eventDateTime !== lastTime) { - report += ` - ${eventDateTime} ${event.y}x [${event.x}]`; + report += `\n - ${eventDateTime} ${event.y}x [${event.x}]`; } else { report += `, ${event.y}x [${event.x}]`; } diff --git a/manual.js b/manual.js index 884d162..cbc7023 100644 --- a/manual.js +++ b/manual.js @@ -10,8 +10,9 @@ const UMAMI_REPORT_FILE = process.env.UMAMI_REPORT_FILE || "umamiReport.txt"; const UMAMI_REPORT_CONTENT = process.env.UMAMI_REPORT_CONTENT || "pageviews|events|urls"; const rethrow = (err) => {throw err;} -const actionUmamiReport = async function() { - try { +class Manual { + + getOptions() { if (UMAMI_SERVER === null) { throw "please setup your environment UMAMI_SERVER, UMAMI_USER, UMAMI_PASSWORD, UMAMI_SITE_DOMAIN" } @@ -25,6 +26,11 @@ const actionUmamiReport = async function() { options.period = '24h'; options.unit = 'hour'; options.tz = 'Europe/Paris'; + return options; + } + + async report(options = {}) { + try { const reportResult = await action.umamiReport(options).catch(rethrow); if ('targetFile' in reportResult) { console.info(`Generated : ${reportResult.targetFile}`); @@ -32,6 +38,7 @@ const actionUmamiReport = async function() { } catch (error) { console.info(`ERROR: ${error}`) } -} + } -actionUmamiReport(); \ No newline at end of file +} +export default Manual; \ No newline at end of file diff --git a/manual_1m_day.js b/manual_1m_day.js new file mode 100644 index 0000000..be14b6a --- /dev/null +++ b/manual_1m_day.js @@ -0,0 +1,8 @@ +import Manual from './manual.js'; + +const manual = new Manual(); + +var options = manual.getOptions() + options.period = '1month'; + options.unit = 'day'; +manual.report(options); \ No newline at end of file diff --git a/manual_1m_hour.js b/manual_1m_hour.js new file mode 100644 index 0000000..3dc175a --- /dev/null +++ b/manual_1m_hour.js @@ -0,0 +1,8 @@ +import Manual from './manual.js'; + +const manual = new Manual(); + +var options = manual.getOptions() + options.period = '1month'; + options.unit = 'hour'; +manual.report(options); \ No newline at end of file diff --git a/manual_1w_day.js b/manual_1w_day.js new file mode 100644 index 0000000..76b90da --- /dev/null +++ b/manual_1w_day.js @@ -0,0 +1,8 @@ +import Manual from './manual.js'; + +const manual = new Manual(); + +var options = manual.getOptions() + options.period = '1week'; + options.unit = 'day'; +manual.report(options); \ No newline at end of file diff --git a/manual_1w_hour.js b/manual_1w_hour.js new file mode 100644 index 0000000..4ef93e3 --- /dev/null +++ b/manual_1w_hour.js @@ -0,0 +1,8 @@ +import Manual from './manual.js'; + +const manual = new Manual(); + +var options = manual.getOptions() + options.period = '1week'; + options.unit = 'hour'; +manual.report(options); \ No newline at end of file diff --git a/manual_24h_hour.js b/manual_24h_hour.js new file mode 100644 index 0000000..5e5758c --- /dev/null +++ b/manual_24h_hour.js @@ -0,0 +1,5 @@ +import Manual from './manual.js'; + +const manual = new Manual(); + +manual.report(manual.getOptions()); \ No newline at end of file