Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/sync-issues.yml
Original file line number Diff line number Diff line change
@@ -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: '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']
});

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: 'HubSpot',
repo: 'cms-js-platform',
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: 'HubSpot',
repo: 'cms-js-platform',
issue_number: parseInt(enterpriseIssueNumber),
body: `Comment from ${comment.user.login} in public repo:\n\n${comment.body}`
});
}
}
Loading