Upgrade @octokit/rest to 19.0.3

This upgrade contains changes to the API types which leads to several changes
around the code base handling the now more precise types.

Signed-off-by: Crevil <bjoern.soerensen@gmail.com>
This commit is contained in:
Crevil
2022-07-09 09:13:07 +02:00
parent 5e6ef0a660
commit 9de15a41d7
19 changed files with 184 additions and 67 deletions
@@ -4,8 +4,9 @@
"node_id": "MDEyOldvcmtmbG93IFJ1bjI2OTI4OQ==",
"check_suite_id": 42,
"check_suite_node_id": "MDEwOkNoZWNrU3VpdGU0Mg==",
"head_branch": "master",
"head_branch": "main",
"head_sha": "acb5820ced9479c074f688cc328bf03f341a511d",
"path": ".github/workflows/build.yml@main",
"run_number": 562,
"event": "push",
"status": "queued",
@@ -16,12 +17,71 @@
"pull_requests": [],
"created_at": "2020-01-22T19:33:08Z",
"updated_at": "2020-01-22T19:33:08Z",
"actor": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"run_attempt": 1,
"referenced_workflows": [
{
"path": "octocat/Hello-World/.github/workflows/deploy.yml@main",
"sha": "86e8bc9ecf7d38b1ed2d2cfb8eb87ba9b35b01db",
"ref": "refs/heads/main"
},
{
"path": "octo-org/octo-repo/.github/workflows/report.yml@v2",
"sha": "79e9790903e1c3373b1a3e3a941d57405478a232",
"ref": "refs/tags/v2"
},
{
"path": "octo-org/octo-repo/.github/workflows/secure.yml@1595d4b6de6a9e9751fb270a41019ce507d4099e",
"sha": "1595d4b6de6a9e9751fb270a41019ce507d4099e"
}
],
"run_started_at": "2020-01-22T19:33:08Z",
"triggering_actor": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"jobs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs",
"logs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs",
"check_suite_url": "https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374",
"artifacts_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts",
"cancel_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel",
"rerun_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun",
"previous_attempt_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/attempts/1",
"workflow_url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038",
"head_commit": {
"id": "acb5820ced9479c074f688cc328bf03f341a511d",
+6 -6
View File
@@ -19,19 +19,19 @@ export type Step = {
status: string;
conclusion?: string;
number: number; // starts from 1
started_at: string;
completed_at: string;
started_at?: string;
completed_at?: string;
};
export type Job = {
html_url: string;
html_url?: string;
status: string;
conclusion: string;
conclusion?: string;
started_at: string;
completed_at: string;
completed_at?: string;
id: number;
name: string;
steps: Step[];
steps?: Step[];
};
export type Jobs = {
@@ -18,7 +18,7 @@ import { useEntity } from '@backstage/plugin-catalog-react';
import React, { useEffect } from 'react';
import { generatePath, Link as RouterLink } from 'react-router-dom';
import { GITHUB_ACTIONS_ANNOTATION } from '../getProjectNameFromEntity';
import { useWorkflowRuns } from '../useWorkflowRuns';
import { useWorkflowRuns, WorkflowRun } from '../useWorkflowRuns';
import { WorkflowRunStatus } from '../WorkflowRunStatus';
import { Typography } from '@material-ui/core';
@@ -90,7 +90,7 @@ export const RecentWorkflowRunsCard = ({
</Typography>
</div>
) : (
<Table
<Table<WorkflowRun>
isLoading={loading}
options={{
search: false,
@@ -107,7 +107,7 @@ export const RecentWorkflowRunsCard = ({
component={RouterLink}
to={generatePath('./ci-cd/:id', { id: data.id! })}
>
{firstLine(data.message)}
{firstLine(data.message || '')}
</Link>
),
},
@@ -73,7 +73,10 @@ const useStyles = makeStyles<Theme>(theme => ({
},
}));
const getElapsedTime = (start: string, end: string) => {
const getElapsedTime = (start: string | undefined, end: string | undefined) => {
if (!start || !end) {
return '';
}
const startDate = DateTime.fromISO(start);
const endDate = end ? DateTime.fromISO(end) : DateTime.now();
const diff = endDate.diff(startDate);
@@ -127,7 +130,7 @@ const JobListItem = ({
<AccordionDetails className={classes.accordionDetails}>
<TableContainer>
<Table>
{job.steps.map(step => (
{job.steps?.map(step => (
<StepView key={step.number} step={step} />
))}
</Table>
@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import useAsync from 'react-use/lib/useAsync';
import { githubActionsApiRef } from '../../api';
import useAsync, { AsyncState } from 'react-use/lib/useAsync';
import { githubActionsApiRef, Job, Jobs, Step } from '../../api';
import { buildRouteRef } from '../../routes';
import { useApi, useRouteRefParams } from '@backstage/core-plugin-api';
@@ -26,18 +26,41 @@ export const useWorkflowRunJobs = ({
hostname?: string;
owner: string;
repo: string;
}) => {
}): AsyncState<Jobs> => {
const api = useApi(githubActionsApiRef);
const { id } = useRouteRefParams(buildRouteRef);
const jobs = useAsync(async () => {
return repo && owner
? api.listJobsForWorkflowRun({
hostname,
owner,
repo,
id: parseInt(id, 10),
})
: Promise.reject(new Error('No repo/owner provided'));
return useAsync(async () => {
if (!repo || !owner) {
throw new Error('No repo/owner provided');
}
const jobs = await api.listJobsForWorkflowRun({
hostname,
owner,
repo,
id: parseInt(id, 10),
});
return {
total_count: jobs.total_count,
jobs: jobs.jobs.map<Job>(job => ({
html_url: job.html_url || undefined,
status: job.status,
conclusion: job.conclusion || undefined,
started_at: job.started_at,
completed_at: job.completed_at || undefined,
id: job.id,
name: job.name,
steps: job.steps?.map<Step>(step => ({
name: step.name,
status: step.status,
conclusion: step.conclusion || undefined,
number: step.number,
started_at: step.started_at || undefined,
completed_at: step.completed_at || undefined,
})),
})),
};
}, [repo, owner, id]);
return jobs;
};
@@ -28,8 +28,8 @@ export const WorkflowRunStatus = ({
status,
conclusion,
}: {
status: string | undefined;
conclusion: string | undefined;
status?: string;
conclusion?: string;
}) => {
if (status === undefined) return null;
switch (status.toLocaleLowerCase('en-US')) {
@@ -19,20 +19,20 @@ import { githubActionsApiRef } from '../api/GithubActionsApi';
import { useApi, errorApiRef } from '@backstage/core-plugin-api';
export type WorkflowRun = {
workflowName: string;
workflowName?: string;
id: string;
message: string;
message?: string;
url?: string;
githubUrl?: string;
source: {
branchName: string;
branchName?: string;
commit: {
hash: string;
hash?: string;
url?: string;
};
};
status: string;
conclusion: string;
status?: string;
conclusion?: string;
onReRunClick: () => void;
};
@@ -75,8 +75,8 @@ export function useWorkflowRuns({
setTotal(workflowRunsData.total_count);
// Transformation here
return workflowRunsData.workflow_runs.map(run => ({
workflowName: run.name,
message: run.head_commit.message,
workflowName: run.name || undefined,
message: run.head_commit?.message,
id: `${run.id}`,
onReRunClick: async () => {
try {
@@ -91,17 +91,17 @@ export function useWorkflowRuns({
}
},
source: {
branchName: run.head_branch,
branchName: run.head_branch || undefined,
commit: {
hash: run.head_commit.id,
hash: run.head_commit?.id,
url: run.head_repository?.branches_url?.replace(
'{/branch}',
run.head_branch,
run.head_branch || '',
),
},
},
status: run.status,
conclusion: run.conclusion,
status: run.status || undefined,
conclusion: run.conclusion || undefined,
url: run.url,
githubUrl: run.html_url,
}));