-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (68 loc) · 2.63 KB
/
sync-status-across-projects.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: Sync Status Across Projects
on:
issues:
types: [edited, labeled, unlabeled, closed, reopened]
jobs:
sync-status:
runs-on: ubuntu-latest
steps:
- name: Sync Status Field
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sourceProjectId = 'YOUR_SOURCE_PROJECT_ID'; // Replace with the source project ID
const targetProjectId = 'YOUR_TARGET_PROJECT_ID'; // Replace with the target project ID
const statusFieldId = 'YOUR_STATUS_FIELD_ID'; // Replace with the status field ID for both projects
// Fetch the current issue status from the source project
const issueNodeId = context.payload.issue.node_id;
// Fetch the status field value in the source project
const { resource } = await github.graphql(`
query($projectId: ID!, $issueId: ID!) {
node(id: $issueId) {
... on Issue {
projectItems(first: 10) {
nodes {
fieldValues(first: 10) {
nodes {
projectField {
id
}
value
}
}
}
}
}
}
}
`, {
projectId: sourceProjectId,
issueId: issueNodeId
});
// Extract the current status from the source project
const currentStatus = resource.node.projectItems.nodes.find(item => item.projectField.id === statusFieldId)?.value;
if (!currentStatus) {
console.log("No status field found or status has not changed.");
return;
}
// Update the status in the target project
await github.graphql(`
mutation($projectId: ID!, $contentId: ID!, $status: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projectId,
itemId: $contentId,
fieldId: "${statusFieldId}",
value: $status
}) {
projectV2Item {
id
}
}
}
`, {
projectId: targetProjectId,
contentId: issueNodeId,
status: currentStatus
});
console.log(`Status synced successfully to target project for issue ID: ${issueNodeId}`);