Skip to content

Commit 611f30a

Browse files
committed
add syncing workflow to pull created issues into internal repo
1 parent 647be5e commit 611f30a

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

.github/workflows/sync-issues.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Sync cms-react issues
2+
3+
on:
4+
issues:
5+
types: [opened, reopened, closed]
6+
issue_comment:
7+
types: [created]
8+
9+
jobs:
10+
sync-to-enterprise:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Sync to internal repo
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{ secrets.JSR_PAT }}
17+
script: |
18+
const eventName = context.eventName;
19+
20+
if (eventName === 'issues') {
21+
const issue = context.payload.issue;
22+
23+
if (context.payload.action === 'opened' || context.payload.action === 'reopened') {
24+
const newIssue = await github.rest.issues.create({
25+
owner: 'enterprise-org-name',
26+
repo: 'enterprise-repo-name',
27+
title: issue.title,
28+
body: `Originally created by ${issue.user.login} in public repo\n\nOriginal Issue: ${issue.html_url}\n\n${issue.body}`,
29+
labels: ['synced']
30+
});
31+
32+
await github.rest.issues.createComment({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
issue_number: issue.number,
36+
body: `This issue has been synced to the enterprise repository (Issue #${newIssue.data.number}).`
37+
});
38+
} else if (context.payload.action === 'closed') {
39+
const comments = await github.rest.issues.listComments({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
issue_number: issue.number
43+
});
44+
45+
const syncComment = comments.data.find(comment =>
46+
comment.body.includes('synced to the enterprise repository (Issue #')
47+
));
48+
49+
if (syncComment) {
50+
const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1];
51+
52+
await github.rest.issues.update({
53+
owner: 'enterprise-org-name',
54+
repo: 'enterprise-repo-name',
55+
issue_number: parseInt(enterpriseIssueNumber),
56+
state: 'closed',
57+
state_reason: 'completed'
58+
});
59+
}
60+
}
61+
} else if (eventName === 'issue_comment') {
62+
const issue = context.payload.issue;
63+
const comment = context.payload.comment;
64+
65+
if (comment.user.type === 'Bot') return;
66+
67+
const comments = await github.rest.issues.listComments({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
issue_number: issue.number
71+
});
72+
73+
const syncComment = comments.data.find(c =>
74+
c.body.includes('synced to the enterprise repository (Issue #')
75+
));
76+
77+
if (syncComment) {
78+
const enterpriseIssueNumber = syncComment.body.match(/Issue #(\d+)/)[1];
79+
80+
await github.rest.issues.createComment({
81+
owner: 'enterprise-org-name',
82+
repo: 'enterprise-repo-name',
83+
issue_number: parseInt(enterpriseIssueNumber),
84+
body: `Comment from ${comment.user.login} in public repo:\n\n${comment.body}`
85+
});
86+
}
87+
}

0 commit comments

Comments
 (0)