Skip to content

🎥 Make videos programmatically with React

get vercel git source

Jonny Burger1945652909ee
diff --git a/packages/cli/src/get-github-repository.ts b/packages/cli/src/get-github-repository.ts
index 35e534fff3..1daf0f005a 100644
--- a/packages/cli/src/get-github-repository.ts
+++ b/packages/cli/src/get-github-repository.ts
@@ -104,7 +104,36 @@ export const getGifRef = (): string | null => {
}
};
-export const getGitSource = (remotionRoot: string): GitSource | null => {
+const getFromEnvVariables = (): GitSource | null => {
+ const {
+ VERCEL_GIT_PROVIDER,
+ VERCEL_GIT_COMMIT_SHA,
+ VERCEL_GIT_REPO_OWNER,
+ VERCEL_GIT_REPO_SLUG,
+ } = process.env;
+ if (
+ VERCEL_GIT_COMMIT_SHA &&
+ VERCEL_GIT_REPO_OWNER &&
+ VERCEL_GIT_REPO_SLUG &&
+ VERCEL_GIT_PROVIDER === 'github'
+ ) {
+ return {
+ name: VERCEL_GIT_REPO_SLUG,
+ org: VERCEL_GIT_REPO_OWNER,
+ ref: VERCEL_GIT_COMMIT_SHA,
+ type: 'github',
+ relativeFromGitRoot: '',
+ };
+ }
+
+ return null;
+};
+
+export const getGitSource = (remotionRoot: string | null): GitSource | null => {
+ if (remotionRoot === null) {
+ return getFromEnvVariables();
+ }
+
const ref = getGifRef();
if (!ref) {
return null;
diff --git a/packages/cli/src/test/get-github-repo.test.ts b/packages/cli/src/test/get-github-repo.test.ts
index b07dd08485..66f5ca9294 100644
--- a/packages/cli/src/test/get-github-repo.test.ts
+++ b/packages/cli/src/test/get-github-repo.test.ts
@@ -57,3 +57,17 @@ test('Should get Git Source', () => {
expect(git).not.toBeNull();
expect(git?.relativeFromGitRoot).toBe(`packages${path.sep}cli`);
});
+
+test('Should recognize VERCEL', () => {
+ process.env.VERCEL_GIT_COMMIT_SHA = '123';
+ process.env.VERCEL_GIT_PROVIDER = 'github';
+ process.env.VERCEL_GIT_REPO_SLUG = 'remotion';
+ process.env.VERCEL_GIT_REPO_OWNER = 'remotion-dev';
+
+ const source = getGitSource(null);
+ expect(source).not.toBeNull();
+ expect(source?.name).toBe('remotion');
+ expect(source?.org).toBe('remotion-dev');
+ expect(source?.ref).toBe('123');
+ expect(source?.type).toBe('github');
+});