Github Actions custom deployment protection rule approval not working #144720
-
Select Topic AreaBug BodyHello, I'm following the documentation here for creating a webhook server that will handle approvals/rejections of deployments in an environment. I have my code in this gist. It's very messy I'm just trying to get a basic POC running locally using ngrok. I'm stuck on actually making the approval. It's failing on the POST request to
This is for a private repo, but we have Github Enterprise so according to the docs here we should have access to all the forms of protection rules on our private repos. It seems like the whole flow works even though the repos are private. The webhook is firing the way I expect, I just can't figure out why this last part is failing. I'm suspecting it might be a permissions issue due to a discrepancy between the docs (which are probably geared towards public repositories) and my private repo. I see the following permissions on my installation token:
I see that the installation token is being granted access to the right repository. I'm thinking maybe there's a missing permission so when the request is made, it can't see the protection rule even though I can see it in the UI. UPDATE I ported over the code to JavaScript seeing as how this webhook would be implemented in a NextJS app anyways. I have everything set up and I'm getting the same error. This is the webhook code:
This is the error object getting logged:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
-
I was able to figure this out with the help of Github Support. According to the docs for creating an environment, the environment name isn't case sensitive. However, it seems like when passing the environment name in the HTTP request, the environment name is case sensitive. The working code looks like this: interface WebhookPayload {
deployment_callback_url: string;
environment: string;
deployment: {
environment: string;
};
installation: {
id: number;
};
repository: {
id: number;
name: string;
owner: {
login: string;
};
};
}
export const POST = async (request: NextRequest): Promise<NextResponse> => {
// TODO: verify header with HMAC(buf, secretToken)
const payload: WebhookPayload = await request.json();
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: client_id,
privateKey: jwt_signing_key,
installationId: payload.installation.id,
},
});
await appOctokit.request({
url: payload.deployment_callback_url,
method: "POST",
// Even though environment names aren't case-sensitive according to the docs,
// they are case sensitive when being used here. This field has the environment
// name in the correct case.
environment_name: payload.environment,
// TODO: get this from the database
state: "approved",
});
return new NextResponse(null, { status: 200 });
}; |
Beta Was this translation helpful? Give feedback.
I was able to figure this out with the help of Github Support.
According to the docs for creating an environment, the environment name isn't case sensitive. However, it seems like when passing the environment name in the HTTP request, the environment name is case sensitive.
The working code looks like this: