Skip to content

Commit

Permalink
Merge repo+owner field
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjitse-E committed Sep 13, 2021
1 parent 192c157 commit e7fd5e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test('Should hit the Github REST API twice', async () => {
beforeEach(() => {
process.env['INPUT_TOKEN'] = 'xyz'
process.env['GITHUB_REPOSITORY'] = 'foo/bar';
process.env['INPUT_REPO'] = 'github-actions-tests'
process.env['INPUT_OWNER'] = 'Vendic'
process.env['INPUT_REPO'] = 'Vendic/github-actions-tests'
process.env['INPUT_PATHS'] = 'hello\nfoo/bar'
})
5 changes: 1 addition & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ inputs:
token:
description: Your Github
required: true
owner:
description: The owner of the repository
required: true
repo:
description: The name of the repository
description: The name of the repository (owner/repo-name)
required: true
paths:
description: A multiline input of different paths that you want to clone
Expand Down
7 changes: 4 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6214,12 +6214,11 @@ var external_fs_ = __nccwpck_require__(747);
async function run() {
try {
const paths = core.getMultilineInput('paths');
const owner = core.getInput('owner');
const repo = core.getInput('repo');
const token = core.getInput('token');
const octokit = github.getOctokit(token);
for (let path of paths) {
let response = await getFileContent(octokit, repo, owner, path);
let response = await getFileContent(octokit, repo, path);
if (response.status != 200) {
throw new Error(`Received in response code ${response.status} from Github`);
}
Expand All @@ -6230,7 +6229,9 @@ async function run() {
core.setFailed(`Action failed: ${error}`);
}
}
async function getFileContent(octokit, repo, owner, path) {
async function getFileContent(octokit, repository, path) {
const owner = repository.split('/')[0];
const repo = repository.split('/')[1];
return octokit.rest.repos.getContent({
owner,
repo,
Expand Down
9 changes: 5 additions & 4 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import * as fs from "fs";
export default async function run(): Promise<void> {
try {
const paths = core.getMultilineInput('paths')
const owner = core.getInput('owner')
const repo = core.getInput('repo')
const token = core.getInput('token')
const octokit = github.getOctokit(token)

for (let path of paths) {
let response: GetContentResult = await getFileContent(octokit, repo, owner, path)
let response: GetContentResult = await getFileContent(octokit, repo, path)
if (response.status != 200) {
throw new Error(`Received in response code ${response.status} from Github`)
}
Expand All @@ -29,10 +28,12 @@ export default async function run(): Promise<void> {

async function getFileContent(
octokit: InstanceType<typeof GitHub>,
repo: string,
owner: string,
repository: string,
path: string
): Promise<OctokitResponse<any>> {
const owner = repository.split('/')[0]
const repo = repository.split('/')[1]

return octokit.rest.repos.getContent({
owner,
repo,
Expand Down

0 comments on commit e7fd5e7

Please sign in to comment.