GithubHelp home page GithubHelp logo

Comments (8)

peter-evans avatar peter-evans commented on May 21, 2024 2

Hi @qdm12

The issue is that pull_request events checkout a merge commit. If you want to raise a pull request to merge into an existing pull request you need to checkout the head_ref. See the documentation here:
https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#pull-request-events

Also, push should only run on master so that you aren't creating two PRs for pull request branches.

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

When using branch-suffix: timestamp, you might end up with a lot of PRs created if your repo has a lot of activity. It can be a bit awkward to use this action well on pull_request events. Personally, I would avoid if possible and just make the solution simpler by running on push to master only. That way you can use the fixed-branch strategy easier.

name: Misspells
on:
  push:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos

from create-pull-request.

peter-evans avatar peter-evans commented on May 21, 2024 1

If you want to perform operations on PRs (like correcting typos, formatting) I recommend using a slash command instead of raising another PR to merge into the PR branch. See slash-command-dispatch, and in particular, the ChatOps in Pull Requests demo.

from create-pull-request.

peter-evans avatar peter-evans commented on May 21, 2024 1

Apparently, this will work for both local PRs and PRs from forks. I will update the docs to this snippet instead of the one I mentioned above.

- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }}

from create-pull-request.

qdm12 avatar qdm12 commented on May 21, 2024

Thanks so much for the detailed help!

I'll stick with the PR approach for now (not too much activity yet / not too much spelling mistakes 😆 ), although your other slash command action is quite exciting as well.

Have a great weekend!!

from create-pull-request.

qdm12 avatar qdm12 commented on May 21, 2024

Hi again,

Actually would you know the checkout step so that it would work for PR from forked repositories? In my case it's this log I obtain, using this workflow file - almost the same as yours I think.

Thank you so much 👍

from create-pull-request.

qdm12 avatar qdm12 commented on May 21, 2024

Actually using this format gives the same error as before 😢 (log), workflow was:

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: reviewdog fixer
        uses: reviewdog/action-misspell@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          locale: "US"
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

from create-pull-request.

peter-evans avatar peter-evans commented on May 21, 2024

Sorry @qdm12. I didn't think about this long enough before I replied with this comment. I've tried a lot of this in the past and essentially gave up. Basically, what you are trying to do is not possible with PRs from forks (or the workaround is so complicated it's undesirable). The PR branch lives in the fork. Most likely you have no access to the fork. So when you think about it, what is this workflow trying to do? You want to create a pull request in the fork to update the PR branch? The only way you could do that is if you have write access to the fork, or, you create a fork of the fork and raise a PR back to update it.

So one option would be to only run on pull_request events when the PR is local and not from a fork. This would still check when the fork PRs are merged to master.

name: Misspells
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  misspell:
+   # Check if the PR is not from a fork
+   if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    steps:
      - name: Checkout on push
        if: github.event_name == 'push'
        uses: actions/checkout@v2
      - name: Checkout on pull_request
        if: github.event_name == 'pull_request'
        uses: actions/checkout@v2
        with:
-         ref: ${{ github.event.pull_request.head.sha }}
+         ref: ${{ github.head_ref }}
      - name: reviewdog fixer
        uses: reviewdog/action-misspell@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          locale: "US"
      - name: sobolevn fixer
        uses: sobolevn/misspell-fixer-action@master
      - uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: 'Typos fixes'
          title: "Typos fixes"
          branch: typos
          branch-suffix: timestamp

As I mentioned previously, if you really want a solution to check/fix both local and fork PRs I suggest to use slash-command-dispatch.

from create-pull-request.

peter-evans avatar peter-evans commented on May 21, 2024

@qdm12 Hope you managed to find a setup that works well for you. Closing this issue for now.

from create-pull-request.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.