Skip to content

Commit

Permalink
fix: defaulting
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Sep 18, 2023
1 parent b46f16d commit 2b7284b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ inputs:
allow_forks:
description: Allow forks
required: false
default: true
check_artifacts:
description: Check workflow run whether it has an artifact
required: false
Expand Down
19 changes: 12 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ async function main() {
let runNumber = core.getInput("run_number")
let checkArtifacts = core.getBooleanInput("check_artifacts")
let searchArtifacts = core.getBooleanInput("search_artifacts")
let allowForks = core.getBooleanInput("allow_forks")
let hasAllowForks = core.getInput("allow_forks") !== ""
let dryRun = core.getInput("dry_run")

// Using allow_forks lets the user accept any fork, in any situation,
// But if it's not set, we forbid forks if the user is trying to download
// artifacts from a given branch.
const willAcceptForks = allowForks || !branch

const client = github.getOctokit(token)

core.info(`==> Repository: ${owner}/${repo}`)
Expand Down Expand Up @@ -108,6 +103,16 @@ async function main() {
core.info(`==> Run number: ${runNumber}`)
}

// We allow forks by default, except when a branch is requested
let allowForks = !branch

// `allow_forks` overrides any other logic
if (hasAllowForks) {
allowForks = core.getBooleanInput("allow_forks")
}

core.info(`==> Allow forks: ${allowForks}`)

if (!runID) {
// Note that the runs are returned in most recent first order.
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRuns, {
Expand All @@ -126,7 +131,7 @@ async function main() {
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
continue
}
if (!willAcceptForks && run.head_repository.full_name !== `${owner}/${repo}`) {
if (!allowForks && run.head_repository.full_name !== `${owner}/${repo}`) {
core.info(`==> Skipping run from fork: ${run.head_repository.full_name}`)
continue
}
Expand Down

0 comments on commit 2b7284b

Please sign in to comment.