Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send branch ref if not specified #13

Merged
merged 3 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Minimal setup.
|---|---|---|---|
|`files`|A list of files with the path separated by a space, relative to root of your repository. Can also be a folder and the action will recursively pull all the files.|`true`|N/A|
|`token`|A GitHub token. |`false`|`${{ github.token }}`|
|`branch`|Checkout files from a specific branch.|`false`|`master`|
|`branch`|Checkout files from a specific branch. If none specified, it will use the default branch of the repository.|`false`|N/A|
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ inputs:
branch:
description: 'Branch to checkout files from'
required: false
default: master

runs:
using: 'node16'
Expand Down
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ const owner = repository.split('/')[0]
const repo = repository.split('/')[1]
const ref = core.getInput('branch');

function getContentParams() {
let params = { owner, repo }

if (ref) { params.ref = ref }
return params;
}

function getContent(path) {
octokit.rest.repos.getContent({
owner,
repo,
path,
ref,
}).then(data => {
octokit.rest.repos.getContent({ path, ...getContentParams() })
.then(data => {
if (Array.isArray(data.data)) {
data.data.forEach(fileData => getContent(fileData.path))
} else {
Expand All @@ -37,6 +40,6 @@ function saveContent(data) {
fs.writeFile(data.path, fileContent, err => { if (err) throw err });
}

files.forEach(file =>{
files.forEach(file => {
getContent(file)
})