Skip to content

Commit

Permalink
feat: add ability to reference a config not in the same repo
Browse files Browse the repository at this point in the history
  • Loading branch information
wespickett committed Aug 29, 2023
1 parent 4ee373a commit 4f70b3c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
24 changes: 22 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 22 additions & 2 deletions lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 4f70b3c

Please sign in to comment.