|
| 1 | +name: Ecosystem Cross-Repo Sync |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + create-partner-issue: |
| 9 | + if: github.event.label.name == 'ecosystem' |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Extract cross-repo references |
| 13 | + id: extract |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + script: | |
| 17 | + const body = context.payload.issue.body || ''; |
| 18 | + const title = context.payload.issue.title || ''; |
| 19 | + const issueNumber = context.payload.issue.number; |
| 20 | + const thisRepo = `${context.repo.owner}/${context.repo.repo}`; |
| 21 | +
|
| 22 | + // Find references to other deucebucket repos: deucebucket/repo-name#123 |
| 23 | + const refPattern = /deucebucket\/([a-zA-Z0-9_-]+)#(\d+)/g; |
| 24 | + const refs = []; |
| 25 | + let match; |
| 26 | + while ((match = refPattern.exec(body)) !== null) { |
| 27 | + const targetRepo = `deucebucket/${match[1]}`; |
| 28 | + if (targetRepo !== thisRepo) { |
| 29 | + refs.push({ repo: match[1], number: parseInt(match[2]) }); |
| 30 | + } |
| 31 | + } |
| 32 | +
|
| 33 | + // Find partner repos mentioned but without existing issues |
| 34 | + const repoPattern = /deucebucket\/([a-zA-Z0-9_-]+)/g; |
| 35 | + const partnerRepos = new Set(); |
| 36 | + while ((match = repoPattern.exec(body)) !== null) { |
| 37 | + const repo = match[1]; |
| 38 | + if (`deucebucket/${repo}` !== thisRepo) { |
| 39 | + partnerRepos.add(repo); |
| 40 | + } |
| 41 | + } |
| 42 | +
|
| 43 | + core.setOutput('has_refs', refs.length > 0 ? 'true' : 'false'); |
| 44 | + core.setOutput('partner_repos', JSON.stringify([...partnerRepos])); |
| 45 | + core.setOutput('this_repo', context.repo.repo); |
| 46 | + core.setOutput('issue_number', issueNumber); |
| 47 | + core.setOutput('issue_title', title); |
| 48 | +
|
| 49 | + - name: Comment with ecosystem links |
| 50 | + if: steps.extract.outputs.has_refs == 'true' |
| 51 | + uses: actions/github-script@v7 |
| 52 | + with: |
| 53 | + github-token: ${{ secrets.ECOSYSTEM_PAT }} |
| 54 | + script: | |
| 55 | + const partnerRepos = JSON.parse('${{ steps.extract.outputs.partner_repos }}'); |
| 56 | + const thisRepo = '${{ steps.extract.outputs.this_repo }}'; |
| 57 | + const issueNumber = ${{ steps.extract.outputs.issue_number }}; |
| 58 | + const issueTitle = '${{ steps.extract.outputs.issue_title }}'; |
| 59 | +
|
| 60 | + for (const repo of partnerRepos) { |
| 61 | + // Check if a tracking comment already exists in the partner repo's referenced issue |
| 62 | + const body = context.payload.issue.body || ''; |
| 63 | + const refMatch = body.match(new RegExp(`deucebucket/${repo}#(\\d+)`)); |
| 64 | +
|
| 65 | + if (refMatch) { |
| 66 | + const partnerIssueNumber = parseInt(refMatch[1]); |
| 67 | + try { |
| 68 | + // Add a cross-reference comment on the partner issue |
| 69 | + const comments = await github.rest.issues.listComments({ |
| 70 | + owner: 'deucebucket', |
| 71 | + repo: repo, |
| 72 | + issue_number: partnerIssueNumber |
| 73 | + }); |
| 74 | +
|
| 75 | + const alreadyLinked = comments.data.some(c => |
| 76 | + c.body.includes(`deucebucket/${thisRepo}#${issueNumber}`) |
| 77 | + ); |
| 78 | +
|
| 79 | + if (!alreadyLinked) { |
| 80 | + await github.rest.issues.createComment({ |
| 81 | + owner: 'deucebucket', |
| 82 | + repo: repo, |
| 83 | + issue_number: partnerIssueNumber, |
| 84 | + body: `### Ecosystem Link\n\nThis issue is linked to deucebucket/${thisRepo}#${issueNumber} — **${issueTitle}**\n\nBoth issues are tracked on [The Mead Hall](https://github.com/users/deucebucket/projects/1) project board.` |
| 85 | + }); |
| 86 | + console.log(`Linked ${repo}#${partnerIssueNumber} <-> ${thisRepo}#${issueNumber}`); |
| 87 | + } else { |
| 88 | + console.log(`Already linked: ${repo}#${partnerIssueNumber}`); |
| 89 | + } |
| 90 | + } catch (err) { |
| 91 | + console.log(`Could not comment on ${repo}#${partnerIssueNumber}: ${err.message}`); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
0 commit comments