Merge pull request #5181 from backstage/timbonicus/workflow-runs-deleted-fork

Make GitHub workflow run source.commit.url optional
This commit is contained in:
Ben Lambert
2021-03-31 09:36:15 +02:00
committed by GitHub
3 changed files with 48 additions and 48 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-github-actions': patch
---
Fixed GitHub workflows not appearing when the originating repository for a workflow run was deleted.
@@ -50,7 +50,7 @@ export type WorkflowRun = {
branchName: string;
commit: {
hash: string;
url: string;
url?: string;
};
};
status: string;
@@ -43,53 +43,48 @@ export function useWorkflowRuns({
const { loading, value: runs, retry, error } = useAsyncRetry<
WorkflowRun[]
>(async () => {
return (
api
// GitHub API pagination count starts from 1
.listWorkflowRuns({
hostname,
owner,
repo,
pageSize,
page: page + 1,
branch,
})
.then((workflowRunsData): WorkflowRun[] => {
setTotal(workflowRunsData.total_count);
// Transformation here
return workflowRunsData.workflow_runs.map(run => ({
workflowName: run.name,
message: run.head_commit.message,
id: `${run.id}`,
onReRunClick: async () => {
try {
await api.reRunWorkflow({
hostname,
owner,
repo,
runId: run.id,
});
} catch (e) {
errorApi.post(e);
}
},
source: {
branchName: run.head_branch,
commit: {
hash: run.head_commit.id,
url: run.head_repository.branches_url.replace(
'{/branch}',
run.head_branch,
),
},
},
status: run.status,
conclusion: run.conclusion,
url: run.url,
githubUrl: run.html_url,
}));
})
);
// GitHub API pagination count starts from 1
const workflowRunsData = await api.listWorkflowRuns({
hostname,
owner,
repo,
pageSize,
page: page + 1,
branch,
});
setTotal(workflowRunsData.total_count);
// Transformation here
return workflowRunsData.workflow_runs.map(run => ({
workflowName: run.name,
message: run.head_commit.message,
id: `${run.id}`,
onReRunClick: async () => {
try {
await api.reRunWorkflow({
hostname,
owner,
repo,
runId: run.id,
});
} catch (e) {
errorApi.post(e);
}
},
source: {
branchName: run.head_branch,
commit: {
hash: run.head_commit.id,
url: run.head_repository?.branches_url?.replace(
'{/branch}',
run.head_branch,
),
},
},
status: run.status,
conclusion: run.conclusion,
url: run.url,
githubUrl: run.html_url,
}));
}, [page, pageSize, repo, owner]);
return [