@@ -148,71 +148,82 @@ jobs:
148148 ls -l exec || echo "Nothing in exec/"
149149 echo "MADATE=$(date '+%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
150150
151- - name : Create a new GitHub Discussion Annoucement
152- id : create-discussion
153- uses : abirismyname/create-discussion@v2.1.0
154- env :
155- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
156- with :
157- title : Test Dicussion adding at ${{ env.MADATE }}
158- body : |
159- Test new message at ${{ env.MADATE }}
160- repository-id : ${{ secrets.DISCUSSION_REPO_ID }}
161- category-id : ${{ secrets.DISCUSSION_CAT_ID }}
162-
163- # - uses: octokit/request-action@v3.x
164- # id: close_branch_qa
151+ # - name: Create a new GitHub Discussion Annoucement
152+ # id: create-discussion
153+ # uses: abirismyname/create-discussion@v2.1.0
165154 # env:
166- # GITHUB_TOKEN: ${{ env.SERVBOT_PAT }}
167- # REQUEST_BODY: "['${{ env.TEAM_RESTRICTIVE_CLOSED_BRANCH}}']"
155+ # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168156 # with:
169- # route: PUT /repos/${{ github.repository }}/branches/main/protection/restrictions/teams
170- # data: ${{ env.REQUEST_BODY }}
157+ # title: Test Dicussion adding at ${{ env.MADATE }}
158+ # body: |
159+ # Test new message at ${{ env.MADATE }}
160+ # repository-id: ${{ secrets.DISCUSSION_REPO_ID }}
161+ # category-id: ${{ secrets.DISCUSSION_CAT_ID }}
162+
163+ - uses : octokit/request-action@v3.x
164+ id : close_branch_qa
165+ env :
166+ GITHUB_TOKEN : ${{ env.SERVBOT_PAT }}
167+ REQUEST_BODY : " ['${{ env.TEAM_RESTRICTIVE_CLOSED_BRANCH}}']"
168+ with :
169+ route : PUT /repos/${{ github.repository }}/branches/main/protection/restrictions/teams
170+ data : ${{ env.REQUEST_BODY }}
171171
172172 - name : Create GitHub Discussion
173173 uses : actions/github-script@v8
174174 with :
175175 github-token : ${{ secrets.GITHUB_TOKEN }}
176176 script : |
177- const { title, body, category } = github.context.payload.inputs;
178-
179177 // Get the discussion categories for your repository
180- const { repository } = await github.graphql(`
178+ const { data: repository } = await github.rest.repos.get({
179+ owner: context.repo.owner,
180+ repo: context.repo.repo
181+ });
182+
183+ // Create discussion using GraphQL
184+ const query = `
181185 query {
182- repository(owner: "${github.repo.owner}", name: "${github.repo.repo}") {
183- discussionCategories(first: 100) {
186+ repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
187+ id
188+ discussionCategories(first: 10) {
184189 nodes {
185190 id
186191 name
187192 }
188193 }
189194 }
190195 }
191- `) ;
192-
193- const discussionCategories = repository.discussionCategories.nodes ;
194- const targetCategory = discussionCategories.find(cat => cat.name === category) ;
195-
196- if (!targetCategory) {
197- core.setFailed(`Discussion category '${ category}' not found.`);
198- return ;
199- }
200-
201- // Create the discussion
202- const { createDiscussion } = await github.graphql(`
203- mutation CreateDiscussion($ repositoryId: ID!, $ categoryId: ID!, $ title: String!, $ body: String! ) {
204- createDiscussion(input: {repositoryId: $repositoryId, categoryId: $categoryId, title: $title, body: $body}) {
205- discussion {
206- url
196+ `;
197+
198+ const result = await github.graphql(query) ;
199+ const repoId = result.repository.id ;
200+ const categories = result.repository.discussionCategories.nodes;
201+
202+ // Use first available category or create with a default
203+ const categoryId = categories.length > 0 ? categories[0].id : null ;
204+
205+ if (categoryId) {
206+ const createMutation = `
207+ mutation CreateDiscussion($repositoryId: ID!, $categoryId: ID!, $title: String!, $body: String!) {
208+ createDiscussion(input: { repositoryId: $repositoryId, categoryId: $categoryId, title: $title, body: $body} ) {
209+ discussion {
210+ url
211+ }
207212 }
208213 }
209- }
210- `, {
211- repositoryId: github.context.payload.repository.node_id,
212- categoryId: targetCategory.id,
213- title: `Title of discussion created at ${{ env.MADATE }}`,
214- body: `This is the body of the discussion created at ${{ env.MADATE }}`
215- });
214+ `;
215+
216+ const discussion = await github.graphql(createMutation, {
217+ repositoryId: repoId,
218+ categoryId: categoryId,
219+ title: `Test Discussion adding at ${{ env.MADATE }}`,
220+ body: `Test new message at ${{ env.MADATE }}`
221+ });
222+
223+ console.log(`Discussion created: ${discussion.createDiscussion.discussion.url}`);
224+ } else {
225+ console.log('No discussion categories found. Please create discussion categories first.');
226+ }
216227
217228 # build_linux:
218229 # if: ${{ github.repository_owner == 'OpenRadioss' }}
0 commit comments