Update VERSION (#244) #214
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: Check CodeBundle Discussions | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check-discussions-on-main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.ref }} | |
- name: Check if codebundle discussion exists | |
id: find_and_create_codebundle_discussions | |
run: | | |
codebundles=$(find codebundles -maxdepth 1 -type d -exec basename {} \; | grep -v "codebundles") | |
echo "Found codebundles: $codebundles" | |
echo "Searching discussions..." | |
# Read the queries from separate files | |
search_discussions_query=$(cat .github/queries/searchDiscussions.graphql | tr -d '\n' | sed 's/"/\\\"/g') | |
create_discussion_query=$(cat .github/queries/createDiscussion.graphql | tr -d '\n' | sed 's/"/\\\"/g') | |
add_comment_query=$(cat .github/queries/addDiscussionComment.graphql | tr -d '\n' | sed 's/"/\\\"/g') | |
get_comments_query=$(cat .github/queries/getComments.graphql | tr -d '\n' | sed 's/"/\\\"/g') | |
# Temp for cleanup of messes | |
delete=false | |
delete_discusssion_query=$(cat .github/queries/deleteDiscussion.graphql | tr -d '\n' | sed 's/"/\\\"/g') | |
# codebundles=test | |
# Perform the searchDiscussions query | |
search_response=$(curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Content-Type: application/json" -X POST -d "{\"query\": \"$search_discussions_query\", \"variables\": {\"searchQuery\": \"org:runwhen-contrib\"}}" https://api.github.com/graphql) | |
discussion_nodes=$(echo "$search_response" | jq -r '[.data.search.edges[].node.discussions.nodes[] | select(.title != null) | { id, title }] | { items: . }') | |
declare -A found_map | |
for codebundle in $codebundles; do | |
found=false | |
while IFS= read -r discussion_node; do | |
node_codebundle=$(jq -r '.title' <<< "$discussion_node") | |
discussion_id=$(jq -r '.id' <<< "$discussion_node") | |
if [[ "$codebundle" == "$node_codebundle" ]]; then | |
found=true | |
echo "Discussion found for $codebundle with ID: $discussion_id" | |
if [[ "$delete" == "true" ]]; then | |
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Content-Type: application/json" -X POST -d "{\"query\": \"$delete_discusssion_query\", \"variables\": {\"discussion_id\": \"$discussion_id\" }}" https://api.github.com/graphql | |
fi | |
break | |
fi | |
done < <(jq -c '.items[]' <<< "$discussion_nodes") | |
found_map["$codebundle"]=$found | |
done | |
# Process the found_map after the loop | |
for codebundle in $codebundles; do | |
found=${found_map["$codebundle"]} | |
if [[ "$delete" != "true" ]] && ! $found ; then | |
echo "No matching discussion found for $codebundle" | |
echo "Creating new discussion for $codebundle" | |
discussion_title=$codebundle | |
# Troubleshooting Commands Category | |
category_id="DIC_kwDOJo2Id84CXeeV" | |
# The repository_id that we need to use | |
repo_id="R_kgDOJo2Idw" | |
discussion_body="🌟Welcome to the community discussion for the troubleshooting commands defined in: [$codebundle](https://github.com/runwhen-contrib/rw-cli-codecollection/tree/main/codebundles/$codebundle) \n\n🌱This discussion is intended to help grow the community\n🛠️Together, let's enhance the usefulness of these troubleshooting commands\n🙌 Your participation is crucial! Share your valuable comments and questions here, and don't forget to give a thumbs up if you find the commands helpful and utilize them in your work." | |
curl -s -H "Authorization: Bearer $GH_TOKEN" -H "Content-Type: application/json" -X POST -d "{\"query\": \"$create_discussion_query\", \"variables\": {\"repo_id\": \"$repo_id\", \"codebundle\": \"$codebundle\",\"discussion_body\": \"$discussion_body\", \"category_id\": \"$category_id\"}}" https://api.github.com/graphql | |
fi | |
done | |
env: | |
GH_TOKEN: ${{ secrets.PAT }} |