Update the demo
This commit is contained in:
parent
41bf8617f1
commit
e815a20dd3
2 changed files with 100 additions and 0 deletions
33
.github/workflows/posthog_pipeline.yaml
vendored
Normal file
33
.github/workflows/posthog_pipeline.yaml
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
name: Push GitHub Data to PostHog
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *' # Runs every day at midnight
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
push-data:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- 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 posthog
|
||||
|
||||
- name: Run data extraction and push script
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
|
||||
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}
|
||||
GITHUB_REPOSITORY: ${{ github.repository }}
|
||||
run: |
|
||||
python tools/push_to_posthog.py
|
||||
67
tools/push_to_posthogh.py
Normal file
67
tools/push_to_posthogh.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# extract_and_push_github_data.py
|
||||
|
||||
import requests
|
||||
import os
|
||||
from posthog import Posthog
|
||||
|
||||
# Get environment variables
|
||||
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
||||
REPO = os.getenv('GITHUB_REPOSITORY')
|
||||
POSTHOG_API_KEY = os.getenv('POSTHOG_API_KEY') # Your PostHog Project API Key
|
||||
POSTHOG_HOST = os.getenv('POSTHOG_HOST', 'https://app.posthog.com') # Default PostHog Cloud
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {GITHUB_TOKEN}",
|
||||
"Accept": "application/vnd.github.v3+json"
|
||||
}
|
||||
|
||||
# Initialize PostHog client
|
||||
posthog = Posthog(
|
||||
api_key=POSTHOG_API_KEY,
|
||||
host=POSTHOG_HOST
|
||||
)
|
||||
|
||||
def get_repo_info():
|
||||
url = f"https://api.github.com/repos/{REPO}"
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
print(f"Error fetching repo info: {response.status_code}")
|
||||
return None
|
||||
|
||||
def main():
|
||||
repo_info = get_repo_info()
|
||||
|
||||
if repo_info:
|
||||
# Prepare data to send to PostHog
|
||||
properties = {
|
||||
'repo_name': repo_info.get('full_name'),
|
||||
'stars': repo_info.get('stargazers_count'),
|
||||
'forks': repo_info.get('forks_count'),
|
||||
'open_issues': repo_info.get('open_issues_count'),
|
||||
'watchers': repo_info.get('subscribers_count'),
|
||||
'created_at': repo_info.get('created_at'),
|
||||
'updated_at': repo_info.get('updated_at'),
|
||||
'pushed_at': repo_info.get('pushed_at'),
|
||||
'language': repo_info.get('language'),
|
||||
'license': repo_info.get('license').get('name') if repo_info.get('license') else None,
|
||||
'topics': repo_info.get('topics')
|
||||
}
|
||||
|
||||
# Send event to PostHog
|
||||
posthog.capture(
|
||||
distinct_id='github_repo', # You can customize this identifier
|
||||
event='GitHub Repo Stats',
|
||||
properties=properties
|
||||
)
|
||||
|
||||
print("Data sent to PostHog successfully.")
|
||||
else:
|
||||
print("Failed to retrieve repository information.")
|
||||
|
||||
# Close PostHog client
|
||||
posthog.shutdown()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Reference in a new issue