Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit 73aa98a

Browse files
fix: types of octokit
1 parent 0c9b54b commit 73aa98a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: src/utils/misc.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import {getInput} from '@actions/core';
22
import {Context} from '@actions/github/lib/context';
33
import {Octokit} from '@technote-space/github-action-helper/dist/types';
44
import {ContextHelper, Utils} from '@technote-space/github-action-helper';
5-
import {ActionsListWorkflowRunsResponseData, ActionsGetWorkflowRunResponseData} from '@octokit/types';
5+
import {components} from '@octokit/openapi-types';
66
import {SHOW_PROPERTIES} from '../constant';
77

8+
type ActionsListWorkflowRunsResponseData = components['schemas']['workflow-run'];
9+
type ActionsGetWorkflowRunResponseData = components['schemas']['workflow-run'];
10+
811
const getMergeMessagePrefix = (): RegExp => Utils.getPrefixRegExp(getInput('MERGE_MESSAGE_PREFIX'));
912
const isExcludeMerged = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_MERGED'));
1013
const isExcludeTagPush = (): boolean => Utils.getBoolValue(getInput('EXCLUDE_TAG_PUSH'));
@@ -13,7 +16,7 @@ export const isExcludeContext = (context: Context): boolean =>
1316
(isExcludeTagPush() && Utils.isTagRef(context)) ||
1417
(isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message))
1518
);
16-
export const isNotExcludeRun = (run: ActionsListWorkflowRunsResponseData['workflow_runs'][number]): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
19+
export const isNotExcludeRun = (run: ActionsListWorkflowRunsResponseData): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
1720

1821
export const getRunId = (): number => Number(process.env.GITHUB_RUN_ID);
1922

Diff for: src/utils/workflow.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {Context} from '@actions/github/lib/context';
22
import {Octokit} from '@technote-space/github-action-helper/dist/types';
33
import {Logger} from '@technote-space/github-action-log-helper';
4+
import {Utils} from '@technote-space/github-action-helper';
45
import {PaginateInterface} from '@octokit/plugin-paginate-rest';
56
import {RestEndpointMethods} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types';
6-
import {ActionsListWorkflowRunsResponseData, ActionsGetWorkflowRunResponseData} from '@octokit/types';
7+
import {components} from '@octokit/openapi-types';
78
import {getTargetBranch, isNotExcludeRun} from './misc';
89

10+
type ActionsGetWorkflowRunResponseData = components['schemas']['workflow-run'];
11+
type ActionsListWorkflowRunsResponseData = components['schemas']['workflow-run'];
12+
913
export const getWorkflowRun = async(octokit: Octokit, context: Context): Promise<ActionsGetWorkflowRunResponseData> => {
1014
return (await octokit.actions.getWorkflowRun({
1115
owner: context.repo.owner,
@@ -23,11 +27,11 @@ export const getWorkflowId = (run: ActionsGetWorkflowRunResponseData): number |
2327
return Number(matches[0]);
2428
};
2529

26-
export const getWorkflowRunCreatedAt = (run: ActionsGetWorkflowRunResponseData): string => run.created_at;
30+
export const getWorkflowRunCreatedAt = (run: ActionsGetWorkflowRunResponseData): string => Utils.ensureNotNull(run.created_at);
2731

2832
export const getWorkflowRunNumber = (run: ActionsGetWorkflowRunResponseData): number => run.run_number;
2933

30-
export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit: Octokit, context: Context): Promise<ActionsListWorkflowRunsResponseData['workflow_runs']> => {
34+
export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit: Octokit, context: Context): Promise<Array<ActionsListWorkflowRunsResponseData>> => {
3135
const options: {
3236
owner: string;
3337
repo: string;
@@ -57,7 +61,7 @@ export const getWorkflowRuns = async(workflowId: number, logger: Logger, octokit
5761
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5862
// @ts-ignore
5963
options,
60-
)).map(run => run as ActionsListWorkflowRunsResponseData['workflow_runs'][number]).filter(run => run.event === context.eventName).filter(isNotExcludeRun);
64+
)).map(run => run as ActionsListWorkflowRunsResponseData).filter(run => run.event === context.eventName).filter(isNotExcludeRun);
6165
};
6266

6367
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)