-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (108 loc) · 4.33 KB
/
set-default-priority.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Set Default Issue Priority
on:
issues:
types: [opened]
jobs:
set-priority:
runs-on: ubuntu-latest
steps:
- name: Set Issue Priority to Normal
uses: actions/github-script@v6
with:
script: |
const issueNumber = context.payload.issue.number;
const org = "department-of-veterans-affairs";
const repo = "tmf-auth-exp-design-patterns";
const projectNumber = 1314;
async function setDefaultPriority() {
try {
// Get the project ID and fields using GraphQL
const { data: { organization } } = await github.graphql(`
query($org: String!, $projectNumber: Int!) {
organization(login: $org) {
projectV2(number: $projectNumber) {
id
fields(first: 20) {
nodes {
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
items(first: 10, orderBy: {field: POSITION, direction: DESC}) {
nodes {
id
content {
... on Issue {
id
number
}
}
}
}
}
}
}
`, {
org: org,
projectNumber: projectNumber
});
const project = organization.projectV2;
console.log(`Found project with ID: ${project.id}`);
const priorityField = project.fields.nodes.find(field => field.name === "Priority");
if (!priorityField) {
console.log("Priority field not found in the project");
return;
}
const normalOption = priorityField.options.find(option => option.name.toLowerCase() === "normal");
if (!normalOption) {
console.log("Normal priority option not found");
return;
}
console.log(`Found "Normal" priority option with ID: ${normalOption.id}`);
const projectItem = project.items.nodes.find(item => item.content && item.content.number === issueNumber);
if (!projectItem) {
console.log("Issue not found in the project");
return;
}
console.log(`Found issue in project with item ID: ${projectItem.id}`);
// Update the Priority field for the issue in the project
const result = await github.graphql(`
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId,
itemId: $itemId,
fieldId: $fieldId,
value: {
singleSelectOptionId: $optionId
}
}
) {
projectV2Item {
id
}
}
}
`, {
projectId: project.id,
itemId: projectItem.id,
fieldId: priorityField.id,
optionId: normalOption.id
});
console.log("Issue priority successfully set to 'Normal'");
console.log("Result:", result);
} catch (error) {
console.error("Error:", error.message);
if (error.request) {
console.error("GraphQL query:", error.request.query);
console.error("Variables:", error.request.variables);
}
}
}
setDefaultPriority();