@backstage-community/plugin-github-actions 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkflowRuns.esm.js","sources":["../../src/components/useWorkflowRuns.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useState } from 'react';\nimport useAsyncRetry from 'react-use/esm/useAsyncRetry';\nimport { githubActionsApiRef } from '../api/GithubActionsApi';\nimport { useApi, errorApiRef } from '@backstage/core-plugin-api';\nimport { Branch } from '../api';\n\nexport type WorkflowRun = {\n workflowName?: string;\n id: string;\n message?: string;\n url?: string;\n githubUrl?: string;\n source: {\n branchName?: string;\n commit: {\n hash?: string;\n url?: string;\n };\n };\n status?: string;\n conclusion?: string;\n onReRunClick: () => void;\n};\n\nexport function useWorkflowRuns({\n hostname,\n owner,\n repo,\n branch,\n initialPageSize = 6,\n}: {\n hostname?: string;\n owner: string;\n repo: string;\n branch?: string | undefined;\n initialPageSize?: number;\n}) {\n const api = useApi(githubActionsApiRef);\n\n const errorApi = useApi(errorApiRef);\n\n const [total, setTotal] = useState(0);\n const [page, setPage] = useState(0);\n const [pageSize, setPageSize] = useState(initialPageSize);\n const [branches, setBranches] = useState<Branch[]>([]);\n const [defaultBranch, setDefaultBranch] = useState<string>('');\n\n const {\n loading,\n value: runs,\n retry,\n error,\n } = useAsyncRetry<WorkflowRun[]>(async () => {\n const fetchedDefaultBranch = await api.getDefaultBranch({\n hostname,\n owner,\n repo,\n });\n\n setDefaultBranch(fetchedDefaultBranch);\n let selectedBranch = branch;\n if (branch === 'default') {\n selectedBranch = fetchedDefaultBranch;\n }\n\n const fetchBranches = async () => {\n let next = true;\n let iteratePage =
|
|
1
|
+
{"version":3,"file":"useWorkflowRuns.esm.js","sources":["../../src/components/useWorkflowRuns.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useState } from 'react';\nimport useAsyncRetry from 'react-use/esm/useAsyncRetry';\nimport { githubActionsApiRef } from '../api/GithubActionsApi';\nimport { useApi, errorApiRef } from '@backstage/core-plugin-api';\nimport { Branch } from '../api';\n\nexport type WorkflowRun = {\n workflowName?: string;\n id: string;\n message?: string;\n url?: string;\n githubUrl?: string;\n source: {\n branchName?: string;\n commit: {\n hash?: string;\n url?: string;\n };\n };\n status?: string;\n conclusion?: string;\n onReRunClick: () => void;\n};\n\nexport function useWorkflowRuns({\n hostname,\n owner,\n repo,\n branch,\n initialPageSize = 6,\n}: {\n hostname?: string;\n owner: string;\n repo: string;\n branch?: string | undefined;\n initialPageSize?: number;\n}) {\n const api = useApi(githubActionsApiRef);\n\n const errorApi = useApi(errorApiRef);\n\n const [total, setTotal] = useState(0);\n const [page, setPage] = useState(0);\n const [pageSize, setPageSize] = useState(initialPageSize);\n const [branches, setBranches] = useState<Branch[]>([]);\n const [defaultBranch, setDefaultBranch] = useState<string>('');\n\n const {\n loading,\n value: runs,\n retry,\n error,\n } = useAsyncRetry<WorkflowRun[]>(async () => {\n const fetchedDefaultBranch = await api.getDefaultBranch({\n hostname,\n owner,\n repo,\n });\n\n setDefaultBranch(fetchedDefaultBranch);\n let selectedBranch = branch;\n if (branch === 'default') {\n selectedBranch = fetchedDefaultBranch;\n }\n\n const fetchBranches = async () => {\n let next = true;\n let iteratePage = 1;\n const branchSet: Branch[] = [];\n\n while (next) {\n const branchesData = await api.listBranches({\n hostname,\n owner,\n repo,\n page: iteratePage,\n });\n if (branchesData.length === 0) {\n next = false;\n }\n iteratePage++;\n branchSet.push(...branchesData);\n }\n\n return branchSet;\n };\n\n const branchSet = await fetchBranches();\n setBranches(branchSet);\n\n // GitHub API pagination count starts from 1\n const workflowRunsData = await api.listWorkflowRuns({\n hostname,\n owner,\n repo,\n pageSize,\n page: page + 1,\n branch: selectedBranch,\n });\n setTotal(workflowRunsData.total_count);\n // Transformation here\n return workflowRunsData.workflow_runs.map(run => ({\n workflowName: run.name ?? undefined,\n message: run.head_commit?.message,\n id: `${run.id}`,\n onReRunClick: async () => {\n try {\n await api.reRunWorkflow({\n hostname,\n owner,\n repo,\n runId: run.id,\n });\n } catch (e) {\n errorApi.post(\n new Error(`Failed to rerun the workflow: ${(e as Error).message}`),\n );\n }\n },\n source: {\n branchName: run.head_branch ?? undefined,\n commit: {\n hash: run.head_commit?.id,\n url: run.head_repository?.branches_url?.replace(\n '{/branch}',\n run.head_branch ?? '',\n ),\n },\n },\n status: run.status ?? undefined,\n conclusion: run.conclusion ?? undefined,\n url: run.url,\n githubUrl: run.html_url,\n }));\n }, [page, pageSize, repo, owner]);\n\n return [\n {\n page,\n pageSize,\n loading,\n runs,\n branches,\n defaultBranch,\n projectName: `${owner}/${repo}`,\n total,\n error,\n },\n {\n runs,\n setPage,\n setPageSize,\n retry,\n },\n ] as const;\n}\n"],"names":["branchSet"],"mappings":";;;;;AAuCO,SAAS,eAAgB,CAAA;AAAA,EAC9B,QAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAkB,GAAA;AACpB,CAMG,EAAA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