Update Hacktoberfest Leaderboard #92
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: '18' | |
- name: Install dependencies | |
run: npm install axios cheerio | |
- name: Update leaderboard | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
async function fetchLeaderboardData() { | |
const websiteUrl = 'https://leaderboard-nk9strn08-blackgirlbytes-projects.vercel.app'; | |
console.log(`Fetching data from: ${websiteUrl}`); | |
try { | |
const response = await axios.get(websiteUrl, { | |
headers: { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' | |
} | |
}); | |
console.log('Response status:', response.status); | |
console.log('Response headers:', response.headers); | |
const $ = cheerio.load(response.data); | |
let leaderboardData = []; | |
$('table tr').slice(1).each((index, element) => { | |
const tds = $(element).find('td'); | |
leaderboardData.push({ | |
rank: index + 1, | |
contributor: $(tds[1]).text().trim(), | |
prs: parseInt($(tds[3]).text().trim(), 10), | |
points: parseInt($(tds[2]).text().trim(), 10) | |
}); | |
}); | |
console.log('Parsed leaderboard data:', leaderboardData); | |
return leaderboardData; | |
} catch (error) { | |
console.error('Error fetching website:', error.message); | |
if (error.response) { | |
console.error('Response status:', error.response.status); | |
console.error('Response headers:', error.response.headers); | |
console.error('Response data:', error.response.data); | |
} | |
throw error; | |
} | |
} | |
const issue_number = 1; // Replace with your leaderboard issue number | |
try { | |
// Fetch the current issue content | |
const { data: issue } = await github.rest.issues.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number | |
}); | |
console.log('Fetched current issue content'); | |
// Fetch the leaderboard data from the website | |
const leaderboardData = await fetchLeaderboardData(); | |
// Prepare the new issue content | |
let newContent = `# π 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:** | |
| Rank | Contributor | Number of Merged PRs | Total Points | | |
|------|----------------|----------------------|--------------| | |
${leaderboardData.map(entry => `| ${entry.rank} | ${entry.contributor} | ${entry.prs} | ${entry.points} |`).join('\n')} | |
### π 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. |`; | |
console.log('Prepared new issue content'); | |
// Update the issue with the new content | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: newContent | |
}); | |
console.log('Leaderboard updated successfully.'); | |
} catch (error) { | |
console.error('Error in main process:', error.message); | |
} |