-
Notifications
You must be signed in to change notification settings - Fork 3
184 lines (160 loc) · 6.2 KB
/
projectcolumnmanagement.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: Project Column Management
<<<<<<< HEAD
# Ensure that only one workflow runs at a time for a specific reference
=======
>>>>>>> 7db5f14df424c604e8b81c7452bb66e313f3ccae
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch: # Allows manual triggering of the workflow
schedule:
<<<<<<< HEAD
- cron: '1 0 * * *' # Run daily at 00:01 UTC
=======
- cron: '1 0 * * *' # Runs daily at 00:01 UTC
>>>>>>> 7db5f14df424c604e8b81c7452bb66e313f3ccae
jobs:
manage_columns:
name: Manage project columns
runs-on: ubuntu-latest
steps:
- name: Check-out repository
uses: actions/checkout@v4
<<<<<<< HEAD
- name: Set up GitHub CLI
run: sudo apt-get install gh
- name: Create and remove columns
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJECT_NUMBER: 7 # Replace with your actual project number
USERNAME: jcallaghan # Replace with your GitHub username
run: |
# Get the current project ID and columns
gh api graphql -f query='
query($username: String!, $projectNumber: Int!) {
user(login: $username) {
projectV2(number: $projectNumber) {
id
fields(first: 100) {
nodes {
id
name
}
}
}
}
}' -f username=$USERNAME -F projectNumber=$PROJECT_NUMBER > project_data.json
PROJECT_ID=$(jq -r '.data.user.projectV2.id' project_data.json)
# Parse the existing columns
jq -r '.data.user.projectV2.fields.nodes[] | .name' project_data.json > existing_columns.txt
# Define columns to ignore (non-date columns)
echo -e "No Status\nQueue\nPantry" > ignore_columns.txt
# Calculate today's date and generate new column names for the next 14 days
today=$(date +'%a %d-%b %Y')
for i in {1..14}; do
column_date=$(date -d "+$i day" +'%a %d-%b %Y')
echo $column_date >> new_columns.txt
done
# Create new columns if they don't already exist
while IFS= read -r column_date; do
if ! grep -Fxq "$column_date" existing_columns.txt; then
echo "Creating new column: $column_date"
gh api graphql -f query='
mutation($projectId: ID!, $name: String!) {
createProjectV2Field(input: {projectId: $projectId, name: $name}) {
projectV2Field {
id
}
}
}' -f projectId=$PROJECT_ID -f name="$column_date"
fi
done < new_columns.txt
# Remove old date-based columns (older than 5 days)
today_epoch=$(date +%s)
cutoff_epoch=$(date -d "-5 days" +%s)
while IFS= read -r column_name; do
# Skip non-date columns
if grep -Fxq "$column_name" ignore_columns.txt; then
continue
fi
# Parse the date and convert to epoch
column_epoch=$(date -d "$column_name" +%s 2>/dev/null || echo "")
# Remove column if older than the cutoff
if [ "$column_epoch" != "" ] && [ $column_epoch -lt $cutoff_epoch ]; then
echo "Removing old column: $column_name"
column_id=$(jq -r --arg name "$column_name" '.data.user.projectV2.fields.nodes[] | select(.name == $name) | .id' project_data.json)
gh api graphql -f query='
mutation($fieldId: ID!) {
deleteProjectV2Field(input: {fieldId: $fieldId}) {
clientMutationId
}
}' -f fieldId=$column_id
fi
done < existing_columns.txt
=======
- name: Checkout repository
uses: actions/checkout@main
- name: Set up date variables
id: set_dates
run: |
echo "n_days=${{ github.event.inputs.days }}" >> $GITHUB_ENV
for i in $(seq 0 $n_days); do
date_name=$(date -d "+${i} day" +"%a %d-%b-%Y") # Make sure to use correct format
echo "day_$i=$date_name" >> $GITHUB_ENV
done
env:
n_days: 14
- name: Log created dates
run: |
for i in $(seq 0 $n_days); do
date_name=$(eval echo "\$day_$i")
echo "Prepared date: $date_name"
done
- name: Create status options in GitHub Project
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PROJECT_ID: "PVT_kwHOAHGtNM4Am6Y8"
run: |
for i in $(seq 0 $n_days); do
date_name=$(eval echo "\$day_$i")
echo "Creating status option for: $date_name"
graphql_query='mutation {
updateProjectV2Field(
input: {
projectId: "'$PROJECT_ID'"
fieldId: "128914728"
name: "Status"
options: [
{ name: "'$date_name'" }
]
}
) {
projectV2Field {
id
name
options {
name
}
}
}
}'
# Log the GraphQL query
echo "GraphQL query: $graphql_query"
# Make the API call to create the status option
response=$(curl -X POST \
-H "Authorization: bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query":"'"$graphql_query"'"}' \
https://api.github.com/graphql)
# Log the response from the GitHub API
echo "API response: $response"
# Check for errors in the response
if echo "$response" | grep -q '"errors"'; then
echo "Error encountered when creating option for: $date_name"
echo "$response"
else
echo "Successfully created status option for: $date_name"
fi
done
>>>>>>> 7db5f14df424c604e8b81c7452bb66e313f3ccae