Skip to content

πŸ§‘πŸΌβ€πŸ³ Update MealPlanner.ics with new meal events and descriptions #1014

πŸ§‘πŸΌβ€πŸ³ Update MealPlanner.ics with new meal events and descriptions

πŸ§‘πŸΌβ€πŸ³ Update MealPlanner.ics with new meal events and descriptions #1014

name: Project Column Management
<<<<<<< HEAD

Check failure on line 3 in .github/workflows/projectcolumnmanagement.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/projectcolumnmanagement.yml

Invalid workflow file

You have an error in your yaml syntax on line 3
# 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