gagoar / use-herald-action

GitHub action to add reviewers, subscribers, labels, and assignees to your PR. You can validate your PR template as well.
https://gagoar.github.io/use-herald-action/
MIT License
53 stars 7 forks source link

eventJsonPath validations do not work #520

Closed toreilly718 closed 2 years ago

toreilly718 commented 2 years ago

After having some issues with this in my own workflow- I traced it back to see if the eventJsonPath filters worked here, and found that it wasn't.

Example PR: https://github.com/gagoar/use-herald-action/pull/519 Rule: https://github.com/gagoar/use-herald-action/blob/master/herald_rules/validate_issue_is_present.json

I think the issue is happening here : https://github.com/gagoar/use-herald-action/blob/master/src/rules.ts#L167

I am not a javascript expert but I did some debugging

var prJSON = require('./pr.json')

  var jp = require('jsonpath');

  var nodes = jp.apply(prJSON, '$..body', function(value) { return value.match('Please') });

  if (nodes.length){
      console.log('Something was returned')
  }
  console.log(nodes)

It seemed like using the apply method instead of query returned the expected result.

gagoar commented 2 years ago

Hey @toreilly718 ! Thanks for opening the issue. I will take a look asap.

cyamonide commented 2 years ago

Hey @toreilly718, Gago's sidekick here.

I looked into PR #519 (the one you linked), and it is actually working correctly. The rule will pass if either:

  1. the text Issue Reference: isn't present at all in the PR description
  2. Issue Reference: is present, followed by an issue number or some other text

So, #519's "valid issue present" rule passes because (1) is satisfied. On the other hand, see #521, which has Issue Reference: present, but it is not followed by an issue number or some other text. Note that the "valid issue present" rule fails for that PR.


I'd suggest you maybe double-check your workflow's JsonPath expression, since they can get really hairy :P

Or, if you can show us how to reproduce your issue, we can help debug your expression and/or use-herald-action's JsonPath rule matcher.

gagoar commented 2 years ago

Closing this because inactivity + it seems to be a user issue more than the lib. Happy to open this up again cc @toreilly718 !