From 611f30ad4a9d0ebd42fa508ddccb72a0975a5c98 Mon Sep 17 00:00:00 2001 From: Jon Miller Date: Fri, 14 Mar 2025 12:42:24 -0500 Subject: [PATCH 1/2] add syncing workflow to pull created issues into internal repo --- .github/workflows/sync-issues.yml | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/sync-issues.yml diff --git a/.github/workflows/sync-issues.yml b/.github/workflows/sync-issues.yml new file mode 100644 index 0000000..5c3674a --- /dev/null +++ b/.github/workflows/sync-issues.yml @@ -0,0 +1,87 @@ +name: Sync cms-react issues + +on: + issues: + types: [opened, reopened, closed] + issue_comment: + types: [created] + +jobs: + sync-to-enterprise: + runs-on: ubuntu-latest + steps: + - name: Sync to internal repo + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.JSR_PAT }} + script: | + const eventName = context.eventName; + + if (eventName === 'issues') { + const issue = context.payload.issue; + + if (context.payload.action === 'opened' || context.payload.action === 'reopened') { + const newIssue = await github.rest.issues.create({ + owner: 'enterprise-org-name', + repo: 'enterprise-repo-name', + title: issue.title, + body: `Originally created by ${issue.user.login} in public repo\n\nOriginal Issue: ${issue.html_url}\n\n${issue.body}`, + labels: ['synced'] + }); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + body: `This issue has been synced to the enterprise repository (Issue #${newIssue.data.number}).` + }); + } else if (context.payload.action === 'closed') { + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number + }); + + const syncComment = comments.data.find(comment => + comment.body.includes('synced to the enterprise repository (Issue #') + )); + + if (syncComment) { + const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1]; + + await github.rest.issues.update({ + owner: 'enterprise-org-name', + repo: 'enterprise-repo-name', + issue_number: parseInt(enterpriseIssueNumber), + state: 'closed', + state_reason: 'completed' + }); + } + } + } else if (eventName === 'issue_comment') { + const issue = context.payload.issue; + const comment = context.payload.comment; + + if (comment.user.type === 'Bot') return; + + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number + }); + + const syncComment = comments.data.find(c => + c.body.includes('synced to the enterprise repository (Issue #') + )); + + if (syncComment) { + const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1]; + + await github.rest.issues.createComment({ + owner: 'enterprise-org-name', + repo: 'enterprise-repo-name', + issue_number: parseInt(enterpriseIssueNumber), + body: `Comment from ${comment.user.login} in public repo:\n\n${comment.body}` + }); + } + } From 3c230f65b91669b30871836239a43b0f25698236 Mon Sep 17 00:00:00 2001 From: Jon Miller Date: Wed, 19 Mar 2025 13:45:15 -0500 Subject: [PATCH 2/2] remove placeholders --- .github/workflows/sync-issues.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync-issues.yml b/.github/workflows/sync-issues.yml index 5c3674a..6677a2b 100644 --- a/.github/workflows/sync-issues.yml +++ b/.github/workflows/sync-issues.yml @@ -22,8 +22,8 @@ jobs: if (context.payload.action === 'opened' || context.payload.action === 'reopened') { const newIssue = await github.rest.issues.create({ - owner: 'enterprise-org-name', - repo: 'enterprise-repo-name', + owner: 'HubSpot', + repo: 'cms-js-platform', title: issue.title, body: `Originally created by ${issue.user.login} in public repo\n\nOriginal Issue: ${issue.html_url}\n\n${issue.body}`, labels: ['synced'] @@ -50,8 +50,8 @@ jobs: const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1]; await github.rest.issues.update({ - owner: 'enterprise-org-name', - repo: 'enterprise-repo-name', + owner: 'HubSpot', + repo: 'cms-js-platform', issue_number: parseInt(enterpriseIssueNumber), state: 'closed', state_reason: 'completed' @@ -78,8 +78,8 @@ jobs: const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1]; await github.rest.issues.createComment({ - owner: 'enterprise-org-name', - repo: 'enterprise-repo-name', + owner: 'HubSpot', + repo: 'cms-js-platform', issue_number: parseInt(enterpriseIssueNumber), body: `Comment from ${comment.user.login} in public repo:\n\n${comment.body}` });