Skip to content

Commit

Permalink
Automatically link issue to milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
ivvist committed Sep 22, 2023
1 parent a4aa4fd commit 2546a8e
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions scripts/linkmilestone.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/bin/bash
#!/bin/bash

isNext( ) {
# Convert the input date string to a Unix timestamp
date_string="${1//./-}"
input_date=$(date -d "$date_string" +"%s")
# Get the current date in Unix timestamp format
current_date=$(date +"%s")
res=0
if [ $input_date -gt $current_date ]; then
res=1
fi
echo $res
}
# Get milestone list
rawmilestones=$(gh api repos/${repo}/milestones --jq '.[] | .title')
# Make arrays from milestones string
readarray -t milestones <<< "$rawmilestones"
l=${#milestones[@]}
# Link to milestone is possible if only 1 Milestone exists
if [ $l -eq 1 ]; then
rawml=${milestones[0]}
ml="${rawml// /}"
if [ -z "$ml" ]; then
gh issue reopen ${issue} --repo ${repo}
echo "::error::No open milestones found"
exit 1
fi
gh issue edit ${issue} --milestone ${ml} --repo ${repo}
else
gh issue reopen ${issue} --repo ${repo}
if [ $l -eq 0 ]; then
echo "::error::No open milestones found"
fi
if [ $l -gt 1 ]; then
echo "::error::More than one open milestone found."
fi
exit 1
fi

# Get milestone list
milestones=$(gh api repos/${repo}/milestones --jq '.[] | .title')
for milestone in $milestones; do
ml=$milestone
hasfound=$(isNext "$ml")
if [ "$hasfound" -eq 1 ]; then
gh issue edit ${issue} --milestone ${milestone} --repo ${repo}
exit 0
fi
done

0 comments on commit 2546a8e

Please sign in to comment.