This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenarxbot-post-sprint-cleanup
executable file
·125 lines (112 loc) · 3.6 KB
/
enarxbot-post-sprint-cleanup
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
124
125
#!/usr/bin/python3
# SPDX-License-Identifier: Apache-2.0
from githubgql import githubgql
import constants
import json
import sys
import os
# Several GraphQL queries and mutations.
QUERY = """
query($sprintColumnId:ID!, $planningColumnId:ID!, $sprintCardsCursor:String, $planningCardsCursor:String) {
sprint: node(id:$sprintColumnId) {
...on ProjectColumn {
cards(first:100, after:$sprintCardsCursor) {
pageInfo { endCursor hasNextPage }
nodes {
id
content {
...on Issue {
id
}
}
}
}
}
}
planning: node(id:$planningColumnId) {
...on ProjectColumn {
cards(first:100, after:$planningCardsCursor) {
pageInfo { endCursor hasNextPage }
nodes {
id
content {
...on Issue {
id
}
}
}
}
}
}
}
"""
QUERY_CURSORS = {
'sprintCardsCursor': ["sprint", "cards"],
'planningCardsCursor': ["planning", "cards"]
}
MOVE_CARD_MUTATION = """
mutation($input:MoveProjectCardInput!) {
moveProjectCard(input:$input) {
clientMutationId
}
}
"""
ADD_CARD_MUTATION = """
mutation($input:AddProjectCardInput!) {
addProjectCard(input:$input) {
clientMutationId
}
}
"""
DELETE_CARD_MUTATION = """
mutation($input:DeleteProjectCardInput!) {
deleteProjectCard(input:$input) {
clientMutationId
}
}
"""
if os.environ["GITHUB_EVENT_NAME"] != "workflow_dispatch":
sys.exit(0)
# Query all cards in two columns: the assigned columns of both Planning and Sprint.
try:
result = githubgql.graphql(
QUERY,
planningColumnId=constants.COLUMNS['Planning']['Assigned'],
sprintColumnId=constants.COLUMNS['Sprint']['Assigned'],
cursors=QUERY_CURSORS
)
except githubgql.TokenError as e:
print(e.error)
sys.exit(0)
# Create sets of issue IDs that are in each column. Also create lookup tables
# for corresponding card IDs for API actions.
planning_content = {c['content']['id'] for c in result['planning']['cards']['nodes'] if c['content'].get('id', None) is not None}
planning_content_cards = {c['content']['id']: c['id'] for c in result['planning']['cards']['nodes'] if c['content'].get('id', None) is not None}
sprint_content = {c['content']['id'] for c in result['sprint']['cards']['nodes'] if c['content'].get('id', None) is not None}
sprint_content_cards = {c['content']['id']: c['id'] for c in result['sprint']['cards']['nodes'] if c['content'].get('id', None) is not None}
for content in sprint_content:
# If the issue is already present in an existing card on the Planning
# board, move that card. If not, create a new card.
if content in planning_content:
githubgql.graphql(
MOVE_CARD_MUTATION,
input={
"columnId": constants.COLUMNS["Planning"]["Nominated"],
"cardId": planning_content_cards[content]
}
)
else:
githubgql.graphql(
ADD_CARD_MUTATION,
input={
"projectColumnId": constants.COLUMNS["Planning"]["Nominated"],
"contentId": content
}
)
# Once done moving/creating cards, delete the issue from the Sprint board.
githubgql.graphql(
DELETE_CARD_MUTATION,
input={
"cardId": sprint_content_cards[content]
}
)