I’m attempting to create a Deployment badge on a Merge Request, similar to the Github feature.
To reproduce
- I’m listening for a Merge Request webhook
- I use gitbeaker to create an environment
projectId
- the project usedenvironmentName
-{internalSlug}-{branch}
externalUrl
- URL of the MR previewtier
- I’ve attempted to set this to nothing,production
,staging
anddevelopment
.
- I use gitbeaker to create the deployment
projectId
- same as beforeenvironmentName
- same as beforebranchSha
- from MR webhookbranchName
- from. MR webhooktag
-false
(there’s an active issue with gitbeaker)status
-success
Debugging
- I can confirm the environment exists
- I can confirm it points to the correct sha and branch
- It does NOT show up on the Merge Request
Additional Information
I think this is related to this line of code.
Code
Here’s an example I was able to extract that shows how I attempted to create this. I can remove gitbeaker and use fetch
if that’s useful, but I think this communicates the issue well.
Here is the local-baylee-test-4 environment this created.
import { Gitlab } from '@gitbeaker/rest';
import Cryptr from 'cryptr';
const environmentName = 'local-baylee-test-4';
const projectId = 60797798;
const branchSha = 'bab448c854d04a1ce13d5b302ef548c025986dbd';
const branchName = 'lab-1';
const externalUrl = 'https://mintlify.com/?princess=wiggles';
const encryptedToken = '';
export const cryptr = new Cryptr(process.env.ENCRYPTION_PASSWORD);
const beaker = new Gitlab({
host: 'https://gitlab.com',
token: cryptr.decrypt(encryptedToken),
});
async function findMRs(deploymentId) {
const mrs = await beaker.Deployments.allMergeRequests(projectId, deploymentId);
console.log(mrs);
return mrs;
}
async function createGitlabEnvironment() {
const environment = await beaker.Environments.create(projectId, environmentName, {
externalUrl,
});
console.log({environment});
return environment;
}
async function createGitlabDeployment(environment) {
const deployment = await beaker.Deployments.create(
projectId,
environment.name,
branchSha,
branchName,
false,
{
status: 'success',
}
);
console.log({deployment});
return deployment;
}
const newEnvironment = await createGitlabEnvironment();
const deployment = await createGitlabDeployment(newEnvironment);
await findMRs(deployment.id);