Skip to content

Commit 48c0cd0

Browse files
bjohansebasCopilot
andauthored
feat: add bots configuration to display user activity (#49)
* feat: add bots configuration to display user activity * Update template/js/index.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 7addc28 commit 48c0cd0

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

lib/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const DEFAULTS = {
1717
port: 5005,
1818
template: builder,
1919
indicies,
20+
bots: true,
2021
title: 'StatusBoard',
2122
description: 'Project StatusBoard',
2223
issueLabels: ['top priority', 'good first issue', 'help wanted', 'discussion', 'meeting']
@@ -40,6 +41,9 @@ class Config {
4041
this.title = opts.title || DEFAULTS.title
4142
this.description = opts.description || DEFAULTS.description
4243

44+
// Include bots in stats
45+
this.bots = opts.bots === undefined ? DEFAULTS.bots : opts.bots
46+
4347
// Orgs
4448
this.orgs = (opts.orgs || [])
4549
.map((org) => new Organization(org))

template/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
title: "<%= title %>",
1818
description: "<%= description %>",
1919
baseUrl: "<%= baseUrl %>",
20+
bots: <%= bots %>,
2021
issueLabels: <%- JSON.stringify(issueLabels) %>,
2122
projects: <%- JSON.stringify(projects) %>,
2223
files: <%- JSON.stringify(files) %>

template/js/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,25 @@ require('nighthawk')({
4646
next()
4747
})
4848
.get('/', fetchIssues({ limit: 3 }), async (req, res) => {
49-
// Turn user activity into a orderd list of 20
49+
// Turn user activity into an ordered list of 20
5050
const userActivity = await (await fetch(`${config.baseUrl}/data/userActivity.json`)).json()
51-
const u = Object.values(userActivity).sort((v1, v2) => {
52-
return v1.activityCount < v2.activityCount ? 1 : v1.activityCount === v2.activityCount ? 0 : -1
53-
}).slice(0, 20)
51+
const u = Object.values(userActivity)
52+
.filter(user => {
53+
if (!config.bots && user?.type) {
54+
return user.type !== 'Bot'
55+
}
56+
57+
// Because the GitHub API doesn’t return a type for the Dependabot account
58+
else if (!config.bots && user.login && user.login.endsWith('[bot]')) {
59+
return false
60+
}
61+
62+
return true
63+
})
64+
.sort((v1, v2) => {
65+
return v1.activityCount < v2.activityCount ? 1 : v1.activityCount === v2.activityCount ? 0 : -1
66+
})
67+
.slice(0, 20)
5468

5569
render(html`
5670
<statusboard-page .config="${config}">

0 commit comments

Comments
 (0)