feat(sync): add resolveBranchHead to fetch branch tip SHA
This commit is contained in:
@@ -88,6 +88,16 @@ export const getRepository = async (
|
||||
return result.data;
|
||||
};
|
||||
|
||||
export const resolveBranchHead = async (
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string,
|
||||
branch: string,
|
||||
): Promise<{ sha: string }> => {
|
||||
const result = await octokit.rest.repos.getBranch({ owner, repo, branch });
|
||||
return { sha: result.data.commit.sha };
|
||||
};
|
||||
|
||||
const toMillis = (value?: string | null) =>
|
||||
value ? new Date(value).getTime() : undefined;
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import type { Octokit } from '@octokit/rest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { resolveBranchHead } from '../../convex/githubClient';
|
||||
|
||||
describe('resolveBranchHead', () => {
|
||||
it('returns the branch tip sha from the branch ref', async () => {
|
||||
const getBranch = vi.fn(async () => ({
|
||||
data: { commit: { sha: 'deadbeef' } },
|
||||
}));
|
||||
const octokit = {
|
||||
rest: { repos: { getBranch } },
|
||||
} as unknown as Octokit;
|
||||
|
||||
const result = await resolveBranchHead(octokit, 'o', 'r', 'main');
|
||||
|
||||
expect(result.sha).toBe('deadbeef');
|
||||
expect(getBranch).toHaveBeenCalledWith({
|
||||
owner: 'o',
|
||||
repo: 'r',
|
||||
branch: 'main',
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user