File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -518,13 +518,45 @@ create_test_discussion() {
518518 local body=" $2 "
519519 local category=" ${3:- General} "
520520
521- # Create discussion using GitHub API since gh CLI might not support discussions create
522- local discussion_data=$( gh api repos/:owner/:repo/discussions \
523- --method POST \
524- --field title=" $title " \
525- --field body=" $body " \
526- --field category_id=" $( gh api repos/:owner/:repo/discussions/categories --jq ' .[] | select(.name=="' $category ' ") | .id' ) " \
527- 2> /dev/null | jq -r ' .number // empty' 2> /dev/null)
521+ # Get repository ID and category ID using GraphQL
522+ local repo_id=$( gh api graphql -f query='
523+ {
524+ repository(owner: "' $REPO_OWNER ' ", name: "' $REPO_NAME ' ") {
525+ id
526+ }
527+ }' --jq ' .data.repository.id' 2> /dev/null)
528+
529+ local category_id=$( gh api graphql -f query='
530+ {
531+ repository(owner: "' $REPO_OWNER ' ", name: "' $REPO_NAME ' ") {
532+ discussionCategories(first: 10) {
533+ nodes {
534+ id
535+ name
536+ }
537+ }
538+ }
539+ }' --jq ' .data.repository.discussionCategories.nodes[] | select(.name=="' $category ' ") | .id' 2> /dev/null)
540+
541+ if [[ -z " $repo_id " || -z " $category_id " ]]; then
542+ echo " "
543+ return
544+ fi
545+
546+ # Create discussion using GraphQL mutation
547+ local discussion_data=$( gh api graphql -f query='
548+ mutation {
549+ createDiscussion(input: {
550+ repositoryId: "' $repo_id ' "
551+ categoryId: "' $category_id ' "
552+ title: "' $title ' "
553+ body: "' $body ' "
554+ }) {
555+ discussion {
556+ number
557+ }
558+ }
559+ }' --jq ' .data.createDiscussion.discussion.number // empty' 2> /dev/null)
528560
529561 if [[ -n " $discussion_data " ]]; then
530562 echo " $discussion_data "
You can’t perform that action at this time.
0 commit comments