Update Hacktoberfest Leaderboard #4
This file contains 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
name: Update Hacktoberfest Leaderboard | |
on: | |
schedule: | |
- cron: '0 */6 * * *' # Runs every 6 hours | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
update-leaderboard: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14' | |
- name: Install dependencies | |
run: npm install axios cheerio | |
- name: Fetch website data and update GitHub issue | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
async function updateLeaderboard() { | |
try { | |
// Fetch data from the website | |
const websiteUrl = 'https://leaderboard-nk9strn08-blackgirlbytes-projects.vercel.app'; | |
const { data } = await axios.get(websiteUrl); | |
const $ = cheerio.load(data); | |
// Extract table data | |
let leaderboardContent = '| Rank | Username | Points | PRs |\n|------|----------|--------|-----|\n'; | |
$('table tr').slice(1).each((i, elem) => { | |
const tds = $(elem).find('td'); | |
leaderboardContent += `| ${$(tds[0]).text().trim()} | ${$(tds[1]).text().trim()} | ${$(tds[2]).text().trim()} | ${$(tds[3]).text().trim()} |\n`; | |
}); | |
// Prepare issue content | |
const issueContent = `# π TBD Hacktoberfest 2024 Leaderboard π | |
Hello, lovely contributors! As Hacktoberfest 2024 and the crisp Fall breeze refreshes us, we wanted to make the contribution process extra fun. Check our live leaderboard below to see who our top contributors are this year in real-time. Not only does this recognize everyone's efforts, it also brings an amplified competitive vibe with each contribution. | |
### π **Current Rankings:** | |
${leaderboardContent} | |
### π How It Works: | |
The top 10 contributors with the most points will snag custom swag with this year's exclusive TBD x Hacktoberfest 2024 design. To earn your place in the leaderboard, we have created a points system that is explained below. As you complete a task by successfully merging a PR, you will automatically be granted a certain number of points. | |
#### π― Point System | |
| Weight | Points Awarded | Description | | |
|--------|----------------|-------------| | |
| π **Small** | 5 points | For smaller tasks that take limited time to complete and/or don't require any product knowledge. |`; | |
// Update GitHub issue | |
const issueUrl = 'https://api.github.com/repos/galaxy-bytes/main-test-repo/issues/1'; | |
await axios.patch(issueUrl, | |
{ body: issueContent }, | |
{ | |
headers: { | |
'Authorization': `token ${process.env.GITHUB_TOKEN}`, | |
'Accept': 'application/vnd.github.v3+json' | |
} | |
} | |
); | |
console.log('Leaderboard issue updated successfully!'); | |
} catch (error) { | |
console.error('Error updating leaderboard:', error.message); | |
} | |
} | |
updateLeaderboard(); |