Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Support workflows by name (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
roll authored Apr 4, 2022
1 parent ef69208 commit 5fdc2f5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/components/Workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,23 @@ async function loadReport(props: {
})
}

// Workflow
async function getWorkflowId() {
const path = `/repos/${user}/${repo}/actions/workflows`
const res = await makeRequest(path)
const data = await res.json()
const predicat = (item: IDict) => item.name.toLowerCase() === flow
const workflow = data.workflows.filter(predicat)[0]
return workflow.id
}

// Run
async function getRunId() {
const path = `/repos/${user}/${repo}/actions/workflows/${flow}.yaml/runs`
async function getRunId(workflowId: string) {
const path = `/repos/${user}/${repo}/actions/workflows/${workflowId}/runs`
const res = await makeRequest(path)
const data = await res.json()
const run = data.workflow_runs.filter((item: IDict) => item.status === 'completed')[0]
const predicat = (item: IDict) => item.status === 'completed'
const run = data.workflow_runs.filter(predicat)[0]
return run.id
}

Expand All @@ -267,7 +278,8 @@ async function loadReport(props: {
const path = `/repos/${user}/${repo}/actions/runs/${runId}/artifacts`
const res = await makeRequest(path)
const data = await res.json()
const artifact = data.artifacts.filter((item: IDict) => item.name === 'report')[0]
const predicat = (item: IDict) => item.name === 'report'
const artifact = data.artifacts.filter(predicat)[0]
return artifact.id
}

Expand All @@ -290,7 +302,7 @@ async function loadReport(props: {
// Main
try {
setProgress(20)
const runId = run || (await getRunId())
const runId = run || (await getRunId(await getWorkflowId()))
setRun(runId.toString())
setProgress(40)
const artifactId = await getArtifactId(runId)
Expand Down

0 comments on commit 5fdc2f5

Please sign in to comment.