Last active
November 28, 2022 22:20
-
-
Save andreldm/8e290b5f3e8246c885cdb594f1cfa9ae to your computer and use it in GitHub Desktop.
Get votes count for Xfce 4.18 wallpaper contest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PROJECT = "356"; | |
const PROJECT_NAME = "artwork"; | |
const ISSUE = "1"; | |
const COOKIES = "get cookies from browser (must be logged in)"; | |
async function getNotes() { | |
let page = 1; | |
const allNotes = []; | |
while (true) { | |
const response = await fetch(`https://gitlab.xfce.org/api/v4/projects/${PROJECT}/issues/${ISSUE}/notes?page=${page}`, { headers: { Cookie: COOKIES } }); | |
const notes = await response.json(); | |
if (notes.length == 0) break; | |
allNotes.push(...notes); | |
page++; | |
} | |
return allNotes; | |
} | |
async function getEmojis(noteId) { | |
let page = 1; | |
const allEmojis = []; | |
while (true) { | |
const response = await fetch(`https://gitlab.xfce.org/api/v4/projects/${PROJECT}/issues/${ISSUE}/notes/${noteId}/award_emoji?page=${page}`, { headers: { Cookie: COOKIES } }); | |
const emojis = await response.json(); | |
if (emojis.length == 0) break; | |
allEmojis.push(...emojis); | |
page++; | |
} | |
return allEmojis; | |
} | |
(async() => { | |
const notes = await getNotes(); | |
const noteIds = notes.map(n => n.id); | |
let emojisPerNote = await Promise.all(noteIds.map(async (id) => { | |
const emojis = await getEmojis(id); | |
return { note: id, emojis: emojis }; | |
})); | |
emojisPerNote = emojisPerNote | |
.filter(el => el.emojis.length > 0) | |
.map(el => { | |
const usernames = new Set(el.emojis.filter(e => e.name == "thumbsup" || e.name == "heart").map(e => e.user.username)).size; | |
return { note: el.note, votes: usernames }; | |
}) | |
.sort((a, b) => b.votes - a.votes); | |
emojisPerNote.forEach(el => { | |
console.log(`https://gitlab.xfce.org/${PROJECT_NAME}/public/-/issues/${ISSUE}#note_${el.note} - ${el.votes} vote(s)`); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment