-
-
Notifications
You must be signed in to change notification settings - Fork 9
40 lines (37 loc) · 1.43 KB
/
metrics.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Metrics
on:
schedule:
- cron: "0 1 * * *"
jobs:
metrics:
runs-on: ubuntu-latest
steps:
- name: Install Node ⬇️
uses: actions/setup-node@v2
with:
node-version: 17
- name: Install dependencies ⚙️
run: npm install applicationinsights
- name: Fetch repo clones and report 📈
uses: actions/github-script@v5
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-oh-my-posh'
});
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)));
let client = appInsights.defaultClient;
client.trackMetric({name: "homebrew installs", value: yesterday_clones.uniques});
console.log(yesterday_clones.uniques);