-
-
Notifications
You must be signed in to change notification settings - Fork 184
240 lines (211 loc) · 9.69 KB
/
progress-tracker.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
name: Progress Tracker
env:
# Update these environment variables every year
# And check the tracker is enabled at:
# https://github.com/HTTPArchive/almanac.httparchive.org/actions/workflows/progress-tracker.yml
FILTER_LABEL: '2024 chapter'
TRACKER_ISSUE_NUMBER: 3634
SQL_BASE_DIR: 'https://github.com/HTTPArchive/almanac.httparchive.org/tree/main/sql/2024/'
on:
workflow_dispatch:
issues:
types:
- edited
jobs:
track-progress:
name: Track Progress
if: github.repository == 'HTTPArchive/almanac.httparchive.org'
runs-on: ubuntu-20.04
steps:
- uses: actions/github-script@v7
if: github.event_name == 'workflow_dispatch' || contains(github.event.issue.labels.*.name, env.FILTER_LABEL)
with:
# yamllint disable rule:line-length
script: |
const filterLabel = process.env.FILTER_LABEL
const trackerIssueNumber = process.env.TRACKER_ISSUE_NUMBER
const sqlBaseDir = process.env.SQL_BASE_DIR
const icons = {
Draft: '📄',
SQL: '🔍',
Results: '📊'
}
const linkMap = {
Draft: /^\[~google-doc\]:\s*(?<link>\S+)/,
SQL: /^\[~sql-files\]:\s*(?<link>\S+)/,
Results: /^\[~google-sheets\]:\s*(?<link>\S+)/
}
const teamMembers = {
Leads: {},
Authors: {},
Reviewers: {},
Analysts: {},
Editors: {},
All: {}
}
const parseListItems = text => {
const items = []
text.split('\n').forEach(line => {
const m = line.trim().match(/^([*+-]|\d+\.)\s+(?<item>.+)/)
if (m) {
items.push(m.groups.item)
}
})
return items
}
const progressIssue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: trackerIssueNumber
})
const progressContent = progressIssue.data.body
const m = progressContent.match(/<!-- TASKS BEGIN -->(?<tasks>[\s\S]*)<!-- TASKS END -->/)
if (!m) {
core.info(`Tasks list marker not found in issue #${trackerIssueNumber}, add list of tracked tasks as: <!-- TASKS BEGIN -->TRACKED TASKS LIST<!-- TASKS END -->`)
return
}
const trackedTasks = parseListItems(m.groups.tasks)
const totalTrackedTasks = trackedTasks.length
core.info(`Tracking progress of ${totalTrackedTasks} tasks across chapters`)
const calcStats = nums => {
const size = nums.length
if (!size) {
return [0, 0, 0, 0, 0, 0, 0]
}
nums.sort((a, b) => a - b)
const sum = nums.reduce((a,b) => a + b, 0)
return [
sum,
nums[0],
nums[size - 1],
(sum / size).toFixed(2),
nums[Math.floor(size / 2)]
]
}
const parseTasks = text => {
const tasks = []
text.split('\n').forEach(line => {
if (/^(\s{2,})?([*+-]|\d+\.)\s+\[ \]\s+\S+/.test(line)) {
tasks.push('')
}
if (/^(\s{2,})?([*+-]|\d+\.)\s+\[[xX]\]\s+\S+/.test(line)) {
tasks.push('☑')
}
})
if (tasks[tasks.length - 1] === '☑') {
tasks[tasks.length - 1] = '🚀'
}
return tasks
}
const parseLinks = text => {
const links = {}
text.split('\n').forEach(line => {
for (const [k, v] of Object.entries(linkMap)) {
const m = line.match(v)
if (m) {
links[k] = m.groups.link
}
}
})
return links
}
const parseHeading = text => {
const m = text.match(/^#\s+Part\s+(?<part>\S+)\s+Chapter\s+(?<number>\S+)\s*:\s*(?<title>.+)/)
return m ? m.groups : {part: '', number: '', title: ''}
}
const parseUserNames = members => {
return [...members.matchAll(/@(?<username>[\w-]+)/g)].map(u => u.groups.username)
}
const parseTeam = text => {
const team = {}
text.split('\n').forEach(line => {
if (/\|\s*\@[^|]*\s*\|/.test(line)) {
const [, leads, authors, reviewers, analysts, editors] = line.split('|')
team.Leads = parseUserNames(leads)
team.Authors = parseUserNames(authors)
team.Reviewers = parseUserNames(reviewers)
team.Analysts = parseUserNames(analysts)
team.Editors = parseUserNames(editors)
team.All = [...new Set([...team.Leads,...team.Authors, ...team.Reviewers, ...team.Analysts, ...team.Editors])]
}
})
return team
}
const formatLinks = links => {
return Object.entries(links).filter(l => !['#', sqlBaseDir].includes(l[1])).map(l => `[${icons[l[0]] || l[0]}](${l[1]})`).join(' ')
}
const formatTeam = team => {
return Object.entries(team).map(([k, v]) => `<span title="${k}: ${v.length ? v.join(', ') : 'TBD'}">${v.length}</span>`).join('+').replace(/\+([^+]*)$/, ' ($1)').replace(/\+/g,' ')
}
const formatRow = chapter => {
return `${chapter.number ? `<span title="Part: ${chapter.part}, Chapter: ${chapter.number}">${chapter.number}</span>. ` : ''}[${chapter.title}](${chapter.url}) | ${formatLinks(chapter.links)} | ${formatTeam(chapter.team)} | ${chapter.tasks.join(' | ')}`
}
const taskIssues = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
direction: 'asc',
labels: filterLabel,
state: 'all'
})
let chapters = []
for (const issue of taskIssues) {
const tasksStatus = parseTasks(issue.body)
const tasksCount = tasksStatus.length
if(tasksCount != totalTrackedTasks) {
core.info(`Skipping issue #${issue.number} with ${tasksCount} instead of ${totalTrackedTasks} tasks`)
continue
}
core.info(`Adding issue #${issue.number} with ${tasksCount} tasks`)
const heading = parseHeading(issue.body)
chapters.push({
id: issue.number,
url: issue.html_url,
title: heading.title || issue.title.replace(/\b20[0-9][0-9]\b/,'').replace(/ /,' ').trim(),
part: heading.part,
number: heading.number,
links: parseLinks(issue.body),
team: parseTeam(issue.body),
tasks: tasksStatus
})
}
if(!chapters.length) {
core.info('Nothing to report')
return
}
const teamStats = {}
Object.keys(teamMembers).forEach(t => {
teamStats[t] = calcStats(chapters.map(c => (c.team[t] || []).length))
})
chapters.sort((a, b) => a.number.localeCompare(b.number, undefined, {numeric: true}))
chapters.forEach(c => {
Object.entries(c.team).forEach(([k, v]) => {
v.forEach(m => {
teamMembers[k][m] = (teamMembers[k][m] || []).concat(c.title)
})
})
})
const report = [
`Chapters | <span title="${Object.entries(icons).map(([k, v]) => `${v} (${k})`).join(', ')}">Links</span> | <span title="${Object.keys(teamMembers).join('+').replace(/\+([^+]*)$/, ' ($1)').replace(/\+/g,' ')}">Team</span> | ${trackedTasks.map((v, i) => `<span title="${v}">${i}<span>`).join(' | ')}`,
`:--------|:------|:----${'|:-:'.repeat(totalTrackedTasks)}`
].concat(chapters.map(formatRow)).join('\n')
const stats = [
'Contributor Stats | Total | Min | Max | Mean | Median',
':-----------------|------:|----:|----:|-----:|------:'
].concat(Object.entries(teamStats).map(([k, v]) => `${k} | ${v.join(' | ')}`)).join('\n')
const teams = Object.entries(teamMembers).map(([team, members]) => {
const memberList = Object.entries(members).sort(([x, a], [y, b]) => {
return x.toLocaleLowerCase().localeCompare(y.toLocaleLowerCase())
}).sort(([x, a], [y, b]) => {
return b.length - a.length
}).map(([member, chapters]) => {
return `<span title="Chapters: ${chapters.join(', ')}">${member} (${chapters.length})</span>`
}).join(', ')
return `### ${team} (${Object.keys(members).length})\n\n${memberList}`
}).join('\n\n')
github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: trackerIssueNumber,
body: progressContent.replace(/<!-- REPORT START -->[\s\S]*<!-- REPORT END -->/, `<!-- REPORT START -->\n${report}\n\n${stats}\n\n<details><summary><b>Contributor Details</b></summary>\n\n${teams}\n</details>\n<!-- REPORT END -->`)
})
core.info(`Updated report in issue #${trackerIssueNumber} with ${chapters.length} chapters`)