Skip to content

Commit

Permalink
Update github-metrics-notify.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
dagnazty authored Dec 31, 2024
1 parent 3dc80aa commit 79dec0e
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions .github/workflows/github-metrics-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,38 @@ permissions:
issues: read # Optional: if you're interacting with issues
pull-requests: write # Optional: if you're interacting with pull requests

# Triggers the workflow every hour and allows manual triggering
# Triggers the workflow on specific GitHub events and schedules it as a backup
on:
# Trigger on repository star events
watch:
types: [started, deleted] # 'started' for star, 'deleted' for unstar

# Trigger on repository forks
fork:

# Trigger on issue events
issues:
types: [opened, closed, reopened, edited]

# Trigger on pull request events
pull_request:
types: [opened, closed, reopened, edited]

# Trigger on release events
release:
types: [published, edited, prereleased, released]

# Trigger on push events to the main branch
push:
branches:
- main

# Scheduled backup trigger every hour for followers/subscribers
schedule:
- cron: '0 */1 * * *' # Every hour at minute 0
workflow_dispatch: # Allows manual triggering

# Allows manual triggering
workflow_dispatch:

jobs:
notify_metrics:
Expand Down Expand Up @@ -44,7 +71,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Built-in secret provided by GitHub Actions
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} # Your Discord webhook URL
GITHUB_EVENT_NAME: ${{ github.event_name }} # To determine if run is manual or scheduled
GITHUB_EVENT_NAME: ${{ github.event_name }} # To determine if run is manual or triggered by an event
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} # Dynamic repository owner
run: |
python3 - <<'EOF' > fetch_metrics.out
Expand Down Expand Up @@ -154,17 +181,24 @@ jobs:
# Manual run: Send notification for initial setup
send_notification = True
initial_setup = True
elif event_name == 'schedule':
# Scheduled run: Do not send notification on initial setup
elif event_name == 'watch' and changes.get('stars'):
# Initial run triggered by a star event: Send notification
send_notification = True
else:
# Event-triggered runs: Do not send notification on initial setup
send_notification = False
else:
if event_name == 'workflow_dispatch':
# Manual run: Always send notification
send_notification = True
if not changes:
no_changes = True
elif event_name == 'schedule':
# Scheduled run: Send notification only if there are changes
elif event_name == 'watch':
# Star event: Send notification only if stars changed
if changes.get('stars'):
send_notification = True
else:
# Scheduled run or other events: Send notification only if there are changes
if changes:
send_notification = True
Expand Down Expand Up @@ -293,9 +327,9 @@ jobs:
id: decide_notification
run: |
if grep -q "SEND_NOTIFICATION=true" fetch_metrics.out; then
echo "send=true" >> $GITHUB_OUTPUT
echo "send=true" >> $GITHUB_OUTPUT
else
echo "send=false" >> $GITHUB_OUTPUT
echo "send=false" >> $GITHUB_OUTPUT
fi
shell: bash

Expand Down

0 comments on commit 79dec0e

Please sign in to comment.