Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it run in every new commit from tina-cloud-app[bot] #2

Open
BrunoSette opened this issue Jul 21, 2023 · 1 comment
Open

Comments

@BrunoSette
Copy link

I'm trying to run this github action in every new .md file created by tina-cloud-app[bot].

My actual code is:

name: Content Suggestion

on:
  push:
    branches:
      - 'main'
    paths:
      - '**.md'

jobs:
  make-suggestion:
    if: github.actor == 'tina-cloud-app[bot]'
    name: "Make Suggestion"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: tinacms/ai-content@v0
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

      - name: Create Pull Request
        id: create-pr
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "Automatic PR from ChatGPT"
          title: "Automatic PR from ChatGPT"
          body: "A new pull request has been created from ChatGPT"
          branch: "bot-auto-pr-${{ github.run_number }}"

      - name: Get list of changed files
        id: files
        run: |
          echo "files=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }})" >> $GITHUB_ENV
        shell: bash

      - name: Comment on PR
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const url = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_REF}/`
            const changedFiles = process.env.files.split('\n')
            const markdownFiles = changedFiles.filter(file => file.endsWith('.md'))
            let commentBody = ''
            for (const mdFile of markdownFiles) {
                commentBody += `- [ai fix: ${url}${mdFile}](${url}${mdFile})\n`
            }
            await github.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: ${{ steps.create-pr.outputs.pull-request-number }},
              body: commentBody
            })

But it doesn't work because I can't create a PR without changing any file in the branch.

Can I make the tinacms/ai-content@v0 run in every commit without a PR ?

@jamespohalloran
Copy link
Contributor

The bot's designed as-is to run on PRs (for the commenting to work).
TinaCMS does support a PR-based workflow (although it's currently a business plan feature: https://tina.io/docs/drafts/editorial-workflow/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants