name: Welcome Discussion

on:
  discussion:
    types: [created]

permissions:
  discussions: write

jobs:
  welcome:
    runs-on: ubuntu-latest
    steps:
      - name: Add welcome comment
        uses: actions/github-script@e69ef5462fd455e02edcaf4dd7708eda96b9eda0 # v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const discussion = context.payload.discussion;
            const author = discussion.user.login;

            const message = [
              `Hi @${author}, thanks for starting this discussion! 👋`,
              '',
              'The Theia community will take a look soon. In the meantime, you might find helpful information in:',
              '- 📖 [Theia Documentation](https://theia-ide.org/docs/)',
              '- ❓ [FAQ](https://theia-ide.org/docs/faq/)',
              '- 💬 [Previous Discussions](https://github.com/eclipse-theia/theia/discussions)',
              '',
              '---',
              '',
              '💙 Eclipse Theia is built and maintained by a community of contributors and sponsors. ' +
              'If Theia is valuable to your work, consider [sponsoring the project](https://theia-ide.org/support/). ' +
              'For professional support, training, or consulting services, [learn more about available options](https://theia-ide.org/support/).'
            ].join('\n');

            await github.graphql(`
              mutation($discussionId: ID!, $body: String!) {
                addDiscussionComment(input: {discussionId: $discussionId, body: $body}) {
                  clientMutationId
                }
              }
            `, {
              discussionId: discussion.node_id,
              body: message
            });
