Skip to content

Commit d5d7de3

Browse files
authored
Merge pull request #197 from department-of-veterans-affairs/bp-193-review-github-actions
Added github action workflows to test
2 parents d02d793 + bc4b3b0 commit d5d7de3

6 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Add Issue to Second Project
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
jobs:
8+
add-issue-to-project:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add Issue to Secondary Project
12+
uses: actions/github-script@v6
13+
with:
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
15+
script: |
16+
const projectId = 'YOUR_SECOND_PROJECT_ID'; // Replace with your target project ID
17+
18+
const issue = context.payload.issue;
19+
20+
const addProjectItem = await github.graphql(`
21+
mutation($projectId: ID!, $contentId: ID!) {
22+
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) {
23+
item {
24+
id
25+
}
26+
}
27+
}
28+
`, {
29+
projectId: projectId,
30+
contentId: issue.node_id
31+
});
32+
33+
console.log(`Issue #${issue.number} added to project with item ID: ${addProjectItem.addProjectV2ItemById.item.id}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Auto-label Issues
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
label-issue:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add Bug Label
12+
if: contains(github.event.issue.title, 'bug')
13+
uses: actions-ecosystem/action-add-labels@v1
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}
16+
labels: "bug"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Track Dependencies
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
add-dependency:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add Dependency Label
12+
if: contains(github.event.issue.body, '#dependent-on')
13+
uses: actions-ecosystem/action-add-labels@v1
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}
16+
labels: "dependency"

.github/workflows/set-issue-label.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Auto-label Issues
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
label-issue:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Add Bug Label
12+
if: contains(github.event.issue.title, 'bug')
13+
uses: actions-ecosystem/action-add-labels@v1
14+
with:
15+
github_token: ${{ secrets.GITHUB_TOKEN }}
16+
labels: "bug"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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}`);
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Update Issue Status
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
update-status:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Update Issue Status to "Done"
12+
uses: actions-ecosystem/action-update-comment@v1
13+
with:
14+
github_token: ${{ secrets.GITHUB_TOKEN }}
15+
issue_number: ${{ github.event.issue.number }}
16+
comment: "Status: Done"

0 commit comments

Comments
 (0)