jenkinsci / pipeline-github-plugin

Pipeline: GitHub
https://plugins.jenkins.io/pipeline-github/
MIT License
159 stars 73 forks source link

isMergeable always returning true #61

Open borisivan opened 5 years ago

borisivan commented 5 years ago

in a PR I have a pending status check. and the repo settings have branch protection with the setting: "Require status checks to pass before merging", and the status check in question is listed.

I have a test with the following code:

   def isMergeable = false
   isMergeable = pullRequest.mergeable
   echo "mergeability: ${isMergeable} should be false..."
   sleep (5)
   isMergeable = pullRequest.mergeable
   echo "mergeability: ${isMergeable} should be false..."
   sleep (5)
   pullRequest.createStatus(status: 'success', context: 'pr examination', description: 'examination successful', targetUrl: "${env.JOB_URL}")
   isMergeable = pullRequest.mergeable
   echo "mergeability: ${isMergeable} true if change immediate... since I just set the status as success immediately prior"
   sleep (5)
   isMergeable = pullRequest.mergeable
   echo "mergeability: ${isMergeable} after 5 second delay since setting, really should be true here..."

.... yet it's always 'true'. I even made sure the repo settings had the configuration for "Enforce all configured restrictions for administrators."

I had a window up to the github UI that I was refreshing after I made a small change to the branch and pushed to github. The PR instantly went to having they merge button greyed out as soon as it received the push, and stayed grey as I spammed the refresh button on my browser, and immediately went to mergeable (in the UI) only when the createStatus command was executed in the code above.

But pullRequest.mergeable appears to always be true, even though the github UI is saying that the PR is not mergeable until I set that statusCheck to success. Any ideas?

borisivan commented 5 years ago

learning more about how this works -- I suspect that this only takes into consideration if there is a git conflict. But if anything that prevents a PR from being merged (reviewers, required status checks, etc) are currently active for a PR.... isMergeable is still true.

Would love to see a solution somehow to really know "is it mergeable".

LaszloAshin commented 2 months ago

Have you tried calling pullRequest.refresh() before rechecking the flag? Solely reading the flag doesn't trigger querying the API.