Skip to content

Update Hacktoberfest Leaderboard #5

Update Hacktoberfest Leaderboard

Update Hacktoberfest Leaderboard #5

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: '18' # Updated to a more recent version
- name: Install dependencies
run: npm install axios cheerio
- name: Create update script
run: |
cat << EOF > update_leaderboard.js
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);
process.exit(1);
}
}
updateLeaderboard();
EOF
- name: Run update script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node update_leaderboard.js