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

Replace baseRefName with headRefName #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tannerhallman
Copy link

@tannerhallman tannerhallman commented Mar 7, 2023

Thanks for your work on this GH Action - Its going to be great for visibility for my team. I tried using the action with this setup:

name: 'PR Conflicts'
on:
  # So that PRs touching the same files as the push are updated
  push:
  # So that the `dirtyLabel` is removed if conflicts are resolve
  # We recommend `pull_request_target` so that github secrets are available.
  # In `pull_request` we wouldn't be able to change labels of fork PRs
  pull_request_target:
    types: [synchronize]

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - name: Check if PRs have conflicts
        uses: eps1lon/actions-label-merge-conflict@v2.0.0
        with:
          dirtyLabel: 'PR: Has Conflicts'
          removeOnDirtyLabel: 'PR: Confirmed No Conflicts'
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          commentOnDirty: 'This pull request has conflicts, please resolve those before we can evaluate the pull request.'
          commentOnClean: 'Conflicts have been resolved. A maintainer will review the pull request shortly.'

However, it wasn't working at all. Using the debug logs, it was returning an empty array response for the query. I used the Github graphql explorer to debug.

What I ended up finding is that the getBranchName query used to populate the baseRefName in the query was seemingly the issue.

baseRefName for my case when I have a PR branched off of dev (long standing environment branch - similar to main/master), the baseRefName of that PR would actually be dev. headRefName in my findings actually was the branch name. It seems that the intention of the query, based on the function name getBranchName, was to filter the query by the actual branch name (headRefName) not the baseRefNamewhich seems to the be branch name that this PR is branched off.

So when I changed the query, my results returned the PR I expected, and thus the gh action was successful.

Here's some screenshots to back it up:

(before my work)

Screenshot showing the baseRefName as printed by the action debug logs:
chore change repos · coworksappcoworks-web@1cd77ca 2023-03-07 11-06-48
chore change repos · coworksappcoworks-web@1cd77ca 2023-03-07 11-13-19(1)

Screenshot of using that in the query, as your action uses. Notice the empty results:
Explorer - GitHub Docs 2023-03-07 11-06-27(1)

(After my work)

Screenshot of using the query filter headRefName instead:
Explorer - GitHub Docs 2023-03-07 11-06-12(1)

Screenshot of gh actions response logs with this change:
chore change repos · coworksappcoworks-web@1cd77ca 2023-03-07 11-14-10

Proof of it working!
feat added gh action that labels PR when conflicts by tannerhallman · Pull Request #487 · coworksappcoworks-web 2023-03-07 11-14-35

As it seems, there was a mixup in the baseRefName and headRefName var. Please let me know if you have any questions!

Anyone reading can use my version of the gh action until this PR is merged. I will keep it up!
tannerhallman/actions-label-merge-conflict@main

Copy link
Owner

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share a repo or order of events that you think is bugged? I don't think what you're proposing is what I originally wanted to do with this action

baseRefName,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
headRefName,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query is for getting all PRs targetting the same branch. But head is the branch of the PR, no? I want the common base of the branches.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseRefName is dev in my case, the "head" that all my PRs are branched off of. headRefName is actually the branch of the PR. You can see that here:

chore change repos · coworksappcoworks-web@1cd77ca 2023-03-07 11-14-10(1)(1)

Repo from my screenshots & testing is a private one. I can try to set you up with a public one.

But what I can tell you is that by merging the branch with the new action into dev, and pushing code to dev, the action was triggered on all PRs that were based off of dev and thus have been labeled. And I did check each to confirm there actually are conflicts.

image

Was this your intended behavior?

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

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

Successfully merging this pull request may close these issues.

None yet

2 participants