Automate Your GitHub Profile: A Pure GraphQL Approach to Showcasing Software Development Activity

Keeping your GitHub profile README up-to-date with your latest contributions, pinned repositories, and blog posts can be a tedious manual task. However, a recent discussion in the GitHub Community highlights an elegant, self-updating solution that leverages GitHub Actions and the GraphQL API, entirely avoiding third-party services. This approach not only streamlines the process but also provides a dynamic showcase of your software development activity.

Automated GitHub profile README updating with code and activity.
Automated GitHub profile README updating with code and activity.

The Pure GitHub Approach to Dynamic Profiles

The discussion, initiated by 2023bme14-gif, sought a method to automatically reflect a user's latest activity on their profile README. Sagargupta16 provided a comprehensive solution, demonstrating how to achieve this using only built-in GitHub features. This method is perfect for individuals or teams looking for efficient development measurement and showcasing their work without external dependencies.

1. The GitHub Action Workflow

The core of the automation lies in a GitHub Actions workflow. This workflow is configured to run on a schedule (e.g., every 6 hours) and can also be triggered manually (workflow_dispatch). It checks out the repository, executes a Python script to fetch and update data, and then commits any changes back to the README.md file. The use of GITHUB_TOKEN ensures secure authentication with sufficient scope to read public data.

name: Update README
on:
  schedule:
    - cron: "0 */6 * * *" # every 6 hours
  workflow_dispatch:
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Fetch and update
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: python update_readme.py
      - name: Commit changes
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git diff --quiet || (git add README.md && git commit -m "chore: update README" && git push)

2. The Python Script with GraphQL

The heavy lifting of data retrieval is handled by a Python script (update_readme.py). This script uses Python's standard libraries (os, json, urllib.request) to interact with the GitHub GraphQL API. GraphQL allows for precise data fetching, meaning you only request the information you need, such as pinned repositories, total commit contributions, and pull request contributions. This efficiency is key for effective development measurement.

The script constructs GraphQL queries to fetch specific user data. For instance, it queries for the user's pinned items (repositories) and their contributions collection, providing a snapshot of their recent software development activity.

import os, json, urllib.request

TOKEN = os.environ["GH_TOKEN"]
USERNAME = "your-username" # Remember to replace with your actual username

def graphql(query):
    req = urllib.request.Request(
        "https://api.github.com/graphql",
        data=json.dumps({"query": query}).encode(),
        headers={"Authorization": f"bearer {TOKEN}", "Content-Type": "application/json"}
    )
    return json.loads(urllib.request.urlopen(req).read())

# Fetch pinned repos and contributions
result = graphql(f"""
{{
  user(login: "{USERNAME}") {{
    pinnedItems(first: 6, types: REPOSITORY) {{
      nodes {{
        ... on Repository {{
          name
          description
          url
          stargazerCount
        }}
      }}
    }}
    contributionsCollection {{
      totalCommitContributions
      totalPullRequestContributions
    }}
  }}
}}
""")
user = result["data"]["user"]
pinned = user["pinnedItems"]["nodes"]
c
# ... further processing to format data for README ...

3. Templating Your README

Once the data is fetched, the Python script then dynamically updates the README.md file. This is achieved by defining specific markers within your README (e.g., and ). The script reads the README.md, replaces the content between these markers with the newly fetched data (formatted as Markdown), and then writes the updated content back to the file.

For incorporating blog posts, the solution suggests using urllib to fetch an RSS feed and xml.etree.ElementTree to parse it. This again demonstrates how to extend the functionality using only standard Python libraries, maintaining the "no third-party services" ethos. This method allows for a comprehensive display of your contributions and insights, making your profile a true reflection of your ongoing software development activity and achievements, which can be valuable for engineering team goals examples and personal branding.

This community insight provides a robust and elegant solution for anyone looking to automate their GitHub profile README, ensuring it always showcases the most current and relevant information about their development journey.

Visualizing software development activity and contributions.
Visualizing software development activity and contributions.

Track, Analyze and Optimize Your Software DeveEx!

Effortlessly implement gamification, pre-generated performance reviews and retrospective, work quality analytics, alerts on top of your code repository activity

 Install GitHub App to Start
devActivity Screenshot