Imagine you found a recipe you would like to run as part of your organization's automation process (such as updating the Gradle plugin version when a new release is published). Rather than manually running this recipe each time, you can use Moderne's GraphQL API to speed this process up with automation.
To help you understand how to automate recipe execution and commits, we'll walk through all the steps necessary to use Moderne's GraphQL API. By the end, you should know how to:
To begin, you'll want to decide what repositories you want your recipe to run on. You have three options for selecting repositories: choosing an existing organization, creating a new user-defined organization, or selecting an existing user-defined organization. Once you've selected or created one, you can proceed to step 2.
Navigate to the recipe you wish to run and fill out the recipe options.
In the top right corner of the page, click on API examples and select Run a recipe. This will provide you with the query that will be run when executing a recipe run. Additionally, the appropriate variables will be added to this query based on your organization selection from step 1.
You can then execute a recipe with the following mutation:
mutationrunRecipe($input: RecipeRunInput!) { runRecipe(run: $input) { id __typename }}
The mutation will return a response that contains the id of the recipe run which will be used in the next step to poll for the completion of the recipe. Example response:
{"data": {"runRecipe": {"id": "5LPSt" } }}
Verify recipe completion
You will now need to poll (Moderne's web interface uses a 3-second interval) with the query shown below using the id from the recipe execution mutation.
queryrunRecipeName($id: ID!) { recipeRun(id: $id) { recipe { id name } state }}
Next, we will perform the pullRequest mutation to create a pull request with our changes. We will be using theid from recipe execution and the response from the previous step to construct the mutation variables for committing a pull request. See the mutation variables tab below.
Using the id returned from the pull request mutation we can then poll for the completion of the commit job. When the response is returned with the completed property equal to the commits.count property the job has been completed. The summaryResults property will contain the count of success, failure, and no changes commit jobs. Detailed statuses are found on the commits property. This is a paginated query so you may need to loop through multiple pages if you wish to see detailed results for each commit.