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