diff --git a/dist/index.js b/dist/index.js index 9103af4..cc50fb7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -300,12 +300,32 @@ async function getChangedFiles(client, prNumber) { } async function getFileContent(client, repoPath) { - const response = await client.repos.getContent({ + + let remoteDefn = { owner: github.context.repo.owner, repo: github.context.repo.repo, path: repoPath, ref: github.context.sha, - }); + }; + + if (repoPath.includes('@')) { + const regex = /^(.+?)\/(.+?)@(.+?):(.+?)$/; + const match = repoPath.match(regex); + + if (match) { + const [_, org, repo, ref, path] = match; + remoteDefn = { + owner: org, + repo, + path, + ref + } + } + } + + core.debug(JSON.stringify({ remoteDefn })) + + const response = await client.repos.getContent(remoteDefn); return Buffer.from(response.data.content, response.data.encoding).toString(); } diff --git a/lib/github.js b/lib/github.js index 90a77d9..f6a44e9 100644 --- a/lib/github.js +++ b/lib/github.js @@ -46,12 +46,32 @@ async function getChangedFiles(client, prNumber) { } async function getFileContent(client, repoPath) { - const response = await client.repos.getContent({ + + let remoteDefn = { owner: github.context.repo.owner, repo: github.context.repo.repo, path: repoPath, ref: github.context.sha, - }); + }; + + if (repoPath.includes('@')) { + const regex = /^(.+?)\/(.+?)@(.+?):(.+?)$/; + const match = repoPath.match(regex); + + if (match) { + const [_, org, repo, ref, path] = match; + remoteDefn = { + owner: org, + repo, + path, + ref + } + } + } + + core.debug(JSON.stringify({ remoteDefn })) + + const response = await client.repos.getContent(remoteDefn); return Buffer.from(response.data.content, response.data.encoding).toString(); }