Metrics #259
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Metrics | |
on: | |
schedule: | |
- cron: "0 1 * * *" | |
jobs: | |
metrics: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Node ⬇️ | |
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c | |
with: | |
node-version: 17 | |
- name: Install dependencies ⚙️ | |
run: npm install applicationinsights | |
- name: Fetch repo clones and report 📈 | |
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 | |
env: | |
APPINSIGHTS_INSTRUMENTATIONKEY: ${{ secrets.APPINSIGHTS_INSTRUMENTATIONKEY }} | |
with: | |
github-token: ${{ secrets.GH_PAT }} | |
script: | | |
let appInsights = require('applicationinsights'); | |
appInsights.setup(); | |
clones = await github.rest.repos.getClones({ | |
owner: 'jandedobbeleer', | |
repo: 'homebrew-aliae' | |
}); | |
const isSameDay = (first, second) => | |
first.getFullYear() === second.getFullYear() && | |
first.getMonth() === second.getMonth() && | |
first.getDate() === second.getDate(); | |
const parseDate = (timestamp) => new Date(Date.parse(timestamp)); | |
const yesterday = ( d => new Date(d.setDate(d.getDate()-1)) )(new Date); | |
yesterday_clones = clones.data.clones.find(clone => isSameDay(yesterday, parseDate(clone.timestamp))); | |
if (yesterday_clones === undefined) { | |
yesterday_clones = {uniques: 0}; | |
} | |
let client = appInsights.defaultClient; | |
client.trackMetric({name: "homebrew installs", value: yesterday_clones.uniques}); | |
console.log(yesterday_clones.uniques); | |