API Trigger build of pull request from fork


#1

Hi Circle,

I’m attempting to develop an integration test setup with parameterized builds, where I track the parameters which failed, and then when a new pull request is opened, retry each set of parameters against that pull request.

But I cannot figure out how to trigger a pull request build with the REST api, if I specify a revision which is on my fork, then Circle cannot find it, and there’s no apparent way to tell circle to build a given PR via the REST api.

I think I should be able to specify something like pulls/33 as the revision, or use another parameter to specify I want a specific pull request and let Circle handle it behind the scenes.


Workflow question: Forks + Third Party Services
#2

Are there any updates on this? I’m trying to do something very similar. Everytime I call the API, I get

{
  "message": "Branch not found"
}

However if I change the request to a GET request, then I get a proper response and everything. Is this something that is broken and will be fixed soon or is there a special way to call forked PR’s?


#3

Could you share the script or API call you’re trying to make?


#4

Hey @zzak! Sure no problem at all. Currently trying to call the trigger api. I am sending a POST request to the url

https://circleci.com/api/v1.1/project/github/willowtreeapps/spruce-ios/tree/pull%2F75?circle-token=<token>

The PR is from a forked Pull Request. Let me know if you need anymore information :slight_smile:


#5

Hello @jacksontaylor13,

Does this branch already have a build on CircleCI that you can find in the UI?

I’m unable to find it, which makes me think either the name is wrong, or it was never built.

Best, Zak


#6

Hey @zzak,

Yes it does! If you change that request to a GET request, then you can get the correct response from the API. The tough part is that right now the branch doesn’t exist but I was having the same issues when it did exist. Is there a way that you are supposed to build forked PR requests with the API?

  • Jackson

#7

Hey @zzak,

We just made a test branch that does exist but is not built. You can try it by making the API call below. Still getting the branch not found even though it exists.

https://circleci.com/api/v1.1/project/github/willowtreeapps/spruce-ios/tree/pull/86?circle-token=<token>

For the actual branch, you can see it: https://github.com/willowtreeapps/spruce-ios/pull/86

Hopefully this will help us figure this out :slight_smile:


#8

Hello @jacksontaylor13,

It doesn’t look like that branch was ever pushed to us, so we can’t build branches that we don’t know about.

Does that answer your question?

Best, Zak


#9

Hey @zzak,

Once again thank you for the really prompt replies! What we are trying to achieve is a chat bot that will allow us to build forked pull-requests. Currently we have sensitive information in the CircleCI environment that we don’t want someone to just print out the values or use the server for mining money. If this API allowed us to say build this PR then we could manually review the code real quick and then send a message to say start the build. Is this something possible with CircleCI?

  • Jackson

#10

Sounds like an interesting idea!

I think code review part would likely need to take place with your source code provider, such as GitHub.

Triggering builds for a given branch or revision is certainly within the bounds of CircleCI, however, you probably want to disable “build PR” feature in the project settings so that you can manually issue builds via webhook API.

Best, Zak


#11

Hey @zzak!

So that’s pretty much the exact idea we just don’t know why the API call isn’t working. Currently our CircleCI setup is:

  • Don’t build any forked PRs automatically
  • Build master branch and any PRs from our team

The steps that we want to happen:

  • User forks the Spruce-iOS repo
  • User submits a new PR on the main repo (a forked PR)
  • One of our team members will code review the PR and make sure that there is nothing sneaky or hackery inside of it. This code review will happen on Github so not using CircleCI for this.
  • We will have a running bot that hooks into Github web hooks. Once a team member says hey bot build this ( or something of the sort ) then we will call the CircleCI API
  • CircleCI should then build the PR and submit status reports to Github
  • Based on the response from the build we would then either merge it in or request changes

So right now everything besides the API call to CircleCI is working. Have you gotten a REST API call with the branch we sent you to work? We’ve tried so many options but I must be missing something if it’s working on your end.


#12

@jacksontaylor13 I asked our engineering team if we can trigger a build for a PR branch with that option disabled. In any case, I think we could find out if we just made a dummy project and tested it.

From what you said, I gather the workflow you’re looking for is:

(Non-employee) User opens PR -> Employee reviews PR, says OK -> PR is built -> Status returned to GitHub

This is something that we don’t support, and would require some engineering on your part to make happen, and was my original concern.

Best, Zak


#13

@zzak That is the correct workflow. We are not concerned about the engineering that needs to happen on our end. The only thing we need from CircleCI is the API call to build the PR. Is there an API call that will be able to build a PR from a forked repo? We have setup a test branch located here that we need an API call to build. Does CircleCI have one?

Thanks,
Jackson


#14

I have the same problem. Even with the option for testing external pull requests enabled, it does not accept pull/<number> either as revision or branch.


#15

I’ve moved this to our feature request category so that our Product team can see it.

Please heart the original post if this is something you would like to see as that is how we judge interest and prioritize feature requests.


#16

Fudge this is exactly the feature I require as well :frowning: I’m also comfortable with the engineering side as long the API works but I might be forced to utilize another CI provider to get the integration on fork piece working. Fingers crossed this is coming in soon


#18

i could make the post request
https://circleci.com/api/v1.1/project/github/<name>/<repo>tree/pull/<number>?circle-token=<token>
work by specifying the revision (the commit) in the parameters:

{
	revision: <commit>,
	build_parameters: {}
}

Actually it works with the revision parameter alone, and a post like https://circleci.com/api/v1.1/project/github/<name>/<repo>?circle-token=<token>
but the job i was trying to run fails if i don’t also specify the pull/<number>


#19