Skip to content

Commit 34ae3fa

Browse files
committed
Pings with numbers
1 parent f670af1 commit 34ae3fa

3 files changed

Lines changed: 77 additions & 9 deletions

File tree

.github/workflows/weekly-stats.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Push AI stats to Teams
2+
3+
on:
4+
schedule:
5+
# https://crontab.guru/#0_12_*_*_1
6+
- cron: "0 12 * * 1"
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
- uses: actions/setup-node@v1
16+
17+
# Build v2
18+
- name: Deps
19+
run: |
20+
yarn install
21+
env:
22+
YARN_CHECKSUM_BEHAVIOR: ignore
23+
24+
# Update the site stats
25+
- run: node packages/typescriptlang-org/scripts/pingTeamsWithAppInsightData.js
26+
env:
27+
APP_INSIGHTS_API_KEY: ${{ secrets.APP_INSIGHTS_API_KEY }}
28+
APP_INSIGHTS_ID: ${{ secrets.APP_INSIGHTS_ID }}
29+
STATS_WEBHOOK_INCOMING_URL: ${{ secrets.STATS_WEBHOOK_INCOMING_URL }}
30+
31+
- name: Send a message to Microsoft Teams
32+
if: ${{ failure() }}
33+
uses: aliencube/[email protected]
34+
with:
35+
webhook_uri: ${{ secrets.TEAMS_WEB_BOT_INCOMING_URL }}
36+
title: Updating site stats failed
37+
summary: Something failed in the GitHub Action workflow
38+
actions: '[{ "@type": "OpenUri", "name": "View Logs", "targets": [{ "os": "default", "uri": "https://github.com/microsoft/TypeScript-Website/actions/runs/${{ github.run_id }}?check_suite_focus=true" }] }]'

packages/typescriptlang-org/scripts/pingTeamsWithAppInsightData.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
*
44
* run with:
55
APP_INSIGHTS_ID="X" APP_INSIGHTS_API_KEY="Y" node packages/typescriptlang-org/scripts/pingTeamsWithAppInsightData.js
6+
7+
if process.env.STATS_WEBHOOK_INCOMING_URL is set, then the message will go into teams
68
*/
79

810
const nodeFetch = require("node-fetch").default
911
const querystring = require("querystring")
1012

1113
const go = async () => {
1214
const dl = await getDetailsForDownloadIntention()
13-
console.log({ dl })
14-
return
1515

1616
// Sessions
1717
const all = await getCountForSessions()
@@ -30,7 +30,7 @@ const go = async () => {
3030
// Users
3131
const allUsers = await getCountForQuery(getUsersAllPrefixed())
3232

33-
// console.log({ allUsers, all, index, playground, handbook })
33+
// https://adaptivecards.io/designer
3434

3535
const headline = {
3636
type: "FactSet",
@@ -44,12 +44,16 @@ const go = async () => {
4444
value: comma(allUsers),
4545
},
4646
{
47-
title: "Homepage",
47+
title: "Homepage Sessions",
4848
value: comma(index),
4949
},
5050
],
5151
}
5252

53+
const homepageSection = makeColumn("Download", {
54+
All: comma(dl),
55+
})
56+
5357
const playgroundSection = makeColumn("Playground Usage", {
5458
All: comma(playground),
5559
})
@@ -71,12 +75,39 @@ const go = async () => {
7175
headline,
7276
{
7377
type: "ColumnSet",
74-
columns: [playgroundSection, handbookSection, jsInTSSection],
78+
columns: [
79+
homepageSection,
80+
playgroundSection,
81+
handbookSection,
82+
jsInTSSection,
83+
],
7584
},
7685
],
7786
}
7887

79-
console.log(JSON.stringify(card))
88+
if (!process.env.STATS_WEBHOOK_INCOMING_URL) {
89+
console.log(JSON.stringify(card, null, " "))
90+
} else {
91+
// https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook
92+
93+
const outer = {
94+
type: "message",
95+
attachments: [
96+
{
97+
contentType: "application/vnd.microsoft.card.adaptive",
98+
contentUrl: null,
99+
content: card,
100+
},
101+
],
102+
}
103+
104+
const r = await nodeFetch(process.env.STATS_WEBHOOK_INCOMING_URL, {
105+
method: "post",
106+
body: JSON.stringify(outer),
107+
headers: { "Content-Type": "application/json" },
108+
})
109+
console.log(r)
110+
}
80111
}
81112

82113
go()
@@ -182,8 +213,7 @@ async function getDetailsForDownloadIntention() {
182213
| make-series Sessions = dcount(session_Id) default = 0 on timestamp from ago(7d) to now() step iff(true, 7d, 7d)`
183214

184215
const response = await makeQuery(query)
185-
console.log(response.tables[0].rows)
186-
return {}
216+
return JSON.parse(response.tables[0].rows[0][0])[0]
187217
}
188218

189219
function comma(x) {

packages/typescriptlang-org/src/templates/pages/index.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ $headline-foreground-bg: #104261;
397397
}
398398
.error {
399399
background-color: #341c2c;
400-
color: #cf1616;
400+
color: #ee5858;
401401
}
402402
}
403403

0 commit comments

Comments
 (0)