Skip to content

Monitor Upstream Changes #3

Monitor Upstream Changes

Monitor Upstream Changes #3

name: Monitor Upstream Changes
on:
schedule:
# Run Monday and Thursday at 9 AM UTC
- cron: '0 9 * * 1,4'
workflow_dispatch:
inputs:
target:
description: 'Which upstream to check'
required: false
default: 'all'
type: choice
options:
- all
- upstream
- quotio
jobs:
check-upstreams:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Add upstream remotes
run: |
git remote add upstream https://github.com/steipete/CodexBar.git || true
git remote add quotio https://github.com/nguyenphutrong/quotio.git || true
git fetch upstream
git fetch quotio
- name: Check for new commits
id: check
run: |
# Count new commits in upstream
UPSTREAM_NEW=$(git log --oneline main..upstream/main --no-merges 2>/dev/null | wc -l | tr -d ' ')
echo "upstream_commits=$UPSTREAM_NEW" >> $GITHUB_OUTPUT
# Count new commits in quotio (last 7 days)
QUOTIO_NEW=$(git log --oneline --all --remotes=quotio/main --since="7 days ago" 2>/dev/null | wc -l | tr -d ' ')
echo "quotio_commits=$QUOTIO_NEW" >> $GITHUB_OUTPUT
# Get commit summaries
echo "upstream_summary<<EOF" >> $GITHUB_OUTPUT
git log --oneline main..upstream/main --no-merges 2>/dev/null | head -10 >> $GITHUB_OUTPUT || echo "No commits" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "quotio_summary<<EOF" >> $GITHUB_OUTPUT
git log --oneline --remotes=quotio/main --since="7 days ago" 2>/dev/null | head -10 >> $GITHUB_OUTPUT || echo "No commits" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create or update issue
if: steps.check.outputs.upstream_commits > 0 || steps.check.outputs.quotio_commits > 0
uses: actions/github-script@v7
with:
script: |
const upstreamCommits = '${{ steps.check.outputs.upstream_commits }}';
const quotioCommits = '${{ steps.check.outputs.quotio_commits }}';
const upstreamSummary = `${{ steps.check.outputs.upstream_summary }}`;
const quotioSummary = `${{ steps.check.outputs.quotio_summary }}`;
const body = `## 🔄 Upstream Changes Detected
**steipete/CodexBar:** ${upstreamCommits} new commits
**quotio:** ${quotioCommits} new commits (last 7 days)
### steipete/CodexBar Recent Commits
\`\`\`
${upstreamSummary}
\`\`\`
### quotio Recent Commits
\`\`\`
${quotioSummary}
\`\`\`
### 📋 Review Actions
**Review upstream changes:**
\`\`\`bash
./Scripts/review_upstream.sh upstream
\`\`\`
**Review quotio changes:**
\`\`\`bash
./Scripts/analyze_quotio.sh
\`\`\`
**View detailed diffs:**
\`\`\`bash
git diff main..upstream/main
git log -p quotio/main --since='7 days ago'
\`\`\`
### 🔗 Links
- [steipete commits](https://github.com/steipete/CodexBar/compare/${context.sha}...steipete:CodexBar:main)
- [quotio commits](https://github.com/nguyenphutrong/quotio/commits/main)
---
*Auto-generated by upstream-monitor workflow*
*Last checked: ${new Date().toISOString()}*`;
// Check for existing open issue
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: 'upstream-sync',
state: 'open'
});
if (issues.data.length > 0) {
// Update existing issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: body
});
// Add comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issues.data[0].number,
body: `🔄 Updated with latest changes (${upstreamCommits} upstream, ${quotioCommits} quotio)`
});
} else {
// Create new issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '🔄 Upstream Changes Available for Review',
body: body,
labels: ['upstream-sync', 'needs-review']
});
}
- name: No changes detected
if: steps.check.outputs.upstream_commits == 0 && steps.check.outputs.quotio_commits == 0
run: |
echo "✅ No new upstream changes detected"
echo "steipete/CodexBar: up to date"
echo "quotio: no commits in last 7 days"