MCPcopy
hub / github.com/conwnet/github1s / getCommitChangedFiles

Function getCommitChangedFiles

extensions/github1s/src/changes/files.ts:52–82  ·  view source on GitHub ↗
(commit: adapterTypes.Commit)

Source from the content-addressed store, hash-verified

50};
51
52export const getCommitChangedFiles = async (commit: adapterTypes.Commit) => {
53 const currentAdapter = adapterManager.getCurrentAdapter();
54 const scheme = currentAdapter.scheme;
55 const { repo } = await router.getState();
56 // if the commit.parents is more than one element
57 // the parents[1].sha should be the merge source commitSha
58 // so we use the parents[0].sha as the parent commitSha
59 const baseRef = commit?.parents?.[0];
60 const baseRootUri = vscode.Uri.parse('').with({
61 scheme: currentAdapter.scheme,
62 authority: `${repo}+${baseRef || 'HEAD'}`,
63 path: '/',
64 });
65 const headRootUri = baseRootUri.with({
66 authority: `${repo}+${commit.sha || 'HEAD'}`,
67 });
68 const repository = Repository.getInstance(scheme, repo);
69 const changedFiles = await repository.getCommitChangedFiles(commit.sha);
70
71 return changedFiles.map((commitFile) => {
72 // the `previous_filename` field only exists in `RENAMED` file,
73 // fallback to `filename` otherwise
74 const baseFilePath = commitFile.previousPath || commitFile.path;
75 const headFilePath = commitFile.path;
76 return {
77 baseFileUri: vscode.Uri.joinPath(baseRootUri, baseFilePath),
78 headFileUri: vscode.Uri.joinPath(headRootUri, headFilePath),
79 status: commitFile.status,
80 };
81 });
82};
83
84export const getChangedFiles = async (): Promise<VSCodeChangedFile[]> => {
85 const routerState = await router.getState();

Callers 2

getCommitFileItemsMethod · 0.90
getChangedFilesFunction · 0.85

Calls 4

getCurrentAdapterMethod · 0.80
getStateMethod · 0.80
getCommitChangedFilesMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected