Skip to content

Commit 774c6ab

Browse files
Merge branch 'master' into cb-bootstrap
2 parents 10d3124 + 2c4965c commit 774c6ab

File tree

5 files changed

+68
-9
lines changed

5 files changed

+68
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fabric.properties
4848
.idea
4949
secrets.json
5050
audit/*.json
51+
public_static/
5152

5253
# IDE
5354
/.vscode/

bot/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module.exports = app => {
2-
app.log('Yay, the boss bot was loaded!')
2+
const adminUsernames = ['championswimmer','abhishek97','himankbhalla','jatinkatyal13','tathagat2006','hereisnaman','TdevM']
33

4+
app.log('Yay, the boss bot was loaded!')
45
app.on('issues.opened', async context => {
56
const issue = context.payload.issue
7+
if(adminUsernames.includes(issue.user.login)){
8+
app.log(`Ignoring new issue ${issue.id} created by admin ${issue.user.login}`)
9+
return
10+
}
611
if (!issue.closed_at) {
712
app.log(`Issue Opened: ${issue.id}`)
813

@@ -20,6 +25,10 @@ Star ⭐ this project and [tweet](https://twitter.com/intent/tweet?text=I%20am%2
2025

2126
app.on('pull_request.opened', async context => {
2227
const pr = context.payload.pull_request
28+
if(adminUsernames.includes(issue.user.login)){
29+
app.log(`Ignoring new pr ${pr.id} opened by admin ${pr.user.login}`)
30+
return
31+
}
2332
if (!pr.closed_at) {
2433
app.log(`Pull Request Opened: ${pr.id}`)
2534

@@ -37,6 +46,10 @@ Star ⭐ this project and [tweet](https://twitter.com/intent/tweet?text=I%20am%2
3746

3847
app.on('pull_request.closed', async context => {
3948
const pr = context.payload.pull_request
49+
if(adminUsernames.includes(pr.user.login)){
50+
app.log(`Ignoring pr ${issue.id} closing by admin ${pr.user.login}`)
51+
return
52+
}
4053
if (!!pr.merged_at) {
4154
app.log(`Pull Request Closed: ${pr.id}`)
4255

routes/root.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ route.get('/logout', (req, res) => {
3939
res.redirect('/')
4040
})
4141

42-
route.get('/leaderboard/:year?', (req, res) => {
43-
let { year } = req.params
42+
route.get('/leaderboard/:year?', async (req, res) => {
43+
let { year = '2020'} = req.params
4444
const validYears = ['2020', '2019', '2018']
45-
45+
4646
if (!validYears.includes(year)) {
4747
return res.status(404).render('pages/404');
4848
} else {
@@ -57,14 +57,38 @@ route.get('/leaderboard/:year?', (req, res) => {
5757

5858
options.page = parseInt(options.page)
5959

60+
let loggedInUser = {};
61+
const githubDetails = req.user && req.user.usergithub
62+
if (githubDetails) {
63+
const result = await du.getLoggedInUserStats(options, githubDetails.username)
64+
if (result[0][0]) {
65+
loggedInUser = result[0][0]
66+
}
67+
}
68+
6069
du.getLeaderboard(options)
6170
.then(data => {
6271
const pagination = []
6372
const count = data[0]
6473
const rows = data[1][0]
6574
const lastPage = Math.ceil(count / options.size)
75+
const showUserAtTop = loggedInUser.user && !rows.some(row => row.user === loggedInUser.user)
76+
rows.forEach((row) => {
77+
if(githubDetails && githubDetails.username === row.user){
78+
row.isColored = true
79+
}
80+
})
81+
for (var i = 1; i <= lastPage; i++) pagination.push({link: `?page=${i}&size=${options.size}`, index: i})
6682

67-
for (var i = 1; i <= lastPage; i++) pagination.push(`?page=${i}&size=${options.size}`)
83+
let newPagination = pagination.slice(Math.max(0, options.page - 3), Math.min(options.page + 2, pagination.length));
84+
if(newPagination[0].index != 1){
85+
newPagination.unshift({link: "#", index: ". . ."});
86+
newPagination.unshift({link: `?page=${1}&size=${options.size}`, index: 1})
87+
}
88+
if(newPagination[newPagination.length -1].index != lastPage){
89+
newPagination.push({link: "#", index: ". . ."});
90+
newPagination.push({link: `?page=${lastPage}&size=${options.size}`, index: lastPage});
91+
}
6892

6993
res.render('pages/leaderboard', {
7094
prevPage: options.page - 1,
@@ -73,8 +97,10 @@ route.get('/leaderboard/:year?', (req, res) => {
7397
isLastPage: options.page == lastPage,
7498
size: options.size,
7599
page: options.page,
76-
pagination: pagination,
100+
pagination: newPagination,
77101
userstats: rows,
102+
loggedInUser,
103+
showUserAtTop,
78104
menu: {
79105
leaderboard: 'active',
80106
leaderboard2020: (year === '2020' || !year) && 'active',

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const sess = {
2121
secret: secrets.secret,
2222
resave: true,
2323
saveUninitialized: true,
24-
cookie: { maxAge: 360000, secure: false, httpOnly: false }
24+
cookie: { maxAge: 86400000, secure: false, httpOnly: false }
2525
}
2626

2727
const app = express()

utils/datautils.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ function createClaim(user, issueUrl, pullUrl, bounty, status) {
104104
})
105105
}
106106

107+
async function getLoggedInUserStats(options = {}, username) {
108+
const period = getContestPeriod(options.year)
109+
110+
const result = await db.Database.query(`with RankTable as (
111+
SELECT "user",
112+
SUM(CASE WHEN "claim"."status" = 'accepted' THEN "bounty" ELSE 0 END) as "bounty",
113+
COUNT("bounty") as "pulls",
114+
ROW_NUMBER() OVER(ORDER BY SUM(CASE WHEN "claim"."status" = 'accepted' THEN "bounty" ELSE 0 END) DESC, COUNT("bounty") DESC) as rank
115+
FROM "claims" AS "claim"
116+
where "createdAt" between '${period.start_date}' and '${period.end_date}'
117+
GROUP BY "user"
118+
ORDER BY "bounty" DESC, "pulls" DESC
119+
)
120+
SELECT RankTable.* from RankTable where RankTable.user = '${username}'`)
121+
122+
return result
123+
}
107124
function getLeaderboard(options = {}) {
108125
options.size = parseInt(options.size || 0)
109126
const offset = (options.page - 1) * options.size
@@ -120,11 +137,12 @@ function getLeaderboard(options = {}) {
120137

121138
const results = db.Database.query(`SELECT "user",
122139
SUM(CASE WHEN "claim"."status" = 'accepted' THEN "bounty" ELSE 0 END) as "bounty",
123-
COUNT("bounty") as "pulls"
140+
COUNT("bounty") as "pulls",
141+
ROW_NUMBER() OVER(ORDER BY SUM(CASE WHEN "claim"."status" = 'accepted' THEN "bounty" ELSE 0 END) DESC, COUNT("bounty") DESC) as rank
124142
FROM "claims" AS "claim"
125143
where "createdAt" between '${period.start_date}' and '${period.end_date}'
126144
GROUP BY "user"
127-
ORDER BY SUM(CASE WHEN "claim"."status" = 'accepted' THEN "bounty" ELSE 0 END) DESC, COUNT("bounty") DESC
145+
ORDER BY "bounty" DESC, "pulls" DESC
128146
LIMIT ${options.size} OFFSET ${offset}`)
129147

130148
return Promise.all([userCount, results])
@@ -159,6 +177,7 @@ module.exports = {
159177
delClaim,
160178
createClaim,
161179
getLeaderboard,
180+
getLoggedInUserStats,
162181
getClaimById,
163182
updateClaim,
164183
getCounts

0 commit comments

Comments
 (0)