Update Request Status Label #26419
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Request Status Label | |
on: | |
schedule: | |
# Run every 5 mins | |
- cron: "* * * * *" | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ vars.MORPHOCLOUD_OS_CLOUD }} | |
cancel-in-progress: true | |
permissions: | |
issues: write | |
contents: read | |
jobs: | |
update-request-status-label: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update issues | |
run: | | |
source ~/venv/bin/activate | |
instance_prefix=${PREFIX:+${PREFIX}_} | |
instance_basename="${instance_prefix}instance" | |
openstack server list --name "^${instance_basename}-\d+" -f json | \ | |
jq -r '.[] | [.Name, .Status] | @tsv' | \ | |
while IFS=$'\t' read -r instance_name status; do | |
issue_number=${instance_name##*-} | |
status_lowercase=${status,,} | |
add_label="status:$status_lowercase" | |
remove_labels=$(gh issue view $issue_number --json labels | \ | |
jq \ | |
-r \ | |
--arg add_label "$add_label" \ | |
-c '[.labels[].name | select(test("^status:")?) | select(. != $add_label)] | join(",")') | |
echo "Updating issue $issue_number adding label [$add_label] and removing labels [$remove_labels]" | |
gh issue edit ${issue_number} --add-label "${add_label}" --remove-label "${remove_labels}" | |
done | |
env: | |
OS_CLOUD: ${{ vars.MORPHOCLOUD_OS_CLOUD }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
PREFIX: ${{ vars.INSTANCE_NAME_PREFIX }} |