diff --git a/.github/workflows/agenda.yaml b/.github/workflows/agenda.yaml index b943b9e..9389510 100644 --- a/.github/workflows/agenda.yaml +++ b/.github/workflows/agenda.yaml @@ -11,6 +11,9 @@ jobs: permissions: discussions: write runs-on: ubuntu-22.04 + env: + CATEGORY_ID: 'DIC_kwDOFXMeLs4COVB8' + REPOSITORY_ID: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI=' steps: - uses: actions/checkout@v5 - name: Check if it's an alternate week @@ -39,24 +42,55 @@ jobs: run: | NEXT_MEETING_DATE=$(date -d "next Tuesday" +%Y-%m-%d) echo "NEXT_MEETING_DATE=$NEXT_MEETING_DATE" >> $GITHUB_ENV - - name: Create discussion with agenda + - name: Define discussion title + if: steps.check-week.outputs.should_run == 'true' + id: define-title + run: | + DISCUSSION_TITLE="Overlays Meeting (${{ env.NEXT_MEETING_DATE }})" + echo "DISCUSSION_TITLE=$DISCUSSION_TITLE" >> $GITHUB_ENV + - name: Search for existing discussion if: steps.check-week.outputs.should_run == 'true' + id: search-discussion + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + FOUND_DISCUSSION_TITLE=$(gh api graphql -f query=' + query SearchDiscussionMutation ($repositoryOwner: String!, $repositoryName: String!, $categoryId: ID!) { + repository(owner: $repositoryOwner, name: $repositoryName) { + discussions(first: 1, orderBy: {direction: DESC, field: CREATED_AT}, categoryId: $categoryId) { + nodes { + title + } + } + } + }' \ + -f repositoryOwner="${{ github.repository_owner }}" \ + -f repositoryName="${{ github.event.repository.name }}" \ + -f categoryId="${{ env.CATEGORY_ID }}" \ + --jq '.data.repository.discussions.nodes[0].title') + if [ "$FOUND_DISCUSSION_TITLE" = "${{ env.DISCUSSION_TITLE }}" ]; then + DISCUSSION_COUNT=1 + else + DISCUSSION_COUNT=0 + fi + echo "DISCUSSION_COUNT=$DISCUSSION_COUNT" >> $GITHUB_OUTPUT + echo "Found $DISCUSSION_COUNT existing discussions" + - name: Create discussion with agenda + if: steps.check-week.outputs.should_run == 'true' && steps.search-discussion.outputs.DISCUSSION_COUNT == '0' id: create-repository-discussion - uses: octokit/graphql-action@v2.x env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - variables: | - body: "${{ env.AGENDA }}" - title: "Overlays Meeting (${{ env.NEXT_MEETING_DATE }})" - repositoryId: 'MDEwOlJlcG9zaXRvcnkzNTk4NjU5MDI=' - categoryId: 'DIC_kwDOFXMeLs4COVB8' - query: | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api graphql -f query=' mutation CreateDiscussionMutation ($title: String!, $body: String!, $repositoryId: ID!, $categoryId: ID!) { createDiscussion(input: { title: $title, body: $body, repositoryId: $repositoryId, categoryId: $categoryId }) { discussion { title + url } } - } - + }' \ + -f title="${{ env.DISCUSSION_TITLE }}" \ + -f body="${{ env.AGENDA }}" \ + -f repositoryId="${{ env.REPOSITORY_ID }}" \ + -f categoryId="${{ env.CATEGORY_ID }}"