-
Notifications
You must be signed in to change notification settings - Fork 4
Updates Projects and Contributors Wall with Real Data. #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| docs/ | ||
| docs/ | ||
| .env | ||
| *.env |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/usr/bin/env bash | ||
| # fetch_github_data.sh - Retrieves live data for the Demon-Die GitHub organization | ||
| # Requires jq to be installed. | ||
|
|
||
| # Load the PAT from .env (strip spaces around =) | ||
| ENV_FILE="$(dirname "$0")/.env" | ||
| if [[ ! -f "$ENV_FILE" ]]; then | ||
| echo "Error: .env file not found" | ||
| exit 1 | ||
| fi | ||
| # Extract token value (supports spaces around =) | ||
| TOKEN=$(grep -E "^GIT_DEMONDIE_ALL" "$ENV_FILE" | cut -d'=' -f2- | tr -d ' \"') | ||
| if [[ -z "$TOKEN" ]]; then | ||
| echo "Error: GitHub token not found in .env" | ||
| exit 1 | ||
| fi | ||
| ORG="Demon-Die" | ||
|
|
||
| # ------------------------------------------------------------ | ||
| # Fetch organization repositories (first 100, pagination if needed) | ||
| REPOS=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/orgs/$ORG/repos?per_page=100") | ||
| PROJECT_COUNT=$(echo "$REPOS" | jq length) | ||
| TOTAL_STARS=$(echo "$REPOS" | jq '[.[] .stargazers_count] | add') | ||
| # Build repos array with needed fields | ||
| REPOS_DATA=$(echo "$REPOS" | jq '[.[] | {name: .name, description: .description, stars: .stargazers_count, html_url: .html_url}]') | ||
|
Pranav00076 marked this conversation as resolved.
|
||
|
|
||
| # ------------------------------------------------------------ | ||
| # Aggregate all unique contributors across all repositories using JSON array merging | ||
| ALL_CONTRIBS="[]" | ||
| for REPO_NAME in $(echo "$REPOS" | jq -r '.[].name'); do | ||
| PAGE=1 | ||
| while true; do | ||
| ContribResp=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/repos/$ORG/$REPO_NAME/contributors?per_page=100&page=$PAGE") | ||
| COUNT=$(echo "$ContribResp" | jq length) | ||
| if [[ $COUNT -eq 0 ]]; then | ||
| break | ||
| fi | ||
| # Merge this page's contributors into the accumulator (ensure array) | ||
| ALL_CONTRIBS=$(printf '%s | ||
| %s' "$ALL_CONTRIBS" "$ContribResp" | jq -s 'add') | ||
| ((PAGE++)) | ||
| done | ||
| done | ||
|
|
||
| # Deduplicate contributors | ||
| UNIQUE_CONTRIBS=$(echo "$ALL_CONTRIBS" | jq 'unique_by(.login)') | ||
| # Fetch org members and ensure it's an array | ||
| ORG_MEMBERS_RAW=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/orgs/$ORG/members?per_page=100") | ||
| ORG_MEMBERS=$(echo "$ORG_MEMBERS_RAW" | jq 'if type=="array" then . else [. ] end') | ||
| # Merge contributors and org members, deduplicate again | ||
| ALL_USERS=$(printf '%s | ||
| %s' "$UNIQUE_CONTRIBS" "$ORG_MEMBERS" | jq -s 'add | unique_by(.login)') | ||
| PRIORITY_LOGINS=("RishiByte" "Pranav00076" "SharanyoBanerjee" "Yuvraj-Sarathe") | ||
| MEMBERS_DATA="[]" | ||
| # Add priority members first | ||
| for LOGIN in "${PRIORITY_LOGINS[@]}"; do | ||
| MATCH=$(echo "$ALL_USERS" | jq -c ".[] | select(.login == \"$LOGIN\")") | ||
| if [[ -n "$MATCH" ]]; then | ||
| # Ensure MATCH is an array before adding | ||
| MATCH_ARRAY=$(echo "$MATCH" | jq -c '[.]') | ||
| MEMBERS_DATA=$(printf '%s\n%s' "$MEMBERS_DATA" "$MATCH_ARRAY" | jq -s 'add') | ||
| fi | ||
| done | ||
| # Add remaining members | ||
| REMAINING=$(echo "$ALL_USERS" | jq -c --argjson p "$(printf '%s\n' "${PRIORITY_LOGINS[@]}" | jq -R . | jq -s .)" '[.[] | select(.login as $l | $p | index($l) | not)]') | ||
| MEMBERS_DATA=$(printf '%s\n%s' "$MEMBERS_DATA" "$REMAINING" | jq -s 'add') | ||
|
|
||
| CONTRIBUTOR_COUNT=$(echo "$MEMBERS_DATA" | jq length) | ||
|
|
||
| # ------------------------------------------------------------ | ||
| # Output summary JSON | ||
| cat > "$(dirname "$0")/github_summary.json" <<EOF | ||
| { | ||
| "project_count": $PROJECT_COUNT, | ||
| "total_stars": $TOTAL_STARS, | ||
| "contributor_count": $CONTRIBUTOR_COUNT, | ||
| "repos": $REPOS_DATA, | ||
| "members": $MEMBERS_DATA | ||
| } | ||
| EOF | ||
|
|
||
| echo "GitHub summary written to github_summary.json" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.