Skip to content

Commit

Permalink
Merge branch 'rohitinu6:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
shristirwt authored Oct 25, 2024
2 parents 95d061f + 7c936ee commit 2f02293
Show file tree
Hide file tree
Showing 13 changed files with 7,728 additions and 569 deletions.
44 changes: 29 additions & 15 deletions .github/scripts/update_leaderboard.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import requests
from collections import defaultdict

# GitHub API URL for closed pull requests
API_URL = "https://api.github.com/repos/rohitinu6/Stock-Price-Prediction/pulls?state=closed"

GITHUB_TOKEN = None
GITHUB_TOKEN = os.getenv("GH_TOKEN")

# Points mapping based on the label names
points_map = {
Expand All @@ -13,38 +14,48 @@
"level3": 45
}

# Function to fetch closed pull requests
# Function to fetch closed pull requests with pagination
def get_closed_prs():
headers = {}

if GITHUB_TOKEN:
headers = {"Authorization": f"token {GITHUB_TOKEN}"}

response = requests.get(API_URL, headers=headers)

if response.status_code != 200:
raise Exception(f"Failed to fetch PRs: {response.status_code} {response.text}")

return response.json()
prs = []
page = 1
while True:
response = requests.get(f"{API_URL}&page={page}", headers=headers)

if response.status_code != 200:
raise Exception(f"Failed to fetch PRs: {response.status_code} {response.text}")

page_prs = response.json()

if not page_prs:
break

prs.extend(page_prs) # Add fetched PRs to the list
page += 1 # Increment page number for next request

return prs

leaderboard = defaultdict(lambda: {"points": 0, "avatar_url": ""})

prs = get_closed_prs()

# Loop through each PR and calculate points based on the labels
for pr in prs:
user = pr['user']['login'] # Get the username
avatar_url = pr['user']['avatar_url'] # Get the avatar URL
labels = pr['labels'] # Get the labels associated with the PR

# Loop through labels and add points based on the level
user = pr['user']['login']
avatar_url = pr['user']['avatar_url']
labels = pr['labels']

for label in labels:
label_name = label['name']
if label_name in points_map:
leaderboard[user]["points"] += points_map[label_name]
leaderboard[user]["avatar_url"] = avatar_url # Store avatar URL
leaderboard[user]["avatar_url"] = avatar_url

# Generate the leaderboard in markdown format
# Function to generate the leaderboard in markdown format
def generate_leaderboard_md(leaderboard):
sorted_leaderboard = sorted(leaderboard.items(), key=lambda x: x[1]["points"], reverse=True)

Expand All @@ -61,6 +72,9 @@ def generate_leaderboard_md(leaderboard):

# Generate the leaderboard markdown and save it to a file
leaderboard_md = generate_leaderboard_md(leaderboard)

# Save the leaderboard to leaderboard.md
with open('leaderboard.md', 'w') as f:
f.write(leaderboard_md)

print("Leaderboard updated successfully!")
66 changes: 66 additions & 0 deletions .github/workflows/issue_labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Issue Labeler

on:
issues:
types: [opened, edited]

jobs:
manage-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Create or Update Labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/labels \
-d '{
"name": "gssoc-ext",
"color": "0e4075",
"description": "GSSOC extended contribution"
}'
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/labels \
-d '{
"name": "hacktoberfest",
"color": "006b75",
"description": "Hacktoberfest participation"
}'
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/labels \
-d '{
"name": "hacktoberfest-accepted",
"color": "95d2aa",
"description": "Hacktoberfest contribution accepted"
}'
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/labels \
-d '{
"name": "level?",
"color": "5319e7",
"description": "Placeholder for difficulty level"
}'
- name: Add Labels to Issue
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: |
gssoc-ext
hacktoberfest
hacktoberfest-accepted
level?
19 changes: 13 additions & 6 deletions .github/workflows/update_leaderboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,34 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}


- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
pip install requests PyGithub
- name: Run leaderboard update script
run: |
python .github/scripts/update_structure.py
python .github/scripts/update_leaderboard.py
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Pass GitHub token to script
GITHUB_REPOSITORY: ${{ github.repository }} # Pass repository information

- name: Commit and push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add leaderboard.md
git commit -m "Update leaderboard"
git push
git add leaderboard.md || echo "No changes to commit" # Prevent errors if there's nothing to commit
git commit -m "Update leaderboard" || echo "No changes to commit"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} || echo "Nothing to push"
Loading

0 comments on commit 2f02293

Please sign in to comment.