Checking if pull request is assigned to a project

Hello,

We currently use github projects to track a which version of our software a pull request should go in. To facilitate this, I want to build a check to that fails when a pull request is not assigned to a project.

I have an action that triggers a script when a pull request is created, with the simple: 

on: pull\_request 

However, this action should also run when a PR is added to a project after the PR is already opened.

I tried with the

added_to_project

event described here https://developer.github.com/v3/issues/events/, but I cannot get this to work. Is it even possible to do what I want?

Hi @djurre , 

Added_to_project event type of issue is not an “Activity types” for Issue event and Pull_request event which could trigger a workflow. 

There is an API to show issue events, you could try to loop the events of the issue , then fail the workflow if no “added_to_project” event in the response. 

Hey @yanjingzhu,

Thanks for the reply! Unfortunately I don’t think that would work, because the problem is that I need a trigger to do that check. So when a PR is open and you add a project, there is nothing to trigger my action to then get the issue events. 

I guess the only way to do what I want properly is with webhooks then. Back to the drawing board!

Hi @djurre , There is an event named : "project_card " . When you add a project to PR and triage it to a column, then project_card event created. 

You could use next code snippet in your workflow yml:  

on:
  pull_request:
     type: [opened]
  project_card:
     type: [created]

That indeed would give the event, but is it then possible to link that back to the PR check?

So you have a PR which runs the check on “pull_request opened”. This fails because there is no project attached. You then create a project card and get the “project_card created” event. Is there a way to use this event to update the check on the PR so that it passes again?

I am sorry to tell you that there is no way to update the check on a PR when workflow is triggered on “project_card created” event. I would encourage you to submit a feature request asking for a new type (added_to_project) of pull_request event in the Feedback form for GitHub Actions. .

I will do that, thanks for thinking along!